java语言代码完整代码
(希望对你有所有帮助)
package cn.shijie.test;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class test1 {
static mproduct m1 = new mproduct();
static mproduct m2 = new mproduct();
static mproduct m3 = new mproduct();
public static void main(String[] args) {
// 初始话数据
GetList();
System.out.println("***************");
System.out.println("请选择购买的商品编号");
System.out.println(m1.id + "." + m1.name + " " + m2.id + "."
+ m2.name + " " + m2.id + "." + m2.name + " ");
System.out.println("***************");
System.out.println("请输入商品编号:");
Scanner s = new Scanner(System.in);
int int1 = s.nextInt();
if (int1 == 1) {
System.out.println(m1.name + " " + m1.price);
} else if (int1 == 2) {
System.out.println(m2.name + " " + m2.price);
} else if (int1 == 3) {
System.out.println(m3.name + " " + m3.price);
}
System.out.println("是否继续:");
while (new Scanner(System.in).next().equals("y")) {
System.out.println("请输入商品编号:");
Scanner s2 = new Scanner(System.in);
int int2 = s.nextInt();
if (int1 == 1) {
System.out.println(m1.name + " " + m1.price);
} else if (int2 == 2) {
System.out.println(m2.name + " " + m2.price);
} else if (int2 == 3) {
System.out.println(m3.name + " " + m3.price);
}
System.out.println("是否继续:");
}
}
static class mproduct {
int id;
String name;
double price;
}
static void GetList() {
m1.id = 1;
m1.name = "T血";
m1.price = 245.0;
m2.id = 2;
m2.name = "网球鞋";
m2.price = 570.0;
m3.id = 1;
m3.name = "网球拍";
m3.price = 247.0;
}
}