【发布时间】:2020-04-23 04:56:13
【问题描述】:
(还没完结。)
在向用户询问订单后,我不知道如何获得总价。示例:我订购了 5 个 Piatos,然后输入 end 以显示结果或总数,但它只显示 20 但它应该是 100,因为 20+20+20+20+20 = 100。我如何将这些单独的价格相加所以它显示正确的总价格而不改变订购物品的方式? (即只选择为每个项目提供的字母。)
import java.util.Scanner;
public class Point_Of_Sale_System_Real {
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
Intro();
}
public static void Intro(){
int Piatos = 20, Vcut = 20;
double itemtotal = 0, itemtotalvisible, itemlone = 0;
String Ia = "a";
String Ib = "b";
System.out.println("Enter the letter that matches the item here: ");
System.out.println("Type \"End\" to stop selecting from the menu." );
String itemselect = "";
do {
itemselect = sc.nextLine();
if (itemselect.equalsIgnoreCase(Ia)){
itemlone = 0 + Piatos;
}
else if (itemselect.equalsIgnoreCase(Ib)){
itemlone = 0 + Vcut;
}
}
while (!itemselect.equalsIgnoreCase("end"));
itemtotalvisible = itemlone + 0;
System.out.println("Total" + itemtotalvisible);
}
}
【问题讨论】: