Question
Hello I am building a small pizza app for class, and I am stuck on how to create a do/while loop for a Switch. The
Hello I am building a small pizza app for class, and I am stuck on how to create a do/while loop for a Switch. The goal is to have Switch(Selection2) on line 66 @ case"2" on line 72 return back to the selection menu in Switch(size) on line 41. Is a do/while the best method to achieve this? Thank you for your time. Screen shot available below written code.
import java.util.Scanner; import java.util.*;
//Create an exception for class BadInputException extends Exception{ String s; BadInputException(String s){ this.s = s; } public String toString(){ return s; } }
//Main Info Input page. Will connect to entends "PizzaSelection" with name/address/phone public class Main { public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// PizzaInput pizzaInput = new PizzaInput(); PizzaSelection pizzaSelection = new PizzaSelection(); Toppings toppings = new Toppings(); ClientEntry cE = new ClientEntry(); String fname = null; String faddress = null; String pnumber = null; // adding to the queue
System.out.println(" Hello! Welcome to Pizza Order"); System.out.println("Please review sizes and prices"); pizzaSelection.selectionList(); System.out.println("What size pizza would you like? ");
// Add switch statement here for Pizza Size Menu
String size = in.nextLine();
switch (size) {
case "1": size = "Small"; break;
case "2": size = "Medium"; break;
case "3": size = "Large"; break;
default: System.out.println("Please select a valid option."); }
System.out.println(" You choice a: " + size + " is that correct size? "+ "Press 1 for 'Yes' Press 2 for'No' ");
//Possible do/while loop String selection2 = in.nextLine(); String wrongSize = in.next(); String correctSize = in.next(); switch(selection2){ case "1": System.out.println(" Okay, you choice:" + size + " .Great!"); selection2 = "1"; break;
case "2": System.out.println(" Okay, the:" + size + " is not the correct size. Press 3 to go back and select the correct size"); selection2 = "2"; //Should i create another arraylist with the size menu// do{ if(.contains() && correctSize.equals("")){ System.out.println(""); break; } else{ System.out.println(""); } break; // hAVE TO FIGURE OUT HOW TO, IF POSSIBLE, TO LOOP CASE3 BACK TO PIZZASELECTION MENU } while();
default: System.out.println("Sorry, that's not a valid option!"); System.out.println("Enter your selection again!"); selection2 = in.nextLine(); } //break; System.out.println(" -------------------------- ");
ispert java,uth1.5canner; tmport java. utth. *; 8fCreate an exception for class BadinputException extends Exceptiont Strung s; BadInputFxception(5trtng s){ thts. 5=5 ? publuc Strung toStrungl If return s; ] f/Watn Info Input page. M11 connect to entends "Ptzza5election" with name/address/fhone v publue class Maun [ pub1ic static woid nata(5tring[] args) f Scanner tn = new Seanner(5ysten. in): 1/ P1zzaTnput pizzaTrput = ncu P1zzaTrput( ) PizzoSelection pizzeSelection = new PizzaSelection( ); Topplngs topptngs - neu Topptings() CtentEntry ct = new CLientEntry( ); String foane = nutl String faddress = rull; String pnunber = nutl; ff adding to the queue Systen, out.print Lni "Ynilellol Helcore to Pizza Order"); Systen. out.printini "Please revtew stzes and prtees"); pizzaSelection. select ionList! ]; Systen. out.println| "lhat stze pizza woutd you ltke?'n" j; ff Add swtteh statenent here for P1zza S1ze Menu Strung stie - Ln, nextlane( ): swttch \{stze| \{ case =1= size = "Small*; break; case =2z size = "Mediun" break: case=3= size = "Large" break: default: Systen-out. printlnc "Please select a valid option, "); R/Posstble do/whtle loop String selection2 = tin. nextlinec ) String wrongSize = inanext i) String correct5ize = in, nexti]; swttch(selection2)t case=14= Systen-out, print1n( "'n0kay, you choice:" + size +. Great!" ) selectuon 2=1; break; case =2= Systen.out. println("\$n0kay, the:" + size + "is not the carrect size. MnPress 3 to go back and select the correct size"); selection 2= " 2, frshould i create another arraylist with the size nemurf d iff, contans( ) 6ir correctSize, equals( (=))f 5ysten_out. printin( ==) break; \} else1 5ysten_out.prtntln( ==1; break: // hAVE TO FIGURE OUT HOW T0, IF POSSIBLE, TO LOOP CASE3 BACK T0 PIZZASELECTION MENU f whtle[1; default: Systen-out.printlin(-5orry, that's not a valtd option:"); Systen, out.println[ "Enter your selection againl"); selectionz - in. nextLtene( ) frbreakStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started