import java.util.Scanner;
public class CoffeeShop {
public static void main(String[] args) {
//Welcome message
String username;
System.out.println("Please enter your name");
Scanner keyboard = new Scanner(System.in);
username = keyboard.next();
System.out.println("Welcome to the Java Byte Code Coffee Shop," + username + "!");
//Menu
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. Expresso $2.00");
//Item selection
int item_Number;
System.out.println("Please enter an item number.");
Scanner item = new Scanner(System.in);
item_Number = item.nextInt();
if(item_Number == 1) {
item = 1.50;
}
if(item_Number == 2) {
item = 3.50;
}
if(item_Number == 3) {
item = 3.25;
}
if(item_Number == 4) {
item = 2.00;
}
//Item Quantity
int quantity;
System.out.println("Please enter the quantity.");
Scanner amount = new Scanner(System.in);
quantity = amount.nextInt();
double total = quantity * item;
System.out.println("Total before discount and tax is " + total);
//Discount and tax
double nuTotal;
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!");
}
}
您的任务是编写一个名为CoffeeShop的程序(在CoffeeShop.java文件中),该程序模拟虚拟咖啡店,允许用户选择要购买的物品以及数量该项目。在从用户处获得物品选择和所需数量后,程序应计算成本,税金,折扣和最终成本,然后将这些数据显示给用户。我每次尝试编译程序时都会收到多个错误。不知道我错在哪里
你得到的多个错误是什么? – APerson 2014-09-25 02:00:36
检查你的“item”变量..一旦它是一个扫描仪,然后你用它来试图存储一个double。 – 2014-09-25 02:01:09