Ich arbeite bei Jimmy John und ich arbeite an einem Test für die Sandwiches. Ich habe die Grundstruktur verloren, aber wenn Sie die falsche Frage beantworten, geht es weiter zur nächsten Frage. Ich brauche es, um die Frage erneut zu stellen und dann in der Schleife weiterzumachen. Hier ist der Code:Einfache Testprogramm Schleife Probleme
package Practice;
import java.util.Scanner;
public class jimmyTest {
public static void main (String args[]){
int age, menuItem;
String tomato, lettuce, mayo, ham, turkey, tuna, beef, capicola, salami, cheese, onion, sauce, oregano, avacado, dijon, sprouts;
tomato = ("Tomato");
lettuce = ("lettuce");
mayo = ("mayo");
ham = ("ham");
turkey = ("turkey");
beef = ("beef");
capicola = ("capicola");
salami = ("Salami");
cheese = ("cheese");
onion = ("onion");
sauce = ("sauce");
oregano = ("oregano");
avacado = ("avacado");
dijon = ("dijon");
sprouts = ("sprouts");
tuna = ("tuna");
Scanner item = new Scanner(System.in);
Scanner item1 = new Scanner(System.in);
Scanner item2 = new Scanner(System.in);
Scanner item3= new Scanner(System.in);
Scanner item4 = new Scanner(System.in);
Scanner item5 = new Scanner(System.in);
Scanner item6 = new Scanner(System.in);
Scanner item7 = new Scanner(System.in);
Scanner item9 = new Scanner(System.in);
Scanner item10 = new Scanner(System.in);
Scanner item11 = new Scanner(System.in);
Scanner item12 = new Scanner(System.in);
Scanner item13 = new Scanner(System.in);
Scanner item14 = new Scanner(System.in);
Scanner item15 = new Scanner(System.in);
Scanner item16 = new Scanner(System.in);
Scanner item17 = new Scanner(System.in);
Scanner item18 = new Scanner(System.in);
Scanner finished = new Scanner(System.in);
String scan1, scan2, scan3, scan4, scan5, scan6, scan7, scan8, scan9, scan10, scan11, scan12, scan13, scan14, scan15, scan16, scan17, scan18, fin;
/*
* scan1 = item1.next();
* scan2 = item2.next();
* scan3 = item3.next();
* scan4 = item4.next();
* scan5 = item5.next();
* scan6 = item6.next();
* scan7 = item7.next();
* scan8 = item8.next();
* scan9 = item9.next();
* scan10 = item10.next();
* scan11 = item11.next();
* scan12 = item12.next();
* scan13 = item13.next();
* scan14 = item14.next();
* scan15 = item15.next();
* scan16 = item16.next();
* scan17 = item17.next();
* scan18 = item18.next();
* fin = finished.next();
*
*/
System.out.println("This is a test over the Jimmy Johns menu. a menu Item will appear, enter each");
System.out.println("item that goes into the sandwich and press enter as you type each item.");
menuItem = 0;
int points;
points = 0;
do {
switch (menuItem){
case 0:
System.out.println("What items are on the Slim 1 from the bread up");
scan1 = item1.next();
scan2 = item2.next();
if (scan1.contains(ham) && scan2.contains(cheese)){
System.out.println("Great job!");
menuItem =+ 1;
points++;
System.out.println(points);
}
else{
System.out.println("Lets try that again!");
}
//*****************************
case 1:
System.out.println("What items are on the Slim 2 from the bread up");
scan1 = item1.next();
if (scan1.contains(beef)){
System.out.println("Great job!");
menuItem =+ 1;
points++;
System.out.println(points);
}
else{
System.out.println("Lets try that again!");
menuItem = 1;
points = 1;
scan1 = item1.next();
}
//***********************************8
case 2:
System.out.println("What items are on the Slim 3 from the bread up");
scan1 = item1.next();
if (scan1.contains(tuna)){
System.out.println("Great job!");
menuItem =+ 1;
points++;
System.out.println(points);
}
else{
System.out.println("Lets try that again!");
menuItem = 2;
}
case 3:
System.out.println("What items are on the Slim 4 from the bread up");
scan1 = item1.next();
if (scan1.contains(turkey)){
System.out.println("Great job!");
menuItem =+ 1;
points++;
System.out.println(points);
}
else{
System.out.println("Lets try that again!");
menuItem = 3;
}
case 4:
System.out.println("What items are on the Slim 5 from the bread up");
scan1 = item1.next();
scan2 = item2.next();
scan3 = item3.next();
if (scan1.contains(salami) && scan2.contains(capicola) && scan3.contains(cheese)){
System.out.println("Great job!");
menuItem =+ 1;
points++;
System.out.println(points);
}
else{
System.out.println("Lets try that again!");
menuItem = 4;
}
case 5:
System.out.println("What items are on the Slim 6 from the bread up");
scan1 = item1.next();
scan2 = item2.next();
scan3 = item3.next();
if (scan1.contains(cheese) && scan2.contains(cheese)){
System.out.println("Great job!");
menuItem =+ 1;
points++;
System.out.println(points);
}
else{
System.out.println("Lets try that again!");
menuItem = 5;
}
break;
case 6:
System.out.println("What items are on the #1 Pepe from the bread up");
break;
case 7:
System.out.println("What items are on the #2 Big John from the bread up");
break;
case 8:
System.out.println("What items are on the #3 Totally Tuna from the bread up");
break;
case 9:
System.out.println("What items are on the #4 Turkey Tom from the bread up");
break;
case 10:
System.out.println("What items are on the #5 Vito from the bread up");
break;
case 11:
System.out.println("What items are on the #6 Veggie from the bread up");
break;
case 12:
System.out.println("What items are on the JJBLT from the bread up");
break;
case 13:
System.out.println("What items are on the #7 Smoked Ham Club from the bread up");
break;
case 14:
System.out.println("What items are on the #8 Billy Club from the bread up");
break;
case 15:
System.out.println("What items are on the #9 Italian Club from the bread up");
break;
case 16:
System.out.println("What items are on the #10 Hunters Club from the bread up");
break;
case 17:
System.out.println("What items are on the #11 Country Club from the bread up");
break;
case 18:
System.out.println("What items are on the #12 Beach Club from the bread up");
break;
case 19:
System.out.println("What items are on the #13 Veggie Club from the bread up");
break;
case 20:
System.out.println("What items are on the #14 Bootlegger Club from the bread up");
break;
case 21:
System.out.println("What items are on the #15 Club Tuna from the bread up");
break;
case 22:
System.out.println("What items are on the #16 Club Lulu from the bread up");
break;
case 23:
System.out.println("What items are on the #17 Ultimate Porker from the bread up");
break;
case 24:
System.out.println("What items are on the Gargantuan from the bread up");
break;
}
return;
}while(points < 24);
}
Jede Hilfe würde sehr geschätzt werden!
Danke,
Quinten
hinzufügen 'break' Anweisung an das Ende der jeweils Klausel. Lesen Sie 'switch' in Java nach. Außerdem machst du unzählige falsche Dinge. Ich würde empfehlen, ein Online-Tutorial zu finden, um loszulegen. Das Erstellen von Dutzenden von Scanner-Instanzen ist nicht die Art, Daten zu lesen. – Kon
Sie benötigen nur einen 'Scanner', der auf' System.in' zeigt. Außerdem brauchen Sie keine Variablen für jeden String-Wert, wenn Sie sie nicht ändern oder einen kürzeren Namen verwenden. Verwenden Sie einfach die Zeichenfolgenliterale in Ihrem Code. – 4castle
Sie verwenden auch '= +' anstelle von '+ ='. Es gibt einen großen Unterschied. Einer weist eine positive Zahl zu, der andere erhöht die Variable um eine Zahl. – 4castle