2016-12-20 5 views
0

私のコードはループバックするのではなく、ヒントをスキップし続けます。なぜか分かりません。私はすべてを読んで、すべてが機能しているようだが、実行しようとすると1つのアイテムを注文することができ、何か他のものを注文するかどうかを決めることさえできない。私はコーディングの初心者なので、明らかに何かが不足している可能性があります。問題の私のプログラムは、私のブール値の条件を無視してスキップし続けますか?

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); 
    } 
} 

答えて

0

ソリューションとの説明は、私たちがそれである間、あなたはオプションは1注文別の項目であるため、答えは「イエス」ではなく、1または2であるかどうかをチェックべきではありません

hereに記載されています。 2.チェックアウト。

プログラム内の関連する変数の値を表示するには、debbugerまたは少なくともSystem.out.println()を使用する必要があります。

関連する問題