ArrayList编写吃货联盟
作者:互联网
package txt1;
public class Dish {
private int xuHao;
private String dishNames;
private double prices;
private int praiseNums;
public int getXuHao() {
return xuHao;
}
public void setXuHao(int xuHao) {
this.xuHao = xuHao;
}
public String getDishNames() {
return dishNames;
}
public void setDishNames(String dishNames) {
this.dishNames = dishNames;
}
public double getPrices() {
return prices;
}
public void setPrices(double prices) {
this.prices = prices;
}
public int getPraiseNums() {
return praiseNums;
}
public void setPraiseNums(int praiseNums) {
this.praiseNums = praiseNums;
}
public Dish(int xuHao, String dishNames, double prices, int praiseNums) {
super();
this.xuHao = xuHao;
this.dishNames = dishNames;
this.prices = prices;
this.praiseNums = praiseNums;
}
public Dish() {
super();
}
}
package txt1;
public class Order {
private int xuHao;
private String names;
private String dishMegs;
private int times;
private String addresses;
private int states;
private double sumPrices;
public int getXuHao() {
return xuHao;
}
public void setXuHao(int xuHao) {
this.xuHao = xuHao;
}
public String getNames() {
return names;
}
public void setNames(String names) {
this.names = names;
}
public String getDishMegs() {
return dishMegs;
}
public void setDishMegs(String dishMegs) {
this.dishMegs = dishMegs;
}
public int getTimes() {
return times;
}
public void setTimes(int times) {
this.times = times;
}
public String getAddresses() {
return addresses;
}
public void setAddresses(String addresses) {
this.addresses = addresses;
}
public int getStates() {
return states;
}
public void setStates(int states) {
this.states = states;
}
public double getSumPrices() {
return sumPrices;
}
public void setSumPrices(double sumPrices) {
this.sumPrices = sumPrices;
}
public Order(String names, String dishMegs, int times, String addresses, int states, double sumPrices) {
super();
this.names = names;
this.dishMegs = dishMegs;
this.times = times;
this.addresses = addresses;
this.states = states;
this.sumPrices = sumPrices;
}
public Order() {
super();
}
}
package txt1;
import java.util.ArrayList;
import java.util.Scanner;
public class Chlm {
Scanner input = new Scanner(System.in);
ArrayList<Order> list = new ArrayList<>();
ArrayList<Dish> list2 = new ArrayList<>();
// 初始化数据
public void inita() {
Order order1 = new Order("陈东升", "红烧带鱼 2份", 13, "金瑞家园16号", 1, 76.0);
Order order2 = new Order("黄进平", "鱼香肉丝 2份", 13, "金瑞家园10号", 0, 46.0);
list.add(order1);
list.add(order2);
Dish dish1 = new Dish(1, "红烧带鱼", 38.0, 0);
Dish dish2 = new Dish(2, "鱼香肉丝", 20.0, 0);
Dish dish3 = new Dish(3, "时令鲜蔬", 10.0, 0);
list2.add(dish1);
list2.add(dish2);
list2.add(dish3);
}
public void info1() {
System.out.println("******我要订餐******");
System.out.println("请输入订单人姓名:");
String name = input.next();
System.out.println("序号\t菜名\t单价\t点赞数");
for (Object object2 : list2) {
Dish dish = (Dish) object2;
String price = dish.getPrices() + "元";
String priaiseNum = (dish.getPraiseNums()) > 0 ? dish.getPraiseNums() + "赞" : "0";
System.out.println(dish.getXuHao() + "\t" + dish.getDishNames() + "\t" + price + "\t" + priaiseNum);
}
System.out.println("请输入你要点的菜品编号:");
int chooseDish = input.nextInt();
System.out.println("请输入你需要的份数:");
int number = input.nextInt();
String dishMeg = list2.get(chooseDish - 1).getDishNames() + " " + number + "份";
double sumPrice = list2.get(chooseDish - 1).getPrices() * number;
double deliCharge = (sumPrice >= 50) ? 0 : 5;
System.out.println("请输入送餐时间(送餐时间为10点到20点的整数):");
int time = input.nextInt();
while (time < 10 || time > 20) {
System.out.println("你的输入有误,请输入10-20之间的整数:");
time = input.nextInt();
}
System.out.println("请输入送餐地址:");
String address = input.next();
System.out.println("订餐成功!");
System.out.println("你订的是:" + dishMeg);
System.out.println("送餐时间:" + time + "点");
System.out.println("餐费:" + sumPrice + "元,送餐费" + deliCharge + "元,总计" + (sumPrice + deliCharge) + "元。");
list.add(new Order(name, dishMeg, time, address, 0, sumPrice));
}
public void info2() {
System.out.println("******查看餐袋******");
System.out.println("序号\t订餐人\t餐品信息\t\t送餐日期\t送餐地址\t\t订餐状态");
for (Object object : list) {
Order n = (Order) object;
System.out.println((list.indexOf(n) + 1) + "\t" + n.getNames() + "\t" + n.getDishMegs() + "\t"
+ n.getTimes() + "\t" + n.getAddresses() + "\t" + (n.getStates() == 1 ? "已完成" : "已预定"));
}
}
public void info3() {
System.out.println("******签收订单******");
System.out.println("请选择要签收的订单序号:");
int signOrderId = input.nextInt();
while(list.size()<signOrderId) {
System.out.println("没有你输入的订单序号,请重新输入:");
signOrderId = input.nextInt();
}
if (list.get(signOrderId - 1).getStates() == 0) {
list.get(signOrderId - 1).setStates(1);
System.out.println("订单签收成功!");
} else if (list.get(signOrderId - 1).getStates() == 1) {
System.out.println("你选择的订单已经完成签收,不能再次签收!");
}
}
public void info4() {
System.out.println("******删除订单******");
System.out.println("请输入要删除的订单序号:");
int orderId = input.nextInt();
while (orderId > list.size()) {
System.out.print("请输入正确的订单编号:");
orderId = input.nextInt();
}
if (list.get(orderId - 1).getStates() == 1) {
list.remove(list.get(orderId - 1));
System.out.println("订单删除成功!");
} else {
System.out.println("订单未签收不能删除!");
}
}
public void info5() {
System.out.println("******我要点赞******");
System.out.println("序号" + "\t" + "菜名" + "\t" + "单价" + "\t点赞数");
for (Object object : list2) {
Dish n = (Dish) object;
String price = n.getPrices() + "元";
String priaiseNum = (n.getPraiseNums()) >= 0 ? n.getPraiseNums() + "赞" : "";
System.out.println(n.getXuHao() + "\t" + n.getDishNames() + "\t" + price + "\t" + priaiseNum);
}
System.out.println("请选择你要点赞的菜品序号:");
int priaiseNum = input.nextInt();
list2.get(priaiseNum - 1).setPraiseNums(list2.get(priaiseNum - 1).getPraiseNums() + 1);
System.out.println("点赞成功!");
}
}
package txt1;
import java.util.Scanner;
public class OrderingMgr {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
Chlm chlm = new Chlm();
chlm.inita();
//1.编写框架
do {
System.out.println("======欢迎进入吃货联盟订餐系统主界面======");
System.out.println("****************************");
System.out.println("1.我要订餐");
System.out.println("2.查看餐袋");
System.out.println("3.签收订单");
System.out.println("4.删除订单");
System.out.println("5.我要点赞");
System.out.println("6.退出系统");
System.out.println("****************************");
System.out.println("请选择:");
int choice = input.nextInt();
switch (choice) {
case 1:
chlm.info1();
continue;
case 2:
chlm.info2();
continue;
case 3:
chlm.info3();
continue;
case 4:
chlm.info4();
continue;
case 5:
chlm.info5();
continue;
case 6:
System.out.println("退出系统!");
break;
default:
System.out.println("对不起你选择的业务还未开通,请重新选择!");
continue;
}
break;
} while (true);
System.out.println("程序结束!!!!!!");
}
}
标签:String,int,ArrayList,吃货,System,println,编写,public,out 来源: https://blog.csdn.net/weixin_55076626/article/details/121383962