2016-12-20 2 views
0

Mein Code springt weiter zum Tipp statt zurück zu laufen und ich verstehe nicht warum. Ich lese die ganze Sache durch und alles scheint zu funktionieren, aber wenn ich versuche zu laufen, erlaubt es mir, einen Gegenstand zu bestellen und erlaubt mir nicht einmal zu entscheiden, ob ich etwas anderes bestellen möchte. Ich bin ein Anfänger zum Codieren, also vermisse ich wahrscheinlich etwas Offensichtliches.Mein Programm ignoriert ständig die Bedingungen meines Boolean?

import java.util.*; 

public class OnlineOrdersFallonBryan 
{ 
    public double value = 0; 
    public double cost = 0; 
    Scanner in = new Scanner(System.in); 
    public void main() 
    { 
     System.out.println("Welcome to Vegi-Man's Online Ordering!"); 
     boolean rightorWrong = true; 
     while (rightorWrong == true) 
     { 
     System.out.println("Menu:"); 
     System.out.println("1. Vegi Burger    $3.00"); 
     System.out.println("2. Chicken-less Chicken Wings $4.00"); 
     System.out.println("3. Fried Vegis    $2.00"); 
     System.out.println("4. Vegan Milkshake   $1.50"); 
     System.out.println("5. Double Vegi Burger   $5.00"); 
     System.out.println("6. Onion Rings    $2.00"); 
     System.out.println("7. Fried Vegi of choice  $2.00"); 
     System.out.println("8. Vegan Icecream    $1.50"); 
     System.out.println("9. Vegan Chocolate Lava Cake $4.50"); 
     System.out.println("10. Vegan Cheese or Sauces $0.50"); 
     System.out.println(""); 
     System.out.println("Select a menu item: "); 
     double menuchoice = in.nextDouble(); 
     if (menuchoice == 1) 
     { 
      value = cost + 3; 
      System.out.println(); 
      System.out.println("Your current total is $" + cost + "."); 
      System.out.println("Options: "); 
      System.out.println("1. Order another item."); 
      System.out.println("2. Checkout."); 
      System.out.println(); 
      System.out.println("Select an option: "); 
      String answer1 = in.nextLine(); 
      rightorWrong = answer1.equalsIgnoreCase("yes"); 
     } 
     if (menuchoice == 2) 
     { 
      value = cost + 4; 
      System.out.println(); 
      System.out.println("Your current total is $" + cost + "."); 
      System.out.println("Options: "); 
      System.out.println("1. Order another item."); 
      System.out.println("2. Checkout."); 
      System.out.println(); 
      System.out.println("Select an option: "); 
      String answer1 = in.nextLine(); 
      rightorWrong = answer1.equalsIgnoreCase("yes"); 
     } 
     if (menuchoice == 3) 
     { 
      value = cost + 2; 
      System.out.println(); 
      System.out.println("Your current total is $" + cost + "."); 
      System.out.println("Options: "); 
      System.out.println("1. Order another item."); 
      System.out.println("2. Checkout."); 
      System.out.println(); 
      System.out.println("Select an option: "); 
      String answer1 = in.nextLine(); 
      rightorWrong = answer1.equalsIgnoreCase("yes"); 
     } 
      if (menuchoice == 4) 
    { 
      value = cost + 1.5; 
      System.out.println(); 
      System.out.println("Your current total is $" + cost + "."); 
      System.out.println("Options: "); 
      System.out.println("1. Order another item."); 
      System.out.println("2. Checkout."); 
      System.out.println(); 
      System.out.println("Select an option: "); 
      String answer1 = in.nextLine(); 
      rightorWrong = answer1.equalsIgnoreCase("yes"); 
     } 
     if (menuchoice == 5) 
     { 
     value = cost + 5; 
     System.out.println(); 
     System.out.println("Your current total is $" + cost + "."); 
     System.out.println("Options: "); 
     System.out.println("1. Order another item."); 
     System.out.println("2. Checkout."); 
     System.out.println(); 
     System.out.println("Select an option: "); 
     String answer1 = in.nextLine(); 
     rightorWrong = answer1.equalsIgnoreCase("yes"); 
    } 
     if (menuchoice == 6) 
    { 
      value = cost + 2; 
      System.out.println(); 
      System.out.println("Your current total is $" + cost + "."); 
      System.out.println("Options: "); 
      System.out.println("1. Order another item."); 
      System.out.println("2. Checkout."); 
      System.out.println(); 
      System.out.println("Select an option: "); 
      String answer1 = in.nextLine(); 
      rightorWrong = answer1.equalsIgnoreCase("yes"); 
     } 
     if (menuchoice == 7) 
     { 
      value = cost + 2; 
      System.out.println(); 
      System.out.println("Your current total is $" + cost + "."); 
      System.out.println("Options: "); 
      System.out.println("1. Order another item."); 
      System.out.println("2. Checkout."); 
      System.out.println(); 
      System.out.println("Select an option: "); 
      String answer1 = in.nextLine(); 
      rightorWrong = answer1.equalsIgnoreCase("yes"); 
     } 
     if (menuchoice == 8) 
     { 
      value = cost + 1.5; 
      System.out.println(); 
      System.out.println("Your current total is $" + cost + "."); 
      System.out.println("Options: "); 
      System.out.println("1. Order another item."); 
      System.out.println("2. Checkout."); 
      System.out.println(); 
      System.out.println("Select an option: "); 
      String answer1 = in.nextLine(); 
      rightorWrong = answer1.equalsIgnoreCase("yes"); 
      } 
     if (menuchoice == 9) 
     { 
      value = cost + 4.5; 
      System.out.println(); 
      System.out.println("Your current total is $" + cost + "."); 
      System.out.println("Options: "); 
      System.out.println("1. Order another item."); 
      System.out.println("2. Checkout."); 
      System.out.println(); 
      System.out.println("Select an option: "); 
      String answer1 = in.nextLine(); 
      rightorWrong = answer1.equalsIgnoreCase("yes"); 
     } 
     if (menuchoice == 10) 
     { 
      value = cost + 0.5; 
      System.out.println(); 
      System.out.println("Your current total is $" + cost + "."); 
      System.out.println("Options: "); 
      System.out.println("1. Order another item."); 
      System.out.println("2. Checkout."); 
      System.out.println(); 
      System.out.println("Select an option: "); 
      String answer1 = in.nextLine(); 
      rightorWrong = answer1.equalsIgnoreCase("yes"); 
     } 
    } 
    if (rightorWrong == false) 
    { 
     response1(); 
    } 
    } 
    public void response1() 
    { 
     System.out.println("Subtotal (with tax): $" + value * 1.0825); 
     System.out.println("Tip: $"); 
     double tip = in.nextDouble(); 
     double total = value + tip; 
     System.out.println("Final Total: $" + total); 
    } 
} 

Antwort

0

Lösung und Erklärung des Problems ist here beschrieben

Während wir gerade dabei sind, sollten Sie nicht, wenn Antwort „Ja“ ist, sondern 1 oder 2, weil Optionen 1.Order ein anderes Element sind. und 2. Checkout.

Sie sollten debbuger oder mindestens System.out.println() verwenden, um Werte relevanter Variablen in Ihrem Programm anzuzeigen.

Verwandte Themen