Working on a project for my class and spent too long searching around on the internet trying to find the right answer...
Basically its a simple vending machine program using a hashmap.
So i got this so far...
We're suppose to next just print out a list of all the items in the vending machine. But I can't figure out how to print the values of the objects.
Is there some way to just make a System.out.prin tln( ??? (softdrink1)); and have it print out the (key, name, price)?
Basically its a simple vending machine program using a hashmap.
So i got this so far...
Code:
public void runSimulator()
{
SoftDrink softdrink1 = new SoftDrink("A1","Coke",1.25);
SoftDrink softdrink2 = new SoftDrink("A2","Pepsi",1.25);
SoftDrink softdrink3 = new SoftDrink("A3","Sprite",1.25);
Candy candy1 = new Candy("B1","Snickers",0.75);
Candy candy2 = new Candy("B2","Crunch",0.75);
Candy candy3 = new Candy("B3","Butterfinger",0.75);
HashMap<String,Object> vendingMap = new HashMap<String,Object>();
vendingMap.put("A1", softdrink1);
vendingMap.put("A2", softdrink2);
vendingMap.put("A3", softdrink3);
vendingMap.put("B1", candy1);
vendingMap.put("B2", candy2);
vendingMap.put("B3", candy3);
Is there some way to just make a System.out.prin tln( ??? (softdrink1)); and have it print out the (key, name, price)?
Comment