学习java半个月,还不懂以下代码,还有救吗?
作者:互联网
package day05;
import java.util.Scanner;
public class cs_test01 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
boolean flas = true;// 用来控制功能指令
boolean flas1 = true;// 用来控制商品选择
boolean zhuc = false;// 用来控制登入,判断是否注册
boolean dengr = false;// 用于控制购物,判断是否登入
boolean gouwu = false;// 用于控制抽奖,判断是否购物
String username = "";
String userpassword = "";
double total = 0;// 折后总金额
System.out.println("***********************************超市*****************************");
while (flas) {
System.out.println("*****欢迎进入超市系统*******");
System.out.println("1.注册\t2.登入\t3.购物\t4.抽奖\t5.退出");
System.out.print("请输入功能编号:");
String choose = sc.next();
switch (choose) {
case "1":
System.out.println("**************注册模块**************");
System.out.print("请输入要注册的账号:");
username = sc.next();
System.out.print("请输入要您的的密码:");
userpassword = sc.next();
System.out.println("注册成功!");
zhuc = true;
break;
case "2":
System.out.println("**************登入模块**************");
if (zhuc) {
int i = 3;
while (i > 0) {
i--;
System.out.print("请输入您的账号:");
String iname = sc.next();
System.out.print("请输入您的密码:");
String ipassword = sc.next();
if (username.equals(iname) && userpassword.equals(ipassword)) {
System.out.println("登入成功!");
dengr = true;
break;
} else {
System.out.println("登入失败,您还有" + i + "次登入机会");
}
}
} else {
System.out.println("您还没注册!请先注册!");
}
break;
case "3":
System.out.println("*************购物模块***))**********");
double playmoney = 0;// 支付金额
String wuping = "";// 商品名称
double price = 0;// 价格
int count = 0;// 数量
double sum = 0;// 金额
if (dengr) {
total=0;
String flas2 = "y";// 用于控制是否继续购物
while ("y".equals(flas2)) {
flas1 = true;
while (flas1) {
flas1 = false;
System.out.println("商品列表:\t1.衣服\t2.裤子\t3.鞋子\t4.帽子");
System.out.println("价格单位:\t1.30¥\t2.35¥\t3.55¥\t4.10¥");
System.out.print("请输入您要购买的商品编号:");
int bianhao = sc.nextInt();
if (1 == bianhao) {
wuping = "衣服";
price = 30;
} else if (2 == bianhao) {
wuping = "裤子";
price = 35;
} else if (3 == bianhao) {
wuping = "鞋子";
price = 55;
} else if (4 == bianhao) {
wuping = "帽子";
price = 10;
} else {
System.out.println("输入有误!请重新输入!");
flas1 = true;
}
}
System.out.print("输入您要购买的数量:");
count = sc.nextInt();
System.out.println("您选择的商品是:" + wuping + ", 价格是:" + price + ", 数量是:" + count);
sum = price * count;
System.out.println("您所需支付的金额是:" + sum);
total =total+sum;
System.out.print("是否选择继续购物y/n:");
flas2 = sc.next();
}
if (total >= 500) {
System.out.println("您所选购的物品总金额是:" + total);
System.out.println("由于您所购物拼大于500元,可打8折优惠");
total = total* 0.8;
System.out.println("打完折后总金额是:" + total);
System.out.print("您所支付的金额是:");
playmoney = sc.nextDouble();
while (playmoney < total) {
System.out.println("支付失败!请重新支付!");
System.out.print("您所支付的金额是:");
playmoney = sc.nextDouble();
}
System.out.println("支付成功!");
System.out.println("找零:" + (playmoney - total));
gouwu = true;
} else {
System.out.println("您所选购的物品总金额是:" + total);
System.out.print("您所支付的金额是:");
playmoney = sc.nextDouble();
while (playmoney < total) {
System.out.println("支付失败!请重新支付!");
System.out.print("您所支付的金额是:");
playmoney = sc.nextDouble();
}
System.out.println("支付成功!");
System.out.println("找零:" + (playmoney - total));
gouwu = true;
}
} else {
System.out.println("您还没登入!请先登入!");
}
break;
case "4":
System.out.println("**************抽奖模块**************");
if (gouwu) {
if (total > 500) {
int ra = (int) (Math.random() * 15) + 1;
if (ra == 1) {
System.out.println("冰箱一台");
} else if (ra == 2) {
System.out.println("空调一台");
} else if (ra < 5) {
System.out.println("花生油一瓶");
} else if (ra < 9) {
System.out.println("香皂一盒");
} else
System.out.println("谢谢惠顾");
} else {
System.out.println("抱歉!您打完折后不足500元,不能抽奖!");
}
} else {
System.out.println("您还没购物!请先购物!");
}
break;
case "5":
System.out.println("**************退出模块**************");
System.out.print("是否退出,y/n:");
String tuichu = sc.next();
if ("y".equals(tuichu)) {
flas = false;
System.out.println("退出系统!欢迎下次光临!");
} else
flas = true;
break;
default:
System.out.println("输入有误!请重新输入:");
break;
}
}
sc.close();
}
}
标签:java,代码,System,else,sc,半个,println,total,out 来源: https://blog.csdn.net/qq_51800990/article/details/117952846