public void show() {
System.out.println("菜单如下:");
System.out.println("饮品序号\t饮品名称\t饮品单价");
for (int i = 0; i < beverage_Names.length; i++) {
System.out.println((i + 1) + "\t" + beverage_Names[i] + "\t¥"
+ beverage_Prices[i]);
}
}
/\*\*
* 添加饮品
*/
public void add(int index, int num) {
for (int i = 0; i < choice_Bvg_Names.length; i++) {
if (choice_Bvg_Names[i] == null) {
choice_Bvg_Names[i] = beverage_Names[index - 1];
choice_Bvg_Prices[i] = beverage_Prices[index - 1];
this.num[i] = num;
break;
}
}
}
/\*\*
* 打印选择的饮品信息
*/
public void check() {
for (int i = 0; i < choice_Bvg_Names.length; i++) {
if (choice_Bvg_Names[i] != null) {
System.out.print(“\t” + choice_Bvg_Names[i]
+ “\t¥” + choice_Bvg_Prices[i] + "\t " + num[i]);
}
}
}
}
订单类:
package com.oop.demo;
public class OrderForm {
private String name;//顾客昵称
private String tel;//顾客电话
private String addr;//顾客地址
Menu[] menu = new Menu[3];//初始化5个菜单信息
int[] states = new int[3];//订单状态
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getTel() {
return tel;
}
public void setTel(String tel) {
this.tel = tel;
}
public String getAddr() {
return addr;
}
public void setAddr(String addr) {
this.addr = addr;
}
}
顾客类:
package com.oop.demo;
import java.util.Scanner;
/**
* 顾客类
*
*/
public class Customer {
Scanner sca = new Scanner(System.in);
OrderForm order_Form;
/\*\*
* 修改信息
* @param name 昵称
* @param tel 电话号码
* @param addr 地址
*/
public void modify() {
if (order_Form.getName() == null) {
System.out.println(“您还没有注册信息!”);
} else {
System.out.println(“请输入您的旧昵称:”);
String name = sca.next();
System.out.println(“请输入您的旧电话号码:”);
String tel = sca.next();
System.out.println(“请输入您的旧送餐地址:”);
String addr = sca.next();
if (order_Form.getName().equals(name) && order_Form.getTel()
.equals(tel) && order_Form.getAddr().equals(addr)) {
System.out.println(“请输入新的昵称:”);
order_Form.setName(sca.next());
System.out.println(“请输入新的电话号码:”);
order_Form.setTel(sca.next());
System.out.println(“请输入新的送餐地址:”);
order_Form.setAddr(sca.next());
System.out.println(“修改成功~”);
} else {
System.out.println(“输入信息于原有信息不符,修改失败!”);
}
}
}
/\*\*
* 删除订单
*/
public void del() {
get();
if (order_Form.menu[0] != null) {
System.out.println(“请输入要删除的订单序号:”);
int num = sca.nextInt();
if (order_Form.states[num - 1] == 0) {
System.out.println(“您选择的订单未签收,不可删除!”);
} else {
for (int i = num - 1; i < this.order_Form.menu.length - 1; i++) {
this.order_Form.menu[i] = this.order_Form.menu[i + 1];
this.order_Form.states[i + 1] = this.order_Form.states[num - 1];
}
this.order_Form.menu[num - 1] = null;
System.out.println(“删除成功~”);
}
}
}
/\*\*
* 签收订单
*/
public void signFor() {
get();
if (order_Form.menu[0] != null) {
System.out.println(“请输入要签收的订单序号:”);
int num = sca.nextInt();
if (order_Form.states[num - 1] == 0) {
order_Form.states[num - 1] = 1;
System.out.println(“签收成功~”);
} else if (order_Form.states[num - 1] == 1) {
System.out.println(“订单已签收无需重复签收!”);
}
}
}
/\*\*
* 查看订单信息
*/
public void get() {
int count = 0;
if (order_Form.getName() != null) {
System.out.println(“订单人:” + order_Form.getName()
+ “\n送餐电话:” + order_Form.getTel()
+ “\n送餐地址:” + order_Form.getAddr());
}
if (order_Form.menu[0] != null) {
System.out.println(“订单序号\t所点食品\t食品价格\t所点数量\t订单状态”);
}
for (int i = 0; i < order_Form.menu.length; i++) {
if (order_Form.menu[i] != null) {
System.out.print(" " + (i + 1));
order_Form.menu[i].check();
if (order_Form.states[i] == 0) {
System.out.println(“\t 待签收”);
} else {
System.out.println(“\t 已签收”);
}
count ++;
}
}
if (count == 0) {
System.out.println(“您没有任何订单记录!”);
}
}
/\*\*
* 点餐方法
*/
public void order(OrderForm orderForm) {
if (order_Form.getName() == null) {
System.out.println(“请输入您的昵称:”);
order_Form.setName(sca.next());
}
if (order_Form.getTel() == null) {
System.out.println(“请输入您的电话号码:”);
order_Form.setTel(sca.next());
}
if (order_Form.getAddr() == null) {
System.out.println(“请输入您的地址:”);
order_Form.setAddr(sca.next());
}
if (orderForm.menu[orderForm.menu.length - 1] != null) {
System.out.println(“存储空间已满,无法存储!”);
} else {
String choice = “”;
Menu menu = null;
do {
System.out.println(“请选择您想要点的食品类型(1.菜品 2.饮品)”);
choice = sca.next();
if (choice.equals(“1”)) {
menu = new Cuisine();
} else if (choice.equals(“2”)) {
menu = new Beverage();
} else {
System.out.println(“您的输入有误,请您重新输入:”);
}
} while(!(choice.equals(“1”) || choice.equals(“2”)));
menu.show();
System.out.println(“请根据编号选择食品:”);
int food = sca.nextInt();
System.out.println(“请输入要点餐的份数:”);
int num = sca.nextInt();
menu.add(food, num);
for (int i = 0; i < this.order_Form.menu.length; i++) {
if (this.order_Form.menu[i] == null) {
this.order_Form.menu[i] = menu;
System.out.println(“订餐成功~”);
break;
}
}
}
}
}
测试类:
package com.oop.demo;
import java.util.Scanner;
/**
* 测试类
*
*/
public class Test {
public static void main(String[] args) {
Scanner sca = new Scanner(System.in);
Customer customer = new Customer();
customer.order_Form = new OrderForm();
System.err.println("欢迎使用吃货联盟订餐系统");
boolean isExit = false;// true:退出系统
do {
System.out.println("\n\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\n"
+ "1.我要订餐\n"
+ "2.查看餐袋\n"
+ "3.签收订单\n"
+ "4.删除订单\n"
+ "5.修改信息\n"
+ "6.退出系统\n"
+ "\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\n"
+ "请根据序号进行选择:");
switch(sca.next()) {
case "1":
System.out.println("\*\*\*我要订餐\*\*\*");
customer.order(customer.order_Form);
break;
case "2":
System.out.println("\*\*\*查看餐袋\*\*\*");
customer.get();
break;
case "3":
System.out.println("\*\*\*签收订单\*\*\*");
customer.signFor();
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
mg-ZoXh3eLc-1714704901112)]
[外链图片转存中…(img-rhumfm5u-1714704901113)]
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!