After trying different things for about a week i have come to the conclusion i am lost. Can someone please show me how to do this.
This assignment, based on Vending Machine we did in class, you are to now vend six different snacks. The Vending Machine has a capacity of storing up to 100 packs of snacks. Therefore, emulating the real vending machine, it is appropriate to allocate a fixed number of packages to each type of snacks. For example, you can stock 20 packs of Chips, 20 packs of M&Ms, 16 packs of Popcorn, 16 packs of Snickers, 14 packs of Gum, 14 packs of Crackers for a total of 100 packs of snacks. The following is one possible solution, and it is not the only solution. Your application can be different from this write up.
Your task for this assignment is to define multiple classes via inheritance. Your classes should implement various “snacks” including “M&Ms”, “Popcorn”, etc.
To begin, create an abstract “Snack” class. Then, create two classes “Salty” and “Sugary” that inherit from the “Snack” class. Then create classes “M&Ms”, “Popcorn”, “Snickers”, “Gum”, “Crackers”, and “Chips” that inherit from “Salty” or “Sugary” as appropriate.
Once you have your inheritance hierarchy defined, implement the toString method for each class.
Finally, let’s presume that each snack has two additional properties: “calories” and “cost”. Calories is an integer that represents how many calories the snack contains, and cost is a floating-point number that represents how much the snack costs to buy. Implement these properties within your hierarchy as appropriate.