我继续为我的输出获取0.0。我不知道我做错了什么。任何帮助,将不胜感激。获取0代替预期计算的输出
我前几部分的用户输入正常,并且数字正确显示。它只是要求总量和随后的数学,我得到的0.0,0.0的时候,0.0
import java.util.Scanner;
public class CoffeeShop {
public static void main(String[] args) {
//Welcome Message and name prompt
String username;
System.out.println("What is your name?");
Scanner keyboard = new Scanner(System.in);
username = keyboard.next();
System.out.println("Welcome to the Java Byte Code Coffee Shop," + username + "!");
//Menus
System.out.println("Here is our menu.");
System.out.println("1. Coffee $1.50");
System.out.println("2. Latte $3.50");
System.out.println("3. Cappuccino $3.25");
System.out.println("4. Espresso $2.00");
//What item do they want?
int product_Number;
System.out.println("Please enter the item number.");
Scanner item = new Scanner(System.in);
product_Number = item.nextInt();
System.out.println("You selected item " + product_Number);
double product;
if (product_Number == 1) {
product = 1.50;
}
if (product_Number == 2) {
product = 3.50;
}
if (product_Number == 3) {
product = 3.25;
}
if (product_Number == 4) {
product = 2.00;
} else {
product = 0.00;
}
//Quantity of item
int quantity;
System.out.println("How many would you like?");
Scanner amount = new Scanner(System.in);
quantity = amount.nextInt();
System.out.println("You want " + quantity + " of them!");
//Testing Product
double total = quantity * product;
System.out.println("Total before discount and tax is " + total);
double nuTotal;
//Discount/Tax
if (total >= 10) {
nuTotal = total - (total * .1);
} else {
nuTotal = total;
}
System.out.println("Your total with discount is " + nuTotal);
double totalTax = nuTotal * .07;
System.out.println("Your total with tax is " + totalTax);
System.out.println("Thank you " + username + "! Please stop by again!");
}
}
所以把更多的调试输出,并追查到底哪一行是“丢失”你的值... –
请发布质量好的代码 - 这种压痕伤害眼睛! –
@kittyPL:修正了缩进。使用IntelliJ或任何自动格式化IDE并不困难,因此花两分钟做这件事有什么坏处? – Makoto