Question: Doing a project about a vending machine in a beginner's class with java, these are the requirements: Pompt the user for a menu with at

Doing a project about a vending machine in a beginner's class with java, these are the requirements:

Pompt the user for a menu with at least 16 items to choose from and has the ability to credit the charge and get back the exact change.The program should have some type of user management like keep track of item inventory and whole day transaction.

I can do the 16 items and credit the change part just fine, but I don't know how to keep track of the inventory. This is what I have so far:

import java.util.Scanner;

public class VendingMachineDriver

{

public static void main(String[] args)

{

VendingMachine machine = new VendingMachine();

Scanner s = new Scanner(System.in);

int choice;

double amount;

int item = 0;

double[] prices = new double[] { 1.25, 1.50, 1.50, 1.75, 1.25, 1.50, 1.50, 1.50, 1.50,

1.50, 1.50, 1.50, 1.50, 2.50, 1.50, 3.0};

double moneyPaid;

do

{

System.out.println("----VendingMachineOptions!----");

System.out.println("1. See snack options.");

System.out.println("2. Check Inventory.");

System.out.println("3. Exit");

System.out.print("Enter your choice: ");

choice = s.nextInt();

switch(choice)

{

case 1:

machine.addASnack();

break;

case 2:

machine.inventory();

break;

default:

System.out.println("Invalid choice");

}

} while(choice != 2);

System.out.println("Enter a valid choice: ");

}

}

---------------------------------------

import java.util.Scanner;

public class VendingMachine

{

Scanner s = new Scanner(System.in);

private int[] numberOfItems = new int[]{3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 ,3 ,3, 3, 3};

int item = 0;

double[] prices = new double[] { 1.25, 1.50, 1.50, 1.75, 1.25, 1.50, 1.50, 1.50, 1.50,

1.50, 1.50, 1.50, 1.50, 2.50, 1.50, 3.0};

double moneyPaid;

public void addASnack()

{

System.out.println(" Please enter your selection:"

+ " 1: Snickers \t 1.25"

+ " 2: Reeses Cup \t 1.50"

+ " 3: Doritoes \t 1.50"

+ " 4: Pepsi \t 1.75"

+ " 5: Twix \t 1.25"

+ " 6: FruitSnacks \t 1.50"

+ " 7: Lays \t 1.50 "

+ " 8: Fanta Cup \t 1.50"

+ " 9: Gatorade \t 1.50"

+ " 10: Cheetos \t 1.50"

+ " 11: Muskateers \t 1.50"

+ " 12: Takis \t 1.50"

+ " 13: Choco Bar \t 1.50"

+ " 14: StarBucks \t 2.50"

+ " 15: TrailMix \t 1.50"

+ " 16: RichSnack \t 3.0"

+ " 17: Exit ");

item = s.nextInt();

if (item < 17)

{

System.out.println(" Enter the mulah!");

moneyPaid = s.nextDouble();

if (moneyPaid >= (prices[item - 1]))

{

System.out.println("Thanks for choosing option" + " " + item + "." +

"Your change is " + (moneyPaid - prices[item -1]));

}

else

{

System.out.println("Please insert another " + "$" + (item - moneyPaid));

}

}

}

public void inventory()

{

System.out.println(" Please enter which item you wish to check the inventory of:"

+ " 1: Snickers \t 1.25"

+ " 2: Reeses Cup \t 1.50"

+ " 3: Doritoes \t 1.50"

+ " 4: Pepsi \t 1.75"

+ " 5: Twix \t 1.25"

+ " 6: FruitSnacks \t 1.50"

+ " 7: Lays \t 1.50 "

+ " 8: Fanta Cup \t 1.50"

+ " 9: Gatorade \t 1.50"

+ " 10: Cheetos \t 1.50"

+ " 11: Muskateers \t 1.50"

+ " 12: Takis \t 1.50"

+ " 13: Choco Bar \t 1.50"

+ " 14: StarBucks \t 2.50"

+ " 15: TrailMix \t 1.50"

+ " 16: RichSnack \t 3.0"

+ " 17: Exit ");

item = s.nextInt();

switch(item)

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!