项目流程:所选择的商品价格和商品数量,每统计一次,计算总价,之后总价进行累加,最后选择退出或者清空total的内存空间。进行下一次的结账;
package com.zhiyou100;
import java.util.Scanner;
import java.util.function.Predicate;
public class MyShop {
public static void main(String[] args) {
boolean sc =true;
while (sc) {
double total=0;
Scanner scanner =new Scanner(System.in);
System.out.println("欢迎来到我的商店!");
while (true) {
System.out.print("请输入单价:");
double price=scanner.nextDouble();
System.out.print("请输入数量:");
int number=scanner.nextInt();
total+=price*number;
System.out.printf("累计结果:¥:%.2f %n", total);
System.out.println("清零请按c,退出请按q,继续请按任意键");
scanner.nextLine();
String flog=scanner.nextLine();
if (flog.equals("c")) {
total=0;
}else if (flog.equals("q")) {
sc=false;
break;
}else {
continue;//continue 继续
}
}
}
}
}