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