• Post Reply Bookmark Topic Watch Topic
  • New Topic

Need Help for School assignment  RSS feed

 
bob morkos
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a collection of Map, in which the Map contains key and an Object Donuts.

public class DonutsVO implements Serializable{
private String price;
private String quantity;
private String type;

public getPrice(){}
.....
}

>> ArrayList of TransactionVO
List dailyResults = // list of daily transaction sold
List monthlyList = new ArrayList();
Iterator iter = daily.iterator();
while(iter.hasNext()){
TransactionVO trans = (TransactionVO)next();
// getDailyDonuts return a Map containing a key and a DogVO
Map donutsSoldDaily = this.getDailyDonuts(trans);
monthlyList.add(donutsSoldDaily);
}
So far this is working, now my question is that I want to retrieve from the monthlyList and compare the map and get the addition of donuts sold for the month by type of donut. I don't know how to go from there, sample code would be very helpful. Any help would be really appreciated. Thanks in advance.
[ April 18, 2004: Message edited by: Ernest Friedman-Hill ]
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that everyone thinks their own problem is urgent -- no need to put "urgent" in your subject line. Doing so actually makes people less likely to read your post. An interesting, descriptive subject line about the actual content (HashMaps, in this case) will attract more people. In fact, I think it's fair to say that "Urgent -- Need help for school assignment" will annoy and turn off 90% of your potential readership.
Anyway, as far as your actual problem: I don't know what a "DogVO" is, and your description doesn't make clear what getDailyDonuts returns, and actually you don't tell us anything about TransactionVO either (VO == "value object?" I'd just leave this annoying little suffix off, if I were you; just makes the code that much harder to read.) Given all I don't know, I can't tell you exactly what to do; but if you know ahead of time all the different kinds of donuts, then set up an array, iterate through all the transactions, and increments the appropriate element in the array for each donut; or, if you don't know all the kinds in advance, then make a new Map. Iterate through all the donuts, and for each donut, check if the type is in the map. If it isn't, add it using the type as the key and an int array of length 1 as the value. If it is, then retrieve the int[1] you previously stored there. Then, whether you just added the array or not, increment the single element. At the end of this, you'll have a map of donut sales by type.
Finally, I wouldn't call this an advanced problem; I'm moving it to Java in General Intermediate. Followups there, please.
[ April 18, 2004: Message edited by: Ernest Friedman-Hill ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!