Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

//Declare Constants final double POTATO_CHIPS = 1.75; final double PRETZELS = 1.50; final double KIND_BAR = 0.80; final String Snack1 = Potato Chips; final String

//Declare Constants final double POTATO_CHIPS = 1.75; final double PRETZELS = 1.50; final double KIND_BAR = 0.80; final String Snack1 = "Potato Chips"; final String Snack2 = "Pretzels"; final String Snack3 = "Kind Bar"; //Declare Variables int potatoChipCount = 0; int pretzelCount = 0; int kindBarCount = 0; int snackCount = 0; double totalAmount = 0.0; boolean inService = true; //Greet to start vending loop System.out.println("Hello"); System.out.println("How many snacks would you like? Limit is 3"); Scanner input = new Scanner(System.in); int numberOfSnacks = input.nextInt(); while(inService) { //Display Options System.out.println("*********************************************"); System.out.println(" Snack Machine "); System.out.println("*********************************************"); System.out.println(""); System.out.println("Potato Chips"+" "+"Potato Chips"+" "+"Potato Chips"); System.out.println(""); System.out.println("A1"+" "+"$ 1.75"+" "+"A2 "+"$ 1.75"+" "+"A3 "+" "+"$"+"1.75"); System.out.println("--------------------------------------------"); System.out.println(""); System.out.println("Pretzels"+" "+"Pretzels"+" "+"Pretzels"); System.out.println(""); System.out.println("A1"+" "+"$"+"1.50"+" "+"A2 "+"$"+"1.50"+" A3"+" "+"$"+"1.50"); System.out.println("--------------------------------------------"); System.out.println(""); System.out.println("Kind Bar"+" "+"Kind Bar"+" "+"Kind Bar"); System.out.println(""); System.out.println("A1"+" "+"$"+"0.80"+" "+"A2 "+"$"+"0.80"+" A3"+" "+"$"+"0.80"); System.out.println("--------------------------------------------"); //Validation loop correct while ((numberOfSnacks <1 && numberofsnacks>3) && numberOfSnacks != 999) { System.out.println("Invalid Entry: Enter a number between 1 and 3"); numberOfSnacks = input.nextInt(); }//while validation inService = false; //if else for inservice //For Loop for (; numberOfSnacks >0; numberOfSnacks--) { System.out.println("Enter snack selection:"); String snackType = input.nextLine(); if(snackType.equals("A1") || snackType.equals("A2") || snackType.equals("A3")) { System.out.println("--------------------------"); System.out.println("----Selection" +snackType+"----"); System.out.println("--------------------------"); System.out.println(" Snack Item:"+" "+Snack1); System.out.println(" Snack Price:"+" "+POTATO_CHIPS); System.out.println(""); potatoChipCount++; totalAmount += POTATO_CHIPS; }//Potato Chips Selection else if(snackType.equals("B1") || snackType.equals("B2") || snackType.equals("B3")) { System.out.println("-----------------------"); System.out.println("----Selection" +snackType+"----"); System.out.println("-----------------------"); System.out.println(" Snack Item:"+" "+Snack2); System.out.println(" Snack Price:"+" "+PRETZELS); System.out.println(""); pretzelCount++; totalAmount += PRETZELS; } else if(snackType.equals("C1") || snackType.equals("C2") || snackType.equals("C3")) { System.out.println("-----------------------"); System.out.println("----Selection" +snackType+"----"); System.out.println("-----------------------"); System.out.println(" Snack Item:"+" "+Snack3); System.out.println(" Snack Price:"+" "+KIND_BAR); System.out.println(""); kindBarCount++; totalAmount += KIND_BAR; } else { System.out.println("Invalid Entry: Enter valid snack"); numberOfSnacks++; // To repeat the current iteration } System.out.println("Invalid Entry: Enter valid snack"); snackType = input.nextLine(); }//For loop Vending / Validation }//In Service

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Mobile Communications

Authors: Jochen Schiller

2nd edition

978-0321123817, 321123816, 978-8131724262

More Books

Students also viewed these Programming questions

Question

What events can result in autoimmune disease?

Answered: 1 week ago