1.点菜系统需要一个类(目前没有考虑用户类,水平不够,日后再来补坑)即Dish类,Dish类下有id,name,price。
private int id;
private String name;
private double price;
对Dish进行构造
public Dish(int id, String name, double price) {
this.id = id;
this.name = name;
this.price = price;
}
对Dish进行Getter和Setter
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
重写toString
public String toString() {
return "Dish{" +
"id=" + id +
", name='" + name + '\'' +
", price=" + price +
'}';
}
2.对点餐系统进行编写
ShowOrder 显示界面
public static void ShowOrder(){
System.out.println("---欢迎您来点菜---");
System.out.println("请输入数字进行点菜");
System.out.println("显示全部菜\t\t1");
System.out.println("点菜\t\t\t\t2");
System.out.println("删菜\t\t\t\t3");
System.out.println("结账\t\t\t\t4");
}
InitDish 对主菜单进行初始化
public static void InitDish(){
dishList.add(new Dish(1,"香辣肉丝",29.0));
dishList.add(new Dish(2,"炖王八",90.0));
dishList.add(new Dish(3,"炒蔬菜",15.0));
}
ShowMenu 显示主菜单
public static void ShowMenu(){
for (int i = 0; i < dishList.size(); i++) {
System.out.println(dishList.get(i));
}
}
ShowPersonMenu 显示自己已经点过的菜单
public static void ShowPersonMenu(){
for (int i = 0; i < PersonList.size(); i++) {
System.out.println(PersonList.get(i));
}
}
OrderDish 进行点菜
public static void OrderDish(){
System.out.println("请输入您点菜的序号");
int id=sc.nextInt();
PersonList.add(dishList.get(id-1));
}
DelectDish 删除菜单
public static void DelectDish(){
System.out.println("输入您要删除的序号");
int id=sc.nextInt();
PersonList.remove(id-1);
}
BuyOrder 结账
public static void BuyOrder(){
double money=0.0;
for (int i = 0; i < PersonList.size(); i++) {
money=money+PersonList.get(i).getPrice();
}
System.out.println("您总共消费"+money);
}