1 Produce a menu system that looks EXACTLY like the followin

1. Produce a menu system that looks EXACTLY like the following illustration

Java Vending Machine

(1) : Chewing Gum -- 40cent

(2) : Potato Chips -- 75cent

(3) : Snickers -- 80cent

(4) : Pop Tarts -- 95cents

Please make your seletion (1, 2, 3, 4 or type 5 to EXIT):

**Notice the use here of the cents symbol ().You will have to reseach how to add this symbol, since it is not present on your keyboard.

For this program, you should use the Scanner class for input from the user. Do not use the JOptionPane class, s it will not provide a runing acount on the screen of the program\'s transaction with the user.

2. Write three method to perform the functions of the program:

i). Display the machine menu

ii). Calculate the money to be added by the user and the change (if any) to the user

iii). Calculate the exact coins to be dispensed to the user.

3. Provide the appropriate PROMPTS for the user to enter their money as an amount of CENTS based on what choice the user has made, how much money he has submitted, how much more (if any) money still needs to be given, how much change is due to the user, and how many of each of the coins(quarters,dimes, and nickels) will be dispensed as change. Design your program to accept input in CENTS, NOT in fractional amounts(i.e., -- do not set up your program to deal in amount containing dollars and cents such as 1.25).

4. Program an ARRAY to hold the cost of each of the four item available from the machine and use the values from the array to calculate howmuch money needs to be input by the user.

5. Use loops where appropriate to calculate the exchange of money and allow the user to run the program as many times as he or she wants. Provide the appropriate mechanism to allow the user to exit the program cleanly.

6. Display appropriate \"Thank you\" messages at the end of the transactions.

7. Your program should display the EXACT COINS that a user would get in change. For our purpose here, you can assume the machine has a limitless quantity of each of the three coins so you do not have to determine what would happen if the machine has run out of quarters, dimes, or nickels. you also do NOT have to design your program to deal with the user trying to do something like submitting pennies or any amount that is not divided by five (i.e., you should not be able to enter an amount like 32cents).

Solution


package menu;

import java.util.Scanner;

public class Menu {
int money;
int returnMoney;
  
public void display(){
System.out.println(\" Vending Machine \ (1):Chewing Gum--40 ¢ \ (2):Potato Chips--75 ¢ \ (3):Snickers--80 ¢ \ (4):Pop Tarts--95 ¢\");
System.out.println(\"Please enter your selection (1,2,3,4 or type 5 to exit):\");
}
public void addMoney(int mn){
money=mn;
}
public void moneyReturn(int mr){
System.out.println(\"Money to be return:\"+mr+\"¢\");
System.out.println(\"Thank you\");
  
}
public static void main(String[] args) {
// TODO code application logic here
int array[]=new int[4];
array[0]=40;
array[1]=75;
array[2]=80;
array[3]=95;
Scanner scn=new Scanner(System.in);
Menu m1=new Menu();
int mon=0;
int choice;
m1.display();
choice=scn.nextInt();
if(choice==1 || choice==2 || choice==3 ||choice==4){
System.out.println(\"Please enter the money to be added(in ¢ ):\");
mon=scn.nextInt();
m1.addMoney(mon);
}
  
  

int monret;
switch(choice){
case 1:monret=mon-array[0];
m1.moneyReturn(monret);
break;
case 2:monret=mon-array[1];
m1.moneyReturn(monret);
break;
case 3:monret=mon-array[2];
m1.moneyReturn(monret);
break;
case 4:monret=mon-array[3];
m1.moneyReturn(monret);
break;
case 5:
break;
default:System.out.println(\"Invalid number\");
break;
}
  
}
  
}

1. Produce a menu system that looks EXACTLY like the following illustration Java Vending Machine (1) : Chewing Gum -- 40cent (2) : Potato Chips -- 75cent (3) :
1. Produce a menu system that looks EXACTLY like the following illustration Java Vending Machine (1) : Chewing Gum -- 40cent (2) : Potato Chips -- 75cent (3) :

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site