while+switch
package com.itheima.fiest;
import java.util.*;
public class zuoye3 {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
System.out.println("MyShopping管理系统>购物结算\n");
System.out.println("**********************************************");
System.out.println("请选择购买的商品编号:\n1.T恤\t2.网球鞋\t3.网球拍");
System.out.println("**********************************************");
String choose="y"; //
String name=""; //
double m=0.0; //
double zong=0.0; //
double zhe=0.8;
while(choose.equals("y")) { //
System.out.print("\n请输入商品编号:");
int num=input.nextInt();
System.out.print("请输入购买数量:");
int shu=input.nextInt();
switch(num) {
case 1:
name="T恤";
m=245.0;
break;
case 2:
name="网球鞋";
m=570.0;
break;
case 3:
name="网球拍";
m=333.0;
break;
}
System.out.println(name+"¥"+m+"\t"+"数量"+shu+"\t合计"+"¥"+(m*shu)); //
zong=m*shu; //
System.out.print("是否继续购买(y/n)");
choose=input.next(); //注意
}
System.out.println("\n折扣:"+zhe);
System.out.println("应付金额:"+zong*zhe); //
System.out.print("实付金额:");
double s=input.nextDouble();
System.out.println("找钱:"+(s-zong*zhe));
System.out.println("程序结束!"); //
}
}