Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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

ID: 3573752 • Letter: 1

Question

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

Java Vending Machine

(1) : Chewing Gum -- 40c

(2) : Potato Chips -- 75c

(3) : Snickers -- 80c

(4) : Pop Tarts -- 95c

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).

Configuration:

Java Vending Machine

1. Chewing Gum -- 40cent

2. Potato Chips -- 75 cent

3. Snickers -- 80 cent

4. Pop Tarts -- 95 cent

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

Please enter the money for item 3: 50

You have submitted 50 cents for item 3

You must submit 30 cents more:

Please enter additional change for your item: 50

You have to given 20 cents too much.

Your change is 20 cents.

Your change is 0 quarters, 2 dimes, and 0 nickels.

Thanks for your patronage! Enjoy your treat

Java Vending Machine

1. Chewing Gum -- 40cent

2. Potato Chips -- 75 cent

3. Snickers -- 80 cent

4. Pop Tarts -- 95 cent

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

Thank You ! Have a Nice Day!

NO dollar and pennies

NOTE: Please Read the instruction well before answer the questionTHANK.

Explanation / Answer

/************************java class**********************/

import java.util.Scanner;

public class JavaVendingMachine {
   /**
   * constant Variable declarations
   */
   public static final int SNICKERS_PRICE = 80;
   public static final int POTATO_CHIPS_PRICE = 75;
   public static final int CHEWING_GUM_PRICE = 40;
   public static final int POP_TARTS_PRICE = 95;

   public static int CENTS = 1;
   public static int NICKEL = 5 * CENTS;
   public static int DIMES = 10 * CENTS;
   public static int QUARTER = 25 * CENTS;

   /**
   * Main method start
   */
   public static void main(String args[]) {
       /**
       * Scanner class object for input
       */
       Scanner input = new Scanner(System.in);
       int choice = 6;
       while (true) {
           /**
           * Main MENU Display
           */
           System.out.println("Java Vending Machine");
           System.out.println("(1). Chewing Gum -- 40cent " + "(2). Potato Chips -- 75 cent "
                   + "(3). Snickers -- 80 cent " + "(4). Pop Tarts -- 95 cent");
           System.out.print("Please make your selection (1, 2, 3, 4 or type 5 to EXIT) : ");
           try {
               // taking input from user
               String str = input.next();
               choice = Integer.parseInt(str);
           } catch (Exception e) {
               System.out.println("Please Enter integer input only");
               // on exception setting default value
               choice = 6;

           }

           switch (choice) {

           case 1:
           case 2:
           case 3:
           case 4:
               System.out.print("Please enter the money for item " + choice + ":");
               int money = input.nextInt();
               //If entered money is not divisible by 5
               if (money % 5 != 0) {
                   System.out.println("You are trying to submit pennis");
                   break;
               } else {
                   int remAmount = 0, additionalMoney, change = 0;
                   System.out.println("You have submitted " + money + " cents for item " + choice);
                   if (choice == 1) {
                       remAmount = JavaVendingMachine.CHEWING_GUM_PRICE - money;
                   } else if (choice == 2) {
                       remAmount = JavaVendingMachine.POTATO_CHIPS_PRICE - money;
                   } else if (choice == 3) {
                       remAmount = JavaVendingMachine.SNICKERS_PRICE - money;
                   }
                   if (choice == 4) {
                       remAmount = JavaVendingMachine.POP_TARTS_PRICE - money;
                   }
                   if (remAmount > 0) {
                       System.out.println("You must submit " + remAmount + " cents more:");
                       System.out.print("Please enter additional change for your item:");
                       additionalMoney = input.nextInt();
                       //if again user enter less money
                       while (additionalMoney < remAmount) {
                           int reMoney;
                           System.out.println("You must submit " + (remAmount - additionalMoney) + " cents more:");
                           System.out.print("Please enter additional change for your item:");
                           reMoney = input.nextInt();
                           additionalMoney += reMoney;

                       }
                       if (additionalMoney > remAmount) {
                           System.out
                           .println("You have to given " + (additionalMoney - remAmount) + " cents too much.");
                           change = additionalMoney - remAmount;
                           System.out.println("Your change is " + change + " cents");

                       }
                       if (change > 0) {
                           //calculating quarter,dimes and nickel
                           int quarter = change / QUARTER;
                           int dimes = (change - quarter * QUARTER) / DIMES;
                           int nickel = (change - quarter * QUARTER - dimes * DIMES) / NICKEL;
                           System.out.println("Your change is " + quarter + " quarters, " + dimes + " dimes, and "
                                   + nickel + " nickels");
                           System.out.println("Thanks for your patronage! Enjoy your treat");
                       } else {
                           System.out.println("Thank You ! Have a Nice Day!");
                           System.out.println("NO dollar and pennies");
                       }

                   } else {
                       System.out.println("Thank You ! Have a Nice Day!");
                       System.out.println("NO dollar and pennies");
                   }

               }
               break;
           case 5:
               System.out.println("Thank You ! Have a Nice Day!");
               System.out.println("NO dollar and pennies");
               System.exit(0);
           default:
               System.out.println("Wrong input");
               break;

           }

       }
   }
}


/**************************output***********************/

Java Vending Machine
(1). Chewing Gum -- 40cent
(2). Potato Chips -- 75 cent
(3). Snickers -- 80 cent
(4). Pop Tarts -- 95 cent
Please make your selection (1, 2, 3, 4 or type 5 to EXIT) : 3
Please enter the money for item 3:50
You have submitted 50 cents for item 3
You must submit 30 cents more:
Please enter additional change for your item:50
You have to given 20 cents too much.
Your change is 20 cents
Your change is 0 quarters, 2 dimes, and 0 nickels
Thanks for your patronage! Enjoy your treat
Java Vending Machine
(1). Chewing Gum -- 40cent
(2). Potato Chips -- 75 cent
(3). Snickers -- 80 cent
(4). Pop Tarts -- 95 cent
Please make your selection (1, 2, 3, 4 or type 5 to EXIT) : 5
Thank You ! Have a Nice Day!
NO dollar and pennies

Thanks a lot