需求1:
package www.hpe.com.test;
import java.util.Scanner;
public class PrintTag2 {
public static void main(String[] args) {
int[][] num = new int[][] { { 245, 2, 490 }, { 570, 1, 570 },
{ 320, 1, 320 } };
String[] name = new String[] { "T恤", "网球鞋", "网球拍" };
System.out.println("**********消费单**************");
System.out.println("购买物品\t单价\t个数\t金额\t");
for (int i = 0; i < num.length; i++) {
System.out.println(name[i] + "\t¥:" + num[i][0] + "\t" + num[i][1]
+ "\t" + num[i][2]);
}
// double dis;
Scanner sc = new Scanner(System.in);
// System.out.println("输入折扣");
// dis=sc.nextDouble();
// System.out.println("你输入的折扣为:");
while (true) {
System.out.println("输入商品编号:\n1.T恤 2.网球鞋 3.网球拍");
System.out.println("请输入你要选择的商品编号:");
int id = sc.nextInt();
System.out.println("请输入商品数量:");
int count=sc.nextInt();
int heji=0;
switch (id) {
case 1:
heji=count*num[0][0];
System.out.println(name[0] + ",单价:" + num[0][0]+",合计:"+heji);
break;
case 2:
heji=count*num[1][0];
System.out.println(name[1] + ",单价:" + num[1][0]+",合计:"+heji);
break;
case 3:
heji=count*num[2][0];
System.out.println(name[2] + ",单价:" + num[2][0]+",合计:"+heji);
break;
default:
System.out.println("没有该商品的编号");
break;
}
int dis=0;
System.out.println("输入折扣:");
dis=sc.nextInt();
int heji2=heji*dis/10;
System.out.println("您输入的商品为:"+name[id-1]+"\n合计:"+heji+"\n折扣为:"+dis+"\n打折后的价钱为:"+heji2);
System.out.println("是否继续y/n");
String str = sc.next();
if (str.equals("n")) {
break;
}
}
}
}