Blog-2
Blog-2
期中考试总结
在考试期间,选择题内容较为困难,还是有许多基础性的内容有问题,也导致选择题的大面积错误。
另外就是针对于编程题:
1、
创建一个圆形类(Circle),私有属性为圆的半径,从控制台输入圆的半径,输出圆的面积
输入格式:
输入圆的半径,取值范围为(0,+∞),输入数据非法,则程序输出Wrong Format,注意:只考虑从控制台输入数值的情况
输出格式:
输出圆的面积(保留两位小数,可以使用String.format(“%.2f”,输出数值)控制精度)
算法如下:
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner input = new Scanner(System.in); double r; r = input.nextDouble(); if(r > 0){ cir yuan = new cir(r); System.out.printf("%.2f",yuan.mianji()); } else{ System.out.println("Wrong Format"); } } } class cir { double radius; cir(double r) { radius = r; } double mianji() { return Math.PI * radius * radius; } }
2、
设计一个矩形类,其属性由矩形左上角坐标点(x1,y1)及右下角坐标点(x2,y2)组成,其中,坐标点属性包括该坐标点的X轴及Y轴的坐标值(实型数),求得该矩形的面积。类设计如下图:

输入格式:
分别输入两个坐标点的坐标值x1,y1,x2,y2。
输出格式:
输出该矩形的面积值(保留两位小数)。
import java.util.Scanner; public class Main { public double x1,y1,x2,y2; public static void main(String[] args) { Scanner input = new Scanner(System.in); double x1, x2, y1, y2; x1 = input.nextDouble(); x2 = input.nextDouble(); y1 = input.nextDouble(); y2 = input.nextDouble(); Main jvxing = new Main(x1,y1,x2,y2); double mianji = jvxing.mianji(); System.out.printf("%.2f",mianji); } public Main(double x1,double y1,double x2,double y2){ this.x1 = x1; this.y1 = y1; this.x2 = x2; this.y2 = y2; } public double mianji(){ double chang,kuang; chang = Math.abs(x1-x2); kuang = Math.abs(y1-y2); return chang*kuang; } }
这一题内容也比较简单,但是算法我没有认识到错误,以至于后面心急,没有继续检查,克扣了分数。
3、
将测验1与测验2的类设计进行合并设计,抽象出Shape父类(抽象类),Circle及Rectangle作为子类,类图如下所示:

试编程完成如上类图设计,主方法源码如下(可直接拷贝使用):
public static void main(String[] args) { // TODO Auto-generated method stub Scanner input = new Scanner(System.in); int choice = input.nextInt(); switch(choice) { case 1://Circle double radiums = input.nextDouble(); Shape circle = new Circle(radiums); printArea(circle); break; case 2://Rectangle double x1 = input.nextDouble(); double y1 = input.nextDouble(); double x2 = input.nextDouble(); double y2 = input.nextDouble(); Point leftTopPoint = new Point(x1,y1); Point lowerRightPoint = new Point(x2,y2); Rectangle rectangle = new Rectangle(leftTopPoint,lowerRightPoint); printArea(rectangle); break; } }
其中,printArea(Shape shape)方法为定义在Main类中的静态方法,体现程序设计的多态性。
输入格式:
输入类型选择(1或2,不考虑无效输入)
对应图形的参数(圆或矩形)
输出格式:
图形的面积(保留两位小数)
此题目同样如此,设计好类,将算法规则定好,还是相对简单的。但是本人还是有错误,时间不够了,我也不太会写,以至于后面没有写第四题

本体大部分内容与菜单计价程序-3相同,增加的部分用加粗文字进行了标注。
设计点菜计价程序,根据输入的信息,计算并输出总价格。
输入内容按先后顺序包括两部分:菜单、订单,最后以"end"结束。
菜单由一条或多条菜品记录组成,每条记录一行
每条菜品记录包含:菜名、基础价格 两个信息。
订单分:桌号标识、点菜记录和删除信息、代点菜信息。每一类信息都可包含一条或多条记录,每条记录一行或多行。
桌号标识独占一行,包含两个信息:桌号、时间。
桌号以下的所有记录都是本桌的记录,直至下一个桌号标识。
点菜记录包含:序号、菜名、份额、份数。份额可选项包括:1、2、3,分别代表小、中、大份。
不同份额菜价的计算方法:小份菜的价格=菜品的基础价格。中份菜的价格=菜品的基础价格1.5。小份菜的价格=菜品的基础价格2。如果计算出现小数,按四舍五入的规则进行处理。
删除记录格式:序号 delete
标识删除对应序号的那条点菜记录。
如果序号不对,输出"delete error"
代点菜信息包含:桌号 序号 菜品名称 份额 分数
代点菜是当前桌为另外一桌点菜,信息中的桌号是另一桌的桌号,带点菜的价格计算在当前这一桌。
程序最后按输入的桌号从小到大的顺序依次输出每一桌的总价(注意:由于有代点菜的功能,总价不一定等于当前桌上的菜的价格之和)。
每桌的总价等于那一桌所有菜的价格之和乘以折扣。如存在小数,按四舍五入规则计算,保留整数。
折扣的计算方法(注:以下时间段均按闭区间计算):
周一至周五营业时间与折扣:晚上(17:00-20:30)8折,周一至周五中午(10:30--14:30)6折,其余时间不营业。
周末全价,营业时间:9:30-21:30
如果下单时间不在营业范围内,输出"table " + t.tableNum + " out of opening hours"
参考以下类的模板进行设计(本内容与计价程序之前相同,其他类根据需要自行定义):
菜品类:对应菜谱上一道菜的信息。
Dish {
String name;//菜品名称
int unit_price; //单价
int getPrice(int portion)//计算菜品价格的方法,输入参数是点菜的份额(输入数据只能是1/2/3,代表小/中/大份) }
菜谱类:对应菜谱,包含饭店提供的所有菜的信息。
Menu {
Dish[] dishs ;//菜品数组,保存所有菜品信息
Dish searthDish(String dishName)//根据菜名在菜谱中查找菜品信息,返回Dish对象。
Dish addDish(String dishName,int unit_price)//添加一道菜品信息
}
点菜记录类:保存订单上的一道菜品记录
Record {
int orderNum;//序号
Dish d;//菜品\\
int portion;//份额(1/2/3代表小/中/大份)
int getPrice()//计价,计算本条记录的价格
}
订单类:保存用户点的所有菜的信息。
Order {
Record[] records;//保存订单上每一道的记录
int getTotalPrice()//计算订单的总价
Record addARecord(int orderNum,String dishName,int portion,int num)//添加一条菜品信息到订单中。
delARecordByOrderNum(int orderNum)//根据序号删除一条记录
findRecordByNum(int orderNum)//根据序号查找一条记录
}
本次课题比菜单计价系列-3增加的异常情况:
1、菜谱信息与订单信息混合,应忽略夹在订单信息中的菜谱信息。输出:"invalid dish"
2、桌号所带时间格式合法(格式见输入格式部分说明,其中年必须是4位数字,月、日、时、分、秒可以是1位或2位数),数据非法,比如:2023/15/16 ,输出桌号+" date error"
3、同一桌菜名、份额相同的点菜记录要合并成一条进行计算,否则可能会出现四舍五入的误差。
4、重复删除,重复的删除记录输出"deduplication :"+序号。
5、代点菜时,桌号不存在,输出"Table number :"+被点菜桌号+" does not exist";本次作业不考虑两桌记录时间不匹配的情况。
6、菜谱信息中出现重复的菜品名,以最后一条记录为准。
7、如果有重复的桌号信息,如果两条信息的时间不在同一时间段,(时段的认定:周一到周五的中午或晚上是同一时段,或者周末时间间隔1小时(不含一小时整,精确到秒)以内算统一时段),此时输出结果按不同的记录分别计价。
8、重复的桌号信息如果两条信息的时间在同一时间段,此时输出结果时合并点菜记录统一计价。前提:两个的桌号信息的时间都在有效时间段以内。计算每一桌总价要先合并符合本条件的饭桌的点菜记录,统一计价输出。
9、份额超出范围(1、2、3)输出:序号+" portion out of range "+份额,份额不能超过1位,否则为非法格式,参照第13条输出。
10、份数超出范围,每桌不超过15份,超出范围输出:序号+" num out of range "+份数。份数必须为数值,最高位不能为0,否则按非法格式参照第16条输出。
11、桌号超出范围[1,55]。输出:桌号 +" table num out of range",桌号必须为1位或多位数值,最高位不能为0,否则按非法格式参照第16条输出。
12、菜谱信息中菜价超出范围(区间(0,300)),输出:菜品名+" price out of range "+价格,菜价必须为数值,最高位不能为0,否则按非法格式参照第16条输出。
13、时间输入有效但超出范围[2022.1.1-2023.12.31],输出:"not a valid time period"
14、一条点菜记录中若格式正确,但数据出现问题,如:菜名不存在、份额超出范围、份数超出范围,按记录中从左到右的次序优先级由高到低,输出时只提示优先级最高的那个错误。
15、每桌的点菜记录的序号必须按从小到大的顺序排列(可以不连续,也可以不从1开始),未按序排列序号的输出:"record serial number sequence error"。当前记录忽略。(代点菜信息的序号除外)
16、所有记录其它非法格式输入,统一输出"wrong format"
17、如果记录以“table”开头,对应记录的格式或者数据不符合桌号的要求,那一桌下面定义的所有信息无论正确或错误均忽略,不做处理。如果记录不是以“table”开头,比如“tab le 55 2023/3/2 12/00/00”,该条记录认为是错误记录,后面所有的信息并入上一桌一起计算。
本次作业比菜单计价系列-3增加的功能:
菜单输入时增加特色菜,特色菜的输入格式:菜品名+英文空格+基础价格+"T"
例如:麻婆豆腐 9 T
菜价的计算方法:
周一至周五 7折, 周末全价。
注意:不同的四舍五入顺序可能会造成误差,请按以下步骤累计一桌菜的菜价:
计算每条记录的菜价:将每份菜的单价按份额进行四舍五入运算后,乘以份数计算多份的价格,然后乘以折扣,再进行四舍五入,得到本条记录的最终支付价格。
最后将所有记录的菜价累加得到整桌菜的价格。
输入格式:
桌号标识格式:table + 序号 +英文空格+ 日期(格式:YYYY/MM/DD)+英文空格+ 时间(24小时制格式: HH/MM/SS)
菜品记录格式:
菜名+英文空格+基础价格
如果有多条相同的菜名的记录,菜品的基础价格以最后一条记录为准。
点菜记录格式:序号+英文空格+菜名+英文空格+份额+英文空格+份数注:份额可输入(1/2/3), 1代表小份,2代表中份,3代表大份。
删除记录格式:序号 +英文空格+delete
代点菜信息包含:桌号+英文空格+序号+英文空格+菜品名称+英文空格+份额+英文空格+分数
最后一条记录以“end”结束。
输出格式:
按输入顺序输出每一桌的订单记录处理信息,包括:
1、桌号,格式:table+英文空格+桌号+”:”+英文空格
2、按顺序输出当前这一桌每条订单记录的处理信息,
每条点菜记录输出:序号+英文空格+菜名+英文空格+价格。其中的价格等于对应记录的菜品*份数,序号是之前输入的订单记录的序号。如果订单中包含不能识别的菜名,则输出“** does not exist”,**是不能识别的菜名
如果删除记录的序号不存在,则输出“delete error”
最后按输入顺序一次输出每一桌所有菜品的总价(整数数值)格式:table+英文空格+桌号+“:”+英文空格+当前桌的原始总价+英文空格+当前桌的计算折扣后总价
/* * 菜单输入时增加特色菜,特色菜的输入格式:菜品名+英文空格+基础价格+"T" 例如:麻婆豆腐 9 T 菜价的计算方法: 周一至周五 7折, 周末全价。 注意:不同的四舍五入顺序可能会造成误差,请按以下步骤累计一桌菜的菜价: 计算每条记录的菜价:将每份菜的单价按份额进行四舍五入运算后,乘以份数计算多份的价格,然后乘以折扣,再进行四舍五入,得到本条记录的最终支付价格。 最后将所有记录的菜价累加得到整桌菜的价格。 * */ import java.util.*; import java.time.DateTimeException; import java.time.Duration; import java.time.LocalDateTime; public class Main { public static void main(String[] args){ Menu menu = new Menu(); ArrayList<Table> tables = new ArrayList<Table>(); Scanner input = new Scanner(System.in); int i,portion, shu; String str1; while (true) {// 输入菜单 Dish temp = new Dish(); int isRepeat; str1 = input.nextLine(); if (str1.matches("[\\S]* [1-9][\\d]*")) { String[] token = str1.split(" "); temp.name = token[0]; temp.price = Integer.parseInt(token[1]); if (temp.price > 300) { System.out.println(temp.name + " price out of range " + temp.price); continue; } temp.isT = false; isRepeat = menu.searchDish(temp.name); if (isRepeat != -1) { menu.dishs.remove(isRepeat); } menu.dishs.add(temp); } else if (str1.matches("[\\S]* [\\d]* T")) { String[] token = str1.split(" "); temp.name = token[0]; temp.price = Integer.parseInt(token[1]); if (temp.price > 300) { System.out.println(temp.name + " price out of range " + temp.price); continue; } temp.isT = true; menu.dishs.add(temp); } else if (str1.equals("end")) { break; } else if (str1.matches("tab.*")) { break; } else { System.out.println("wrong format"); } } while (!str1.equals("end")) { Table temp = new Table(); boolean isRepeat = false; int repeatNum = 0; if (str1.matches("table.*")) { if (str1.matches("table [1-9][\\d]* [\\d]*/[\\d][\\d]?/[\\d][\\d]? [\\d][\\d]?/[\\d][\\d]?/[\\d][\\d]?")) { String[] token = str1.split(" "); String[] Date = token[2].split("/"); String[] Time = token[3].split("/"); int[] intDate = new int[3]; int[] intTime = new int[3]; for (i = 0; i < 3; i++) { intDate[i] = Integer.parseInt(Date[i]); intTime[i] = Integer.parseInt(Time[i]); } temp.num = Integer.parseInt(token[1]); if (temp.num > 55) { System.out.println(temp.num + " table num out of range"); str1 = input.nextLine(); continue; } try { temp.time = LocalDateTime.of(intDate[0], intDate[1], intDate[2], intTime[0], intTime[1], intTime[2]); temp.getWeekDay(); } catch (DateTimeException e) { System.out.println(temp.num + " date error"); str1 = input.nextLine(); continue; } for (i = 0; i < tables.size(); i++) {// 最终输出桌号订单信息 if (!tables.get(i).isOpen()) { System.out.println("table " + tables.get(i).num + " out of opening hours"); } } if (!(temp.time.isAfter(LocalDateTime.of(2022, 1, 1, 0, 0, 0)) && temp.time.isBefore(LocalDateTime.of(2024, 1, 1, 0, 0, 0)))) { System.out.println("not a valid time period"); str1 = input.nextLine(); continue; } for (i = 0; i < tables.size(); i++) {// 最终输出桌号订单信息 if (!tables.get(i).isOpen()) { System.out.println("table " + tables.get(i).num + " out of opening hours"); } } if (temp.isOpen()) { // 判断桌号是否重复 for (i = 0; i < tables.size(); i++) {// 有重复的桌号 if (temp.num == tables.get(i).num && tables.get(i).isOpen()) { // 同一天 Duration duration = Duration.between(temp.time, tables.get(i).time); if (duration.toDays() == 0) {// 在周一到周五 if (temp.weekday > 0 && temp.weekday < 6) {// 在同一时间段 if (temp.time.getHour() < 15 && tables.get(i).time.getHour() < 15) { temp = tables.get(i); isRepeat = true; repeatNum = i; break; } } // 在周末 else {// 时间相差小于一小时 if (duration.toHours() < 3600) { temp = tables.get(i); repeatNum = i; isRepeat = true; break; } } } } } } if(!isRepeat) { System.out.println("table " + temp.num + ": "); } for (i = 0; i < tables.size(); i++) {// 最终输出桌号订单信息 if (!tables.get(i).isOpen()) { System.out.println("table " + tables.get(i).num + " out of opening hours"); } } } else { System.out.println("wrong format"); str1 = input.nextLine(); continue; } while (true) { // 本桌开始点菜 str1 = input.nextLine(); if (str1.matches("[1-9][\\d]* [\\S]* [\\d] [1-9][\\d]*")) { String[] token = str1.split(" "); portion = Integer.parseInt(token[2]); shu = Integer.parseInt(token[3]); if (!temp.order.notes.isEmpty()) { if (Integer.parseInt(token[0]) <= temp.order.notes.get(temp.order.notes.size() - 1).orderNum) { System.out.println("record serial number sequence error"); continue; } } if (menu.searchDish(token[1]) == -1) { System.out.println(token[1] + " does not exist"); continue; } if (portion > 3 || portion < 1) { System.out.println(Integer.parseInt(token[0]) + " portion out of range " + portion); continue; } if (shu > 15) { System.out.println(Integer.parseInt(token[0]) + " num out of range " + shu); continue; } temp.oder(menu, token[0], token[1], portion, shu); } // 判断是否为删除订单 else if (str1.matches("[1-9][\\d]* delete")) { String[] token = str1.split(" "); temp.order.delARecordByOrderNum(Integer.parseInt(token[0])); } // 判断是否为夹杂菜单 else if (str1.matches("[\\S]* [\\d]*")) { System.out.println("invalid dish"); } else if (str1.matches("[\\S]* [\\d]* T")) { System.out.println("invalid dish"); } // 判断是否为代点 else if (str1.matches("[\\d]* [\\d]* [\\S]* [\\d] [1-9][\\d]*")) { String[] token = str1.split(" "); // 判断代点桌号是否存在 boolean exist = false; for (int j = 0; j < tables.size(); j++) {//说明for的增强,但是不太会 if (tables.get(j).num == Integer.parseInt(token[0])) { exist = true; break; } } if (exist) { System.out.print(Integer.parseInt(token[1]) + " table " + temp.num + " pay for table " + Integer.parseInt(token[0]) + " "); Record treat = new Record(); treat.d = menu.dishs.get(menu.searchDish(token[2])); portion = Integer.parseInt(token[3]); shu = Integer.parseInt(token[4]); treat.portion = portion; treat.shu = shu; System.out.print(treat.totalprice() + "\n"); temp.sum += treat.totalprice(); } // 若不存在则输出内容 else { System.out.println("Table number :" + Integer.parseInt(token[0]) + " does not exist"); } } else if (str1.equals("end")) { break; } else if(str1.matches("ta.*")){ break; } else { System.out.println("wrong format"); } } } else if (str1.matches("t.*")) { isRepeat = true; temp = tables.get(tables.size()); while (true) { str1 = input.nextLine(); if (str1.matches("[1-9][\\d]* [\\S]* [\\d] [1-9][\\d]*")) { String[] token = str1.split(" "); portion = Integer.parseInt(token[2]); shu = Integer.parseInt(token[3]); if (!temp.order.notes.isEmpty()) {// 判断订单号是否由小到大排列 if (Integer.parseInt(token[0]) <= temp.order.notes.get(temp.order.notes.size() - 1).orderNum) { System.out.println("record serial number sequence error"); continue; } } if (menu.searchDish(token[1]) == -1) { System.out.println(token[1] + " does not exist"); continue; } if (portion > 3 || portion < 1) { System.out.println(Integer.parseInt(token[0]) + " portion out of range " + portion); continue; } if (shu > 15) { System.out.println(Integer.parseInt(token[0]) + " num out of range " + shu); continue; } temp.oder(menu, token[0], token[1], portion, shu); } // 判断是否为删除订单 else if (str1.matches("[1-9][\\d]* delete")) { String[] token = str1.split(" "); temp.order.delARecordByOrderNum(Integer.parseInt(token[0])); } // 判断是否为夹杂菜单 else if (str1.matches("[\\S]* [\\d]*")) { System.out.println("invalid dish"); } else if (str1.matches("[\\S]* [\\d]* T")) { System.out.println("invalid dish"); } // 判断是否为代点 else if (str1.matches("[\\d]* [\\d]* [\\S]* [\\d] [1-9][\\d]*")) { String[] token = str1.split(" "); boolean cun = false;// 判断代点桌号是否存在 for (int j = 0; j < tables.size(); j++) {//说明for的增强,但是不太会 if (tables.get(j).num == Integer.parseInt(token[0])) { cun = true; break; } } for (i = 0; i < tables.size(); i++) {// 最终输出桌号订单信息 if (!tables.get(i).isOpen()) { System.out.println("table " + tables.get(i).num + " out of opening hours"); } } if (cun) { System.out.print(Integer.parseInt(token[1]) + " table " + temp.num + " pay for table " + Integer.parseInt(token[0]) + " "); Record treat = new Record(); treat.d = menu.dishs.get(menu.searchDish(token[2])); portion = Integer.parseInt(token[3]); shu = Integer.parseInt(token[4]); treat.portion = portion; treat.shu = shu; System.out.print(treat.totalprice() + "\n"); temp.sum += treat.totalprice(); } else {// 若不存在则输出内容 System.out.println("Table number :" + Integer.parseInt(token[0]) + " does not exist"); } } else if (str1.equals("end")) { break; } else { System.out.println("wrong format"); } for (i = 0; i < tables.size(); i++) {// 最终输出桌号订单信息 if (!tables.get(i).isOpen()) { System.out.println("table " + tables.get(i).num + " out of opening hours"); } } } if (!tables.isEmpty()) { tables.get(tables.size() - 1).order.notes.addAll(temp.order.notes); } } else { str1 = input.nextLine(); continue; } if (isRepeat) {// 本桌点菜结束,进入下一桌 tables.remove(repeatNum); } temp.getSum(); tables.add(temp); } for (i = 0; i < tables.size(); i++) {// 最终输出桌号订单信息 if (!tables.get(i).isOpen()) { System.out.println("table " + tables.get(i).num + " out of opening hours"); } else System.out.println("table " + tables.get(i).num + ": " + tables.get(i).origSum + " " + tables.get(i).sum); } } static class Menu { ArrayList<Dish> dishs = new ArrayList<Dish>(); int searchDish(String dishName) { for (int i = 0; i < dishs.size(); i++) { if (dishName.equals(dishs.get(i).name)) { return i; } } return -1; } } static class Dish { String name; int price; boolean isT = false; } static class Table { Order order = new Order(); LocalDateTime time; int num,weekday; long sum = 0,origSum = 0; void oder(Menu menu, String str1, String str2, int portion, int quota) {{ order.notes.add(order.addARecord(Integer.parseInt(str1), str2, portion, quota, menu)); } } void getWeekDay() { weekday = time.getDayOfWeek().getValue(); } void getSum() { for (int i = 0; i < order.notes.size(); i++) { if (!order.notes.get(i).isDeleted) { origSum += order.notes.get(i).totalprice(); if (order.notes.get(i).d.isT) { if (weekday > 0 && weekday < 6) { sum += Math.round(order.notes.get(i).totalprice() * 0.7); } else { sum += order.notes.get(i).totalprice(); } } else { if (weekday > 0 && weekday < 6) { if (time.getHour() >= 17 && time.getHour() < 20) sum += Math.round(order.notes.get(i).totalprice() * 0.8); if (time.getHour() == 20) { if (time.getMinute() <= 30) sum += Math.round(order.notes.get(i).totalprice() * 0.8); } if (time.getHour() >= 10 && time.getHour() < 14) sum += Math.round(order.notes.get(i).totalprice() * 0.6); if (time.getHour() == 14) { if (time.getMinute() <= 30) sum += Math.round(order.notes.get(i).totalprice() * 0.6); } } else sum+=order.notes.get(i).totalprice(); } } } } boolean isOpen() { if (weekday > 0 && weekday < 6) { if (time.getHour() >= 17 && time.getHour() < 20) return true; if (time.getHour() == 20) { if (time.getMinute() <= 30) return true; } if (time.getHour() > 10 && time.getHour() < 14) return true; if (time.getHour() == 10) { if (time.getMinute() >= 30) return true; } if (time.getHour() == 14) { if (time.getMinute() <= 30) return true; } } else { if (time.getHour() > 9 && time.getHour() < 21) return true; if (time.getHour() == 9) { if (time.getMinute() >= 30) return true; } if (time.getHour() == 21) { if (time.getMinute() <= 30) return true; } } return false; } } static class Record { int orderNum,portion,shu; Dish d; boolean isDeleted = false; int totalprice() { if (portion == 2) return (int) Math.round(1.5 * d.price) * shu; else if (portion == 3) return 2 * d.price * shu; else return d.price * shu; } } static class Order { ArrayList<Record> notes = new ArrayList<Record>(); Record addARecord(int orderNum, String dishName, int portion, int shu, Menu menu) { Record newRecord = new Record(); newRecord.orderNum = orderNum; newRecord.d = menu.dishs.get(menu.searchDish(dishName)); newRecord.portion = portion; newRecord.shu = shu; System.out.println(newRecord.orderNum + " " + newRecord.d.name + " " + newRecord.totalprice()); return newRecord; } boolean delARecordByOrderNum(int orderNum) { int i , flag = 0; for (i = 0; i < notes.size(); i++) { if (notes.get(i).orderNum == orderNum) { if (!notes.get(i).isDeleted) { notes.get(i).isDeleted = true; } else { System.out.println("deduplication " + orderNum); } flag++; } } if (flag == 0) { System.out.println("delete error;"); return false; } return true; } } static class Time { String time1,time2; int year,month,day,hour,minute,weekday; public void getweekOfDay() { this.weekday=LocalDateTime.of(this.year, this.month, this.day, this.hour, this.minute).getDayOfWeek().getValue(); } public void getYear() { String Date1[] = time1.split("\\/"); year = Integer.parseInt(Date1[0]); month = Integer.parseInt(Date1[1]); day = Integer.parseInt(Date1[2]); } public void getDay() { String Date2[] = time2.split("\\/"); hour = Integer.parseInt(Date2[0]); minute = Integer.parseInt(Date2[1]); } } }
这个题目相对的在菜单三的基础上增加新内容,但是我的代码能力有限,也没有能力到满分,所以只能有个这水平。
但是这个实验可以充分认识到自己的不足,自己代码能力的不足,也是认识到自己基础水平的一个题目。
在针对于自己的几个问题,也一直没有找到合适的解决方法:
1、错误的table记录,内容并入上一个table计算。2、错误的table记录 3、重复的桌号,其中之一不在营业时间。等等。
类图如下:

本题在菜单计价程序-3的基础上增加了部分内容,增加的内容用加粗字体标识。
注意不是菜单计价程序-4,本题和菜单计价程序-4同属菜单计价程序-3的两个不同迭代分支
设计点菜计价程序,根据输入的信息,计算并输出总价格。
输入内容按先后顺序包括两部分:菜单、订单,最后以"end"结束。
菜单由一条或多条菜品记录组成,每条记录一行
每条菜品记录包含:菜名、基础价格 三个信息。
订单分:桌号标识、点菜记录和删除信息、代点菜信息。每一类信息都可包含一条或多条记录,每条记录一行或多行。
桌号标识独占一行,包含两个信息:桌号、时间。
桌号以下的所有记录都是本桌的记录,直至下一个桌号标识。
点菜记录包含:序号、菜名、份额、份数。份额可选项包括:1、2、3,分别代表小、中、大份。
不同份额菜价的计算方法:小份菜的价格=菜品的基础价格。中份菜的价格=菜品的基础价格1.5。小份菜的价格=菜品的基础价格2。如果计算出现小数,按四舍五入的规则进行处理。
删除记录格式:序号 delete
标识删除对应序号的那条点菜记录。
如果序号不对,输出"delete error"
代点菜信息包含:桌号 序号 菜品名称 口味度 份额 份数
代点菜是当前桌为另外一桌点菜,信息中的桌号是另一桌的桌号,带点菜的价格计算在当前这一桌。
程序最后按输入的先后顺序依次输出每一桌的总价(注意:由于有代点菜的功能,总价不一定等于当前桌上的菜的价格之和)。
每桌的总价等于那一桌所有菜的价格之和乘以折扣。如存在小数,按四舍五入规则计算,保留整数。
折扣的计算方法(注:以下时间段均按闭区间计算):
周一至周五营业时间与折扣:晚上(17:00-20:30)8折,周一至周五中午(10:30--14:30)6折,其余时间不营业。
周末全价,营业时间:9:30-21:30
如果下单时间不在营业范围内,输出"table " + t.tableNum + " out of opening hours"
参考以下类的模板进行设计:菜品类:对应菜谱上一道菜的信息。
Dish {
String name;//菜品名称
int unit_price; //单价
int getPrice(int portion)//计算菜品价格的方法,输入参数是点菜的份额(输入数据只能是1/2/3,代表小/中/大份) }
菜谱类:对应菜谱,包含饭店提供的所有菜的信息。
Menu {
Dish[] dishs ;//菜品数组,保存所有菜品信息
Dish searthDish(String dishName)//根据菜名在菜谱中查找菜品信息,返回Dish对象。
Dish addDish(String dishName,int unit_price)//添加一道菜品信息
}
点菜记录类:保存订单上的一道菜品记录
Record {
int orderNum;//序号\\
Dish d;//菜品\\
int portion;//份额(1/2/3代表小/中/大份)\\
int getPrice()//计价,计算本条记录的价格\\
}
订单类:保存用户点的所有菜的信息。
Order {
Record[] records;//保存订单上每一道的记录
int getTotalPrice()//计算订单的总价
Record addARecord(int orderNum,String dishName,int portion,int num)//添加一条菜品信息到订单中。
delARecordByOrderNum(int orderNum)//根据序号删除一条记录
findRecordByNum(int orderNum)//根据序号查找一条记录
}
### 输入格式:
桌号标识格式:table + 序号 +英文空格+ 日期(格式:YYYY/MM/DD)+英文空格+ 时间(24小时制格式: HH/MM/SS)
菜品记录格式:
菜名+英文空格+基础价格
如果有多条相同的菜名的记录,菜品的基础价格以最后一条记录为准。
点菜记录格式:序号+英文空格+菜名+英文空格+份额+英文空格+份数注:份额可输入(1/2/3), 1代表小份,2代表中份,3代表大份。
删除记录格式:序号 +英文空格+delete
代点菜信息包含:桌号+英文空格+序号+英文空格+菜品名称+英文空格+份额+英文空格+分数
最后一条记录以“end”结束。
### 输出格式:
按输入顺序输出每一桌的订单记录处理信息,包括:
1、桌号,格式:table+英文空格+桌号+”:”
2、按顺序输出当前这一桌每条订单记录的处理信息,
每条点菜记录输出:序号+英文空格+菜名+英文空格+价格。其中的价格等于对应记录的菜品\*份数,序号是之前输入的订单记录的序号。如果订单中包含不能识别的菜名,则输出“\*\* does not exist”,\*\*是不能识别的菜名
如果删除记录的序号不存在,则输出“delete error”
最后按输入顺序一次输出每一桌所有菜品的总价(整数数值)格式:table+英文空格+桌号+“:”+英文空格+当前桌的总价
以上为菜单计价系列-3的题目要求,加粗的部分是有调整的内容。本次课题相比菜单计价系列-3新增要求如下:
1、菜单输入时增加特色菜,特色菜的输入格式:菜品名+英文空格+口味类型+英文空格+基础价格+"T"
例如:麻婆豆腐 川菜 9 T
菜价的计算方法:
周一至周五 7折, 周末全价。
特色菜的口味类型:川菜、晋菜、浙菜
川菜增加辣度值:辣度0-5级;对应辣度水平为:不辣、微辣、稍辣、辣、很辣、爆辣;
晋菜增加酸度值,酸度0-4级;对应酸度水平为:不酸、微酸、稍酸、酸、很酸;
浙菜增加甜度值,甜度0-3级;对应酸度水平为:不甜、微甜、稍甜、甜;
例如:麻婆豆腐 川菜 9 T
输入订单记录时如果是特色菜,添加口味度(辣/酸/甜度)值,格式为:序号+英文空格+菜名+英文空格+口味度值+英文空格+份额+英文空格+份数
例如:1 麻婆豆腐 4 1 9
单条信息在处理时,如果口味度超过正常范围,输出"spicy/acidity/sweetness num out of range : "+口味度值,spicy/acidity/sweetness(辣度/酸度/甜度)根据菜品类型择一输出,例如:
acidity num out of range : 5
输出一桌的信息时,按辣、酸、甜度的顺序依次输出本桌菜各种口味的口味度水平,如果没有某个类型的菜,对应的口味(辣/酸/甜)度不输出,只输出已点的菜的口味度。口味度水平由口味度平均值确定,口味度平均值只综合对应口味菜系的菜计算,不做所有菜的平均。比如,某桌菜点了3份川菜,辣度分别是1、3、5;还有4份晋菜,酸度分别是,1、1、2、2,辣度平均值为3、酸度平均值四舍五入为2,甜度没有,不输出。
一桌信息的输出格式:table+英文空格+桌号+:+英文空格+当前桌的原始总价+英文空格+当前桌的计算折扣后总价+英文空格+"川菜"+数量+辣度+英文空格+"晋菜"+数量+酸度+英文空格+"浙菜"+数量+甜度。
如果整桌菜没有特色菜,则只输出table的基本信息,格式如下,注意最后加一个英文空格:
table+英文空格+桌号+:+英文空格+当前桌的原始总价+英文空格+当前桌的计算折扣后总价+英文空格
例如:table 1: 60 36 川菜 2 爆辣 浙菜 1 微甜
计算口味度时要累计本桌各类菜系所有记录的口味度总和(每条记录的口味度乘以菜的份数),再除以对应菜系菜的总份数,最后四舍五入。
注:本题要考虑代点菜的情况,当前桌点的菜要加上被其他桌代点的菜综合计算口味度平均值。
2、考虑客户订多桌菜的情况,输入时桌号时,增加用户的信息:
格式:table+英文空格+桌号+英文空格+":"+英文空格+客户姓名+英文空格+手机号+日期(格式:YYYY/MM/DD)+英文空格+ 时间(24小时制格式: HH/MM/SS)
例如:table 1 : tom 13670008181 2023/5/1 21/30/00
约束条件:客户姓名不超过10个字符,手机号11位,前三位必须是180、181、189、133、135、136其中之一。
输出结果时,先按要求输出每一桌的信息,最后按字母顺序依次输出每位客户需要支付的金额。不考虑各桌时间段的问题,同一个客户的所有table金额都要累加。
输出用户支付金额格式:
用户姓名+英文空格+手机号+英文空格+支付金额
注意:不同的四舍五入顺序可能会造成误差,请按以下步骤累计一桌菜的菜价:
计算每条记录的菜价:将每份菜的单价按份额进行四舍五入运算后,乘以份数计算多份的价格,然后乘以折扣,再进行四舍五入,得到本条记录的最终支付价格。
将所有记录的菜价累加得到整桌菜的价格。
输入格式:
桌号标识格式:table + 序号 +英文空格+ 日期(格式:YYYY/MM/DD)+英文空格+ 时间(24小时制格式: HH/MM/SS)
菜品记录格式:
菜名+口味类型+英文空格+基础价格
如果有多条相同的菜名的记录,菜品的基础价格以最后一条记录为准。
点菜记录格式:序号+英文空格+菜名+英文空格+辣/酸/甜度值+英文空格+份额+英文空格+份数 注:份额可输入(1/2/3), 1代表小份,2代表中份,3代表大份。辣/酸/甜度取值范围见题目中说明。
删除记录格式:序号 +英文空格+delete
代点菜信息包含:桌号+英文空格+序号+英文空格+菜品名称**+英文空格+辣/酸/甜度值+**英文空格+份额+英文空格+分数
最后一条记录以“end”结束。
输出格式:
按输入顺序输出每一桌的订单记录处理信息,包括:
1、桌号,格式:table+英文空格+桌号+“:”+英文空格
2、按顺序输出当前这一桌每条订单记录的处理信息,
每条点菜记录输出:序号+英文空格+菜名+英文空格+价格。其中的价格等于对应记录的菜品\*份数,序号是之前输入的订单记录的序号。如果订单中包含不能识别的菜名,则输出“\*\* does not exist”,\*\*是不能识别的菜名
如果删除记录的序号不存在,则输出“delete error”
之后按输入顺序一次输出每一桌所有菜品的价格(整数数值),
格式:table+英文空格+桌号+“:”+英文空格+当前桌的计算折扣后总价+英文空格+辣度平均值+英文空格+酸度平均值+英文空格+甜度平均值+英文空格
最后按拼音顺序输出每位客户(不考虑客户同名或拼音相同的情况)的支付金额,格式: 用户姓名+英文空格+手机号+英文空格+支付总金额,按输入顺序排列。
/* * 1周一至周五 7折, 周末全价。 特色菜的口味类型:川菜、晋菜、浙菜 川菜增加辣度值:辣度0-5级;对应辣度水平为:不辣、微辣、稍辣、辣、很辣、爆辣; 晋菜增加酸度值,酸度0-4级;对应酸度水平为:不酸、微酸、稍酸、酸、很酸; 浙菜增加甜度值,甜度0-3级;对应酸度水平为:不甜、微甜、稍甜、甜; * 2考虑客户订多桌菜的情况,输入时桌号时,增加用户的信息: 格式:table+英文空格+桌号+英文空格+":"+英文空格+客户姓名+英文空格+手机号+日期(格式:YYYY/MM/DD)+英文空格+ 时间(24小时制格式: HH/MM/SS) * 3最后按拼音顺序输出每位客户(不考虑客户同名或拼音相同的情况)的支付金额,格式: 用户姓名+英文空格+手机号+英文空格+支付总金额,按输入顺序排列。 */ import java.util.*; import java.time.LocalDateTime; public class Main { public static void main(String[] args) { Table[] table=new Table[10]; Menu menu = new Menu(); Scanner input = new Scanner(System.in); String next = input.nextLine(); int i=0,num=0,flag=0,temp=0; while (!next.equals("end")) { String[] lineArray = next.split(" "); if(next.isEmpty()) { next = input.nextLine(); System.out.println("wrong format"); continue; } else if(lineArray.length == 7&&lineArray[0].equals("table")&&canParse(lineArray[1]) &&isopen(lineArray[5],lineArray[6])&&judge(lineArray[4])){ i++; flag=1; table[i]=new Table(); table[i].order=new Order(menu); table[i].num=Integer.parseInt(lineArray[1]); table[i].name=lineArray[3]; table[i].phone=lineArray[4]; table[i].t=new Time(); table[i].t.time1=lineArray[5]; table[i].t.time2=lineArray[6]; System.out.println("table "+Integer.parseInt(lineArray[1])+": "); temp=0; } else if (lineArray.length == 7&&lineArray[0].equals("table")&&(!judge(lineArray[4])||!canParse(lineArray[1]))) { System.out.println("wrong format"); temp=1; } else if(lineArray.length == 7&&lineArray[0].equals("table")&&(!canParse(lineArray[1])||Integer.parseInt(lineArray[1])>55||Integer.parseInt(lineArray[1])<=0||!isopen(lineArray[5],lineArray[6]))) { temp=1; } else if(lineArray.length >7&&lineArray[0].equals("table")) { System.out.println("wrong format"); temp=1; } else if ((lineArray.length == 4||lineArray.length == 5)&&!lineArray[0].equals("table")&&temp==0&&canParse(lineArray[0])) { int ordernum = Integer.parseInt(lineArray[0]); String dishName = lineArray[1]; int parse =0; int parseInt1 ,parseInt2; if(lineArray.length == 4){ parseInt1 = Integer.parseInt(lineArray[2]); parseInt2 = Integer.parseInt(lineArray[3]); } else { parse = Integer.parseInt(lineArray[2]); parseInt1 = Integer.parseInt(lineArray[3]); parseInt2 = Integer.parseInt(lineArray[4]); } if(table[i].order.addARecord(ordernum, dishName, parse, parseInt1,parseInt2,i,false,false)!=null) num=ordernum; /**/ else{ num=0; table[i-1].order.addARecord(ordernum, dishName, parse, parseInt1,parseInt2,i-1,false,false); table[i].sametime=1; } } else if ("delete".equals(lineArray[1])&&temp==0) { table[i].order.delARecordByOrderNum(Integer.parseInt(lineArray[0]),i); } else if((lineArray.length ==5||lineArray.length ==6)&&canParse(lineArray[0])&&canParse(lineArray[1])){ int a=0; if(i>1){ for(int j=1;j<=i;j++){ if(table[j].num==Integer.parseInt(lineArray[0])){ Dish dish = menu.searthDish(lineArray[2]); int price; if(lineArray.length ==5) price= dish.getPrice(Integer.parseInt(lineArray[3]))*Integer.parseInt(lineArray[4]); else price= dish.getPrice(Integer.parseInt(lineArray[4]))*Integer.parseInt(lineArray[5]); System.out.println(lineArray[1]+" table "+table[i].num+" pay for table "+table[j].num+" "+price); table[Integer.parseInt(lineArray[0])].order.addARecord(Integer.parseInt(lineArray[1]),lineArray[2],Integer.parseInt(lineArray[3]),Integer.parseInt(lineArray[4]),Integer.parseInt(lineArray[5]),Integer.parseInt(lineArray[0]),true,false); table[i].order.addARecord(Integer.parseInt(lineArray[1]),lineArray[2],Integer.parseInt(lineArray[3]),Integer.parseInt(lineArray[4]),Integer.parseInt(lineArray[5]),i,false,true); a=1; } } if(a==0) System.out.println("Table number :"+Integer.parseInt(lineArray[0])+" does not exist"); } else System.out.println("Table number :"+Integer.parseInt(lineArray[0])+" does not exist"); } else { if((lineArray.length == 3)&&!canParse(lineArray[0])&&!lineArray[1].equals("delete")) { System.out.println("wrong format"); } if(lineArray.length == 4&&canParse(lineArray[2])&&lineArray[3].equals("T")) menu.addDish(lineArray[0], lineArray[1],Integer.parseInt(lineArray[2]),true); if(lineArray.length == 2&&canParse(lineArray[1])&&flag==0) menu.addDish(lineArray[0],null,Integer.parseInt(lineArray[1]),false); } if(lineArray.length == 7&&lineArray[0].equals("table")&&canParse(lineArray[1])&&!isopen(lineArray[5], lineArray[6])) { if (!isopen(lineArray[5], lineArray[6])) System.out.println("table " + Integer.parseInt(lineArray[1]) + " out of opening hours"); } next = input.nextLine(); } input.close(); for(int j=1;j<=i;j++){ table[j].price(j); } for(int j=1;j<=i;j++){ for(int k=j+1;k<=i;k++) { if (table[j].name!=null&&table[k].name!=null&&table[j].name.compareTo(table[k].name) == 0){ table[k].name=null; table[j].Tableprice+=table[k].Tableprice; } if(table[j].name!=null&&table[k].name!=null&&table[j].name.compareTo(table[k].name)>0){ table[9]=table[j]; table[j]=table[k]; table[k]=table[9]; } } } for(int j=1;j<=i;j++){ if(table[j].name!=null) System.out.println(table[j].name+" "+table[j].phone+" "+table[j].Tableprice); } } public static boolean canParse(String str) { if(str==null) { return false; } return str.matches("\\d+"); } public static boolean judge(String str){ if(str.length()!=11) return false; String[] s=str.split(""); if(s[0].equals("1")&&s[1].equals("8")&&s[2].equals("0"))return true; if(s[0].equals("1")&&s[1].equals("8")&&s[2].equals("1"))return true; if(s[0].equals("1")&&s[1].equals("8")&&s[2].equals("9"))return true; if(s[0].equals("1")&&s[1].equals("3")&&s[2].equals("3"))return true; if(s[0].equals("1")&&s[1].equals("3")&&s[2].equals("5"))return true; else if(s[0].equals("1")&&s[1].equals("3")&&s[2].equals("6"))return true; return false; } public static boolean isopen(String str1 ,String str2){ Time time = new Time(); time.time1=str1; time.time2=str2; time.getDay(); time.getYear(); time.getweekDay(); if (time.weekday<=5&&time.weekday>=1&&((time.hour>=17&&time.hour<20)||(time.hour==20&&time.minute<=30)||(time.hour==10&&time.minute>=30)||(time.hour>=11&&time.hour<14)||(time.hour==14&&time.minute<=30))) { return true; } else if((time.weekday==6|| time.weekday==7)&&((time.hour==9&&time.minute>=30)|| (time.hour>9&&time.hour<21)||(time.hour==21&&time . minute<=30))) { return true; } else { return false; } } } class Menu { private List<Dish> dishs = new ArrayList<>();//菜品数组保存菜品信息 Dish searthDish(String dishName) { for (Dish dish : dishs) { if (dish.getDishname().equals(dishName)) { return dish; } } return null; } /**/ Dish addDish(String dishName,String kindOfDish, int unit_price,boolean t) { for (Dish dish : dishs) { if (dish.getDishname().equals(dishName)) { dish.setUnit_price(unit_price); dish.setKindOfDish(kindOfDish); dish.setT(t); return dish; } } Dish dish = new Dish(dishName,kindOfDish, unit_price,t); dishs.add(dish); return dish; } } class Order { private Menu menu; public boolean iscc,isjc,iszc; public int ccNum=0,jcNum=0,zcNum=0; public int ccDegree=0,jcDegree=0,zcDegree=0; static Record[][] records=new Record[10][30]; public Order(Menu menu) { this.menu = menu; } int TotalPrice1(int i) {//计算订单的总价 int sum = 0; for (int j=1;j<=records[i].length;j++) { if(records[i][j]==null)break; int price = records[i][j].getPrice(); if (!records[i][j].isDelete()&&!records[i][j].getD().T&&!records[i][j].isreplace) { sum = sum + price; } } return sum; } int TotalPrice2(int i) { int sum = 0; for (int j=1;j<=records[i].length;j++) { if(records[i][j]==null)break; int price = records[i][j].getPrice(); if (!records[i][j].isDelete()&&records[i][j].getD().T&&!records[i][j].isreplace) { sum = sum + price; } } return sum; } int getTotalPrice3(int i,double a){ int sum = 0; for (int j=1;j<=records[i].length;j++){ if(records[i][j]==null)break; int price = (int)Math.round(records[i][j].getPrice()*a); if (!records[i][j].isDelete()&&!records[i][j].getD().T&&!records[i][j].isreplace) { sum += price; } } return sum; } int getTotalPrice4(int i,double a ){ int sum = 0; for (int j=1;j<=records[i].length;j++) { if(records[i][j]==null)break; int price = (int)Math.round(records[i][j].getPrice()*a); if (!records[i][j].isDelete()&&records[i][j].getD().T&&!records[i][j].isreplace) { sum +=price; } } return sum; } Record addARecord(int orderNum, String dishName, int degree,int portion, int num,int i,boolean isreplace,boolean bereplace) { Dish dish = menu.searthDish(dishName); if (dish == null) { System.out.println(dishName + " does not exist"); return null; } if(portion>3) { System.out.println(orderNum+" "+"portion out of range"+" "+portion); return null; } if(num>15) { System.out.println(orderNum+" "+"num out of range"+" "+num); return null; } if(dish.kindOfDish!=null&&dish.kindOfDish.equals("川菜")&&(degree>5||degree<0)) { System.out.println("spicy num out of range :" + degree); return null; } if(dish.kindOfDish!=null&&dish.kindOfDish.equals("晋菜")&&(degree>4||degree<0)) { System.out.println("acidity num out of range :" + degree); return null; } if(dish.kindOfDish!=null&&dish.kindOfDish.equals("浙菜")&&(degree>3||degree<0)) { System.out.println("sweetness num out of range :" + degree); return null; } if(dish.kindOfDish!=null&&dish.kindOfDish.equals("川菜")&&!bereplace) { this.iscc=true; this.ccDegree+=degree*num; this.ccNum+=num; } if(dish.kindOfDish!=null&&dish.kindOfDish.equals("晋菜")&&!bereplace) { this.isjc=true; this.jcDegree+=degree*num; this.jcNum+=num; } if(dish.kindOfDish!=null&&dish.kindOfDish.equals("浙菜")&&!bereplace) { this.iszc=true; this.zcDegree+=degree*num; this.zcNum+=num; } int t = 0; for (int j=1;j<=records[i].length;j++) { if(records[i][j]==null) { t=j; break; } } records[i][t]= new Record(orderNum, dish,degree, portion, num); int price = records[i][t].getPrice(); records[i][t].isreplace=isreplace; if(!records[i][t].isreplace&&!bereplace) System.out.println(records[i][t].getNumOrder() + " " + records[i][t].getD().getDishname() + " " + price); return records[i][t]; } public boolean delARecordByOrderNum(int orderNum,int i) { int t; for (int j=1;j<=20;j++) { if (records[i][j]!=null&&!records[i][j].isNotFound() &&records[i][j].getNumOrder() == orderNum) { records[i][j].setDelete(true); records[i][j].setDeleteNum(records[i][j].getDeleteNum()+1); if(records[i][j].getD().kindOfDish!=null&&records[i][j].getD().kindOfDish.equals("川菜")&&this.iscc) { this.ccDegree-=records[i][j].degree*records[i][j].num; this.ccNum-=records[i][j].num; if(this.ccDegree==0&&this.ccNum==0) this.iscc=false; } if(records[i][j].getD().kindOfDish!=null&&records[i][j].getD().kindOfDish.equals("晋菜")&&this.isjc) { this.jcDegree-=records[i][j].degree*records[i][j].num; this.jcNum-=records[i][j].num; if(this.jcDegree==0&&this.jcNum==0) this.isjc=false; } if(records[i][j].getD().kindOfDish!=null&&records[i][j].getD().kindOfDish.equals("浙菜")&&this.iszc) { this.zcDegree-=records[i][j].degree*records[i][j].num; this.zcNum-=records[i][j].num; if(this.zcDegree==0&&this.zcNum==0) this.iszc=false; } t=records[i][j].getDeleteNum(); if(t>1) { System.out.println("deduplication "+orderNum); } return true; } } System.out.println("delete error;"); return false; } } class Dish { String dishname;//菜品名称 int price,tastenum; //单价 String kindOfDish; public void setKindOfDish(String kindOfDish) { this.kindOfDish = kindOfDish; } boolean T; public void setT(boolean t) { T = t; } public String getDishname() { return dishname; } public void setUnit_price(int unit_price) { this.price = unit_price; } public Dish(String name, String kindOfDish,int unit_price,boolean t) { this.dishname = name; this.kindOfDish=kindOfDish; this.price = unit_price; this.T=t; } int getPrice(int portion) {//计算菜品价格的方法,输入参数是点菜的份额(输入数据只能是1/2/3,代表小/中/大份) if (portion == 2) return (int) Math.round(1.5 *price); else if (portion == 3) return 2 * price ; else return price ; } } class Table{ int num; Time t ; Order order; long Tableprice; String name,phone; int sametime=0,price=0; void price(int i) { t.getDay(); t.getYear(); t.getweekDay(); if (t.weekday<=5&&t.weekday>=1) { if((t.hour>=17&&t.hour<20)||(t.hour==20&&t.minute<=30) ) { this.Tableprice=this.order.getTotalPrice3(i,0.8)+this.order.getTotalPrice4(i,0.7); System.out.print("table "+this.num+": "+(this.order.TotalPrice1(i)+this.order.TotalPrice2(i))+" "+(this.Tableprice+price)); } else if((t.hour==10&&t.minute>=30)||(t.hour>=11&&t.hour<14)||(t.hour==14&&t.minute<=30)) { this.Tableprice=this.order.getTotalPrice3(i,0.6)+this.order.getTotalPrice4(i,0.7); System. out. print("table "+this. num+": "+(this.order.TotalPrice1(i)+this.order.TotalPrice2(i))+" "+(this.Tableprice+price)) ; } } if(t.weekday==6|| t.weekday==7) { if((t.hour==9&&t.minute>=30)|| (t.hour>9&&t.hour<21)||(t.hour==21&&t.minute<=30)) { Tableprice=Math.round ((order.TotalPrice1(i)+order.TotalPrice2(i))); System. out. print ("table "+this. num+": "+(this.order.TotalPrice1(i)+this.order.TotalPrice2(i))+" "+(this.Tableprice+price)) ; } } if(this.order.iscc) { System.out.print(" 川菜 " + this.order.ccNum ); int a=(int)Math.round(this.order.ccDegree/(this.order.ccNum*1.0) ); if(a==0) System.out.print(" 不辣"); if(a==1) System.out.print(" 微辣"); if(a==2) System.out.print(" 稍辣"); if(a==3) System.out.print(" 辣"); if(a==4) System.out.print(" 很辣"); if(a==5) System.out.print(" 爆辣"); } if(this.order.isjc) { System.out.print(" 晋菜 " + this.order.jcNum ); int a=(int)Math.round(this.order.jcDegree/(this.order.jcNum*1.0) ); if(a==0) System.out.print(" 不酸"); if(a==1) System.out.print(" 微酸"); if(a==2) System.out.print(" 稍酸"); if(a==3) System.out.print(" 酸"); if(a==4) System.out.print(" 很酸"); } if(this.order.iszc) { System.out.print(" 浙菜 " + this.order.zcNum ); int a=(int)Math.round(this.order.zcDegree/(this.order.zcNum*1.0) ); if(a==0) System.out.print(" 不甜"); if(a==1) System.out.print(" 微甜"); if(a==2) System.out.print(" 稍甜"); if(a==3) System.out.print(" 甜"); } if(!this.order.iszc&&!this.order.isjc&&!this.order.iscc) System.out.print(" "); System.out.print("\n"); } } class Time { String time1,time2; int year,month,day,hour,minute,weekday; public void getweekDay() { this.weekday=LocalDateTime.of(this.year, this.month, this.day, this.hour, this.minute).getDayOfWeek().getValue(); } public void getYear() { String Date1[] = time1.split("\\/"); year = Integer.parseInt(Date1[0]); month = Integer.parseInt(Date1[1]); day = Integer.parseInt(Date1[2]); } public void getDay() { String Date2[] = time2.split("\\/"); hour = Integer.parseInt(Date2[0]); minute = Integer.parseInt(Date2[1]); } } class Record { public int numOrder;//序号 public Dish d;//菜品 public int portion,num,degree;//份额(1/2/3代表小/中/大份) public boolean isreplace,isDelete = false; public int deleteNum=0; public int getDeleteNum() { return deleteNum; } public void setDeleteNum(int deleteNum) { this.deleteNum = deleteNum; } public boolean isNotFound() { return notFound; } public boolean notFound = false; public Record(int orderNum, Dish d,int degree, int portion, int num) { this.numOrder = orderNum; this.d = d; d.tastenum=degree; this.degree = degree; this.portion = portion; this.num = num; } int getPrice() { return d.getPrice(portion) * this.num; } public int getNumOrder() { return numOrder; } public Dish getD() { return d; } public void setDelete(boolean delete) { isDelete = delete; } public boolean isDelete() { return isDelete; } }
这个题目又相对于第三个和第四个而言,增加了输入(菜类,辣度,甜度等),对于我这个废物来说,我又是少点这个,少点那个的
在判断辣度和甜度的越界时,没有添加条件,越界有错误。在分类的菜类的内容时,也是在辣度和甜度的越界值有问题。
另外的就是在:单用户—多菜系—含错误记录。发现错误。但时找不到错误,不知道更改。
其次:单用户—含错误记录-含删除记录。
类图如下:


浙公网安备 33010602011771号