Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import java.util.Scanner; public class ProjectPart { public static void main(String[] args) { // TODO Auto-generated method stub //Declare Constants final double POTATO_CHIPS = 1.75; final

import java.util.Scanner; public class ProjectPart { public static void main(String[] args) { // TODO Auto-generated method stub //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; 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("--------------------------------------------"); //Prompt Customer Input //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(); input.nextLine(); }//Validate number of snacks inService = false; //if else for inservice //For Loop for (; numberOfSnacks >0; numberOfSnacks--) { System.out.println("Enter snack selection:"); String snackType = input.nextLine(); //Snack Type Validation NOT EQUAL while (!snackType.equals("A1")&& !snackType.equals("A2") && !snackType.equals("A3") && !snackType.equals("B1") && !snackType.equals("B2") && !snackType.equals("B3") && !snackType.equals("C1") && !snackType.equals("C2") && snackType.equals("C3")) { System.out.println("Invalid Entry: Enter valid snack"); snackType = input.nextLine()

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_2

Step: 3

blur-text-image_3

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 does physics deal with?

Answered: 1 week ago

Question

Enumerate the qualities of a salesman.

Answered: 1 week ago