Bear Bibeault wrote:If the inventory class is merely responsible for keep track of numbers of items, why does it need anything other than integer counters?
John Jai wrote:a counter will do...
else if you like to have separate Inventory class like the previous poster suggested, you shall add that in different List and get its size.
Campbell Ritchie wrote:Beware of anything using instanceof; it can usually be done more elegantly by some other means. Have you considered overloading that putFruit method? Or, go through the Java Tutorials, where you find an example of how you use a Map as a counting device. You can set up a Map with Class<?> objects as its "K" and Integer objects as its "V", and you can count against the Class objects.
Campbell Ritchie wrote:Have you been through the tutorials link I gave you?
If you use that approach, there is no need for any overloading.
Campbell Ritchie wrote:Jian Shen, welcome to the Ranch
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |