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

Program 4. Write a program that combines programs 1 through 3 into one vending m

ID: 3889500 • Letter: P

Question

Program 4. Write a program that combines programs 1 through 3 into one vending machine user interface program First welcome the user and display the drink options, prompt the user for their drink selection, enter their selection, and record the amount due for a small (program 3). Next, display the size options, prompt the user for the size, enter their size selection, and record the price multiplier (program 2) Based on the size entered, your program should adjust the amount due. Next, display the amount due, prompt the user for their payment, enter their payment, and determine the amount of change to return (program 1). Note: the flow chart for this program does not have to include the entire flow charts for programs 1 through 3. Rather, it can put a brief description of each of the smaller programs in a compute box and show the flow of control for between each smaller program. Any additional computations or control should also be included. In program 4 you should remove any unnecessary print statements used in programs 1 through 3 that do not display useful information to the user.

Explanation / Answer

import.java.util.scanner; public class VendingMachine { public static void main (String args[]) { int[4] coin = {5,5,5,5};//create an array to hold coin values int[4] drink = {5,5,5,5}; //create an array to hold drink values int choice; char cont; //String input1, input2, input3; double price = 1.2, balance = 0, coinInsert = 0, sumCoininsert = 0; showmenu(coin, drink); sumCoininsert = inputcoin(coinInsert); showdrinks(choice); showbalace(sumCoininsert, price); contmethod(cont); } /*****************showmenu method*****************/ public static int showmenu (int coin, int drink) { int coin; int drink; System.out.println("[Coins available : RM 1 [" + coin[0] + "] RM0.50 [ " + coin[1] + "] RM 0.20 [ " + coin[2] + "] RM0.10 [" +coin[3] "] ]"); System.out.println("[Drinks available : Pepsi [" + drink[0] + "] Coke [" + drink[1] + "] Mirinda Orange [" + drink[2] + "] 7up [" + drink[3] + "] ]"); } /********************showmenu method*****************/ /**************inputcoin method *******************/ public static double inputcoin (double coinInsert) { double coinInsert = 0, sumCoininsert = 0; Scanner sc = new Scanner(System.in); System.out.println("Insert Coin==>"); double coinInsert = sc.nextDouble(); while (coinInsert == '1' || coinInsert == '0.5' || coinInsert == '0.2' || coinInsert == '0.1') { coinInc(coinInsert); sumCoininsert = sumCoininsert + coinInsert; while (sumCoinInsert < 1.20) { System.out.println("Insert Coin==>"); double coinInsert = sc.nextDouble(); } } System.out.println (" Total :" +sumCoinInsert); } /********************inputcoin method*******************/ /***************coinInc method************************/ public static double coinInc(int coinInsert) { double coinInsert; Scanner sc = new Scanner(System.in); switch (coinInsert) { case coinInsert == '1': coin[0]++; break; case coinInsert == '0.5': coin[1]++; break; case coinInsert == '0.2': coin[2]++; break; case coinInsert == '0.1': coin[3]++; break; default: System.out.println("Invalid coin"); sumCoininsert = 0; System.out.println("Insert Coin==>"); double coinInsert = sc.nextDouble(); break; } } /******************coinInc method*********************/ /*****************showdrinks method **************/ public static int showdrinks (int choice) { int choice; System.out.println("Drinks [RM1.20]"); System.out.println("1.Pepsi" " 2.Coke" " 3.Mirinda Orange" " 4.7up"); Scanner sc = new Scanner(System.in); System.out.println("Choice==>"); int choice = sc.nextInt(); while (choice == '1' || choice == '2' || choice == '3' || choice == '4') { if (choice =='1') { drink[0]--; }else if (choice=='2') { drink[1]--; }else if (choice =='3') { drink[2]--; }else (choice == '4') { drink[3]--; } } System.out.println("Invalid choice"); System.out.println("Choice==>"); int choice = sc.nextInt(); } /*****************showdrinks method **************/ /****************showbalance method*******************/ public static double showbalance(double sumCoininsert, double price) { double price = 1.2, balance = 0, sumCoininsert; balance = sumCoininsert - price; if (balance != 0.00) { countbalance (balance); System.out.println(" Your balance is :" +balance) System.out.println(" :" +fifty+ "x50" " " +twenty+ "x20" " " +tenth+ "x10" ); }else //if (balance == 0.00) { System.out.println("Your balance is :" +balance); } } /****************showbalance method*******************/ /****************countbalance method******************/ public static double countbalance(double balance) { double balance; int ibalance = (int)(balance); int fifty = ibalance/50; int cfifty = ibalance%50; int twenty = cfifty/20; int ctwenty = cfifty%20; int tenth = ctwenty/10; int ctenth = ctwenty%10; if ( fifty != 0) { coin[1]--; } if (twenty != 0) { coin[2]--; } if (tenth != 0) { coin[3]--; } } /*************countbalance method*********************/ /************************contmethod*****************************/ public static String contmethod (char cont) { char cont; Scanner sc = new Scanner(System.in); System.out.println ("Do you want to continue? y/n :"); //input3 = in.readline(); cont = sc.charAt(0); while (cont == 'y' || cont == 'Y') { continue ; } System.out.println("Thank You, Please come again."); System.exit(0); } }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote