Question: This is my current code please help me fix it to fit the guide lines below: import java.util.Scanner; public class Solution { // static arrays

This is my current code please help me fix it to fit the guide lines below:

import java.util.Scanner;

public class Solution {

// static arrays for our data. Alternatively if this becomes big, then we can use a better data

// structure like a map

private static final String[] BEVERAGES = {"Coke", "Pepsi", "Water"};

private static final double[] BEVERAGE_PRICES = {1.50, 1.75, 1};

private static int[] drink_counts = {10, 10, 10};

public static void main (String[] args) {

@SuppressWarnings("resource")

Scanner sc = new Scanner(System.in);

// this is done for continous execution of the program. This program has to be killed to stop.

while (true) {

System.out.println("Hello there, For a beverage, please make a selection on the keypad!");

System.out.println("Your choices are: "

+ "\t Coke : A1 "

+ "\t Pepsi: B2 "

+ "\t Water: C3 ");

String userChoice = sc.next();

// simple switch based on interal beverage Id. The ids are hardcoded right now, but if the choice list

// becomes big, we can always create a static unmodifiable map.

int beverageId = -1;

switch(userChoice) {

case "A1":

beverageId = 0;

break;

case "B2":

beverageId = 1;

break;

case "C3":

beverageId = 2;

break;

default:

System.err.println("Invalid Selection");

break;

}

if (beverageId != -1) {

System.out.println(String.format("$%.2f", BEVERAGE_PRICES[beverageId]));

System.out.println();

} else {

continue;

}

// outer if-else checks the beverage counts

if (drink_counts[beverageId] > 0) {

drink_counts[beverageId] = drink_counts[beverageId] - 1;

System.out.println("Please enter the amount in $1 or $5 bills ");

int amount = 0;

String more = "y";

// while loop to collect amount from the user

while (!more.equalsIgnoreCase("n")) {

String amountEntered = sc.next();

if (!amountEntered.equals("1") && !amountEntered.equals("5")) {

System.err.println("Invalid amount. Please try again");

more = "y";

continue;

}

amount += Integer.parseInt(amountEntered);

System.out.println("Would you like to enter more: (y)");

more = sc.next().toLowerCase();

}

if (amount BEVERAGE_PRICES[beverageId]) {

System.err.println("Amount less than needed. transaction cancelled.");

} else if (amount == BEVERAGE_PRICES[beverageId]) {

System.out.println("Thank you! Enjoy your Beverage!");

}

else {

// display message after collecting amount and calculating change.

System.out.println(String.format("Here is your change: $%.2f", amount - BEVERAGE_PRICES[beverageId]));

}

} else {

System.err.println("Sorry. We are out of that beverage");

}

}

}

}

This is my current code please help me fix it to fit

the guide lines below: import java.util.Scanner; public class Solution { // static

Enhance Lab 2 so that a service technician can re-program the keypad to accept new user inputs and modify the favorite beverages. All functions from Lab 2 work the same. A service technician enters 0000#, your program presents a menu and operates continuously until user exit the menu: 1) Add new beverage 2) Remove beverage 3) Update beverage price A service technician can also re-program the logical truth values for C1, C2, C3 for any of the favorite beverages. The vending machine can be programed up to 8 favorite beverages as indicated all possible values in the truth table. Once the vending machine is re-programed, your program presents the user with a choice of the favorite beverages. Then allow the user to choose a beverage by entering a pair of input. The output which beverage user choses. Let A set of favorite beverages = {a0, al, a2, a3, a4, a5, a, a7} such that a0, al..., a7 can be any favorite beverages. Let B set of valid user input = {(A, 1), (A, 2), (A, 3), ... (D10)} such that any ordered pair can be re-programed for any of the favorite beverage in set A. Output Input For output Display the drink cost any C2 C3 any 0 0 0 Price is programmable User Input from the keyboard Any element in set B Any element in set B Any element in set B Any element in set B Any element in set B any 0 0 1 Price is programmable any 0 1 0 Price is programmable any Price is programmable any 0 0 Price is programmable any 0 1 Price is programmable Any element in set B Any element in set B Any element in set B Any element in set B any 1 0 Price is programmable any 1 1 Price is programmable All Lab 2 functionalities remain working the same and remain intact. Your program should operate continuously with a list of drinks and their costs displayed on screen. Example of the keypad: INSTRUCTIONS 1 For price ol desired item press corresponding A 12 B 34 C 56 : D78 # 9 10 2 3 4 Price appears on display Insert coins Make selection on key pad 17 Once a user has selected their drink the system should allow them to enter the amount of money they are inserting into the machine. The program should then calculate the amount of change to be returned and subtract one from the number of the drink in the machine. If the user selects a drink which has sold out an appropriate message should be displayed. Some input validation should be carried out on the selection from the true table. Arrays must be used and an expected looping menu-structure of the keypad. Enhance Lab 2 so that a service technician can re-program the keypad to accept new user inputs and modify the favorite beverages. All functions from Lab 2 work the same. A service technician enters 0000#, your program presents a menu and operates continuously until user exit the menu: 1) Add new beverage 2) Remove beverage 3) Update beverage price A service technician can also re-program the logical truth values for C1, C2, C3 for any of the favorite beverages. The vending machine can be programed up to 8 favorite beverages as indicated all possible values in the truth table. Once the vending machine is re-programed, your program presents the user with a choice of the favorite beverages. Then allow the user to choose a beverage by entering a pair of input. The output which beverage user choses. Let A set of favorite beverages = {a0, al, a2, a3, a4, a5, a, a7} such that a0, al..., a7 can be any favorite beverages. Let B set of valid user input = {(A, 1), (A, 2), (A, 3), ... (D10)} such that any ordered pair can be re-programed for any of the favorite beverage in set A. Output Input For output Display the drink cost any C2 C3 any 0 0 0 Price is programmable User Input from the keyboard Any element in set B Any element in set B Any element in set B Any element in set B Any element in set B any 0 0 1 Price is programmable any 0 1 0 Price is programmable any Price is programmable any 0 0 Price is programmable any 0 1 Price is programmable Any element in set B Any element in set B Any element in set B Any element in set B any 1 0 Price is programmable any 1 1 Price is programmable All Lab 2 functionalities remain working the same and remain intact. Your program should operate continuously with a list of drinks and their costs displayed on screen. Example of the keypad: INSTRUCTIONS 1 For price ol desired item press corresponding A 12 B 34 C 56 : D78 # 9 10 2 3 4 Price appears on display Insert coins Make selection on key pad 17 Once a user has selected their drink the system should allow them to enter the amount of money they are inserting into the machine. The program should then calculate the amount of change to be returned and subtract one from the number of the drink in the machine. If the user selects a drink which has sold out an appropriate message should be displayed. Some input validation should be carried out on the selection from the true table. Arrays must be used and an expected looping menu-structure of the keypad

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!