首页 > 其他分享 >BLOG-2

BLOG-2

时间:2023-06-28 22:23:07浏览次数:30  
标签:lineArray int BLOG && time table public

前言:

第四次题目集:第四次题目集只有一道题目,是菜单计价系统4,该次计价系统在菜单计价系统3的基础上添加了特色菜功能,并且增加了一些对错误信息的输出语句,最后还改进了价格的输出方式,改为输出打折前的价格与打折后的价格。难度增加相对较小。

第五次题目集:第五次题目集同样只有一道题目,是菜单计价系统5,该题目也是在菜单计价系统3的基础上进行更改,但是难度大大增加,需要做出大改动。该次菜单计价系统在3的基础之上增加了特色菜的口味类型,并且每个口味类型还有对应的程度值,然后在点菜的输入方式上也作出了很大的改变,点特色菜时需要增加一个口味值的输入,然后在输出的部分也同样需要输出特色菜品的口味类型与口味值。该次题集需要改动的地方很多,难度较大。

期中考试题目集:该次题集比较简单,题目有四道,属于层层递进型,第一题是计算圆的面积,第二题是计算矩形的面积,第三题是把前两题合起来,对所求的图形类型进行选择然后输出对应的面积,第四题则是增加了对面积大小的排序。

设计与分析:

7-1 菜单计价程序-4 分数 100 作者 蔡轲 单位 南昌航空大学

本体大部分内容与菜单计价程序-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+英文空格+桌号+“:”+英文空格+当前桌的原始总价+英文空格+当前桌的计算折扣后总价

输入样例:

在这里给出一组输入。例如:

麻婆豆腐 12
油淋生菜 9 T
table 31 2023/2/1 14/20/00
1 麻婆豆腐 1 16
2 油淋生菜 1 2
2 delete
2 delete
end
 

输出样例:

在这里给出相应的输出。例如:

table 31: 
1 num out of range 16
2 油淋生菜 18
deduplication 2
table 31: 0 0
 

输入样例1:

份数超出范围+份额超出范围。例如:

麻婆豆腐 12
油淋生菜 9 T
table 31 2023/2/1 14/20/00
1 麻婆豆腐 1 16
2 油淋生菜 4 2
end
 

输出样例1:

份数超出范围+份额超出范围。例如:

table 31: 
1 num out of range 16
2 portion out of range 4
table 31: 0 0
 

输入样例2:

桌号信息错误。例如:

麻婆豆腐 12
油淋生菜 9 T
table a 2023/3/15 12/00/00
1 麻婆豆腐 1 1
2 油淋生菜 2 1
end
 

输出样例2:

在这里给出相应的输出。例如:

wrong format
 

输入样例3:

混合错误:桌号信息格式错误+混合的菜谱信息(菜谱信息忽略)。例如:

麻婆豆腐 12
油淋生菜 9 T
table 55 2023/3/31 12/000/00
麻辣香锅 15
1 麻婆豆腐 1 1
2 油淋生菜 2 1
end
 

输出样例3:

在这里给出相应的输出。例如:

wrong format
 

输入样例4:

错误的菜谱记录。例如:

麻婆豆腐 12.0
油淋生菜 9 T
table 55 2023/3/31 12/00/00
麻辣香锅 15
1 麻婆豆腐 1 1
2 油淋生菜 2 1
end
 

输出样例4:

在这里给出相应的输出。例如:

wrong format
table 55: 
invalid dish
麻婆豆腐 does not exist
2 油淋生菜 14
table 55: 14 10
 

输入样例5:

桌号格式错误(以“table”开头)+订单格式错误(忽略)。例如:

麻婆豆腐 12
油淋生菜 9 T
table a 2023/3/15 12/00/00
1 麻婆 豆腐 1 1
2 油淋生菜 2 1
end
 

输出样例5:

在这里给出相应的输出。例如:

wrong format
 

输入样例6:

桌号格式错误,不以“table”开头。例如:

麻婆豆腐 12
油淋生菜 9 T
table 1 2023/3/15 12/00/00
1 麻婆豆腐 1 1
2 油淋生菜 2 1
tab le 2 2023/3/15 12/00/00
1 麻婆豆腐 1 1
2 油淋生菜 2 1
end
 

输出样例6:

在这里给出相应的输出。例如:

table 1: 
1 麻婆豆腐 12
2 油淋生菜 14
wrong format
record serial number sequence error
record serial number sequence error
table 1: 26 17
 

其他用例请参考公开的测试用例

代码长度限制 50 KB 时间限制 1000 ms 内存限制 64 MB   分析:该题主要是在菜单计价程序3的基础之上增加特色菜一类,对此需要增加一种对输入数据类型的判断,然后在菜单类的存储之中也增加一种类型用于存储特色菜。由于对菜价输出形式的更改,因此需要增加对菜价计算的方法,然后在后面输出是对两种总价计算进行调用,以此达到输出打折前与打折后的总价的目的。 代码如下:

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
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 nextLine = input.nextLine();
int i=0;
int num=0;
int flag=0;
int temp=0;
int sametime=0;
while (!nextLine.equals("end")) {
String[] lineArray = nextLine.split(" ");
if(lineArray.length == 4&& lineArray[0].equals("table") && canParseInt(lineArray[1]) && judgeOne(lineArray[2], lineArray[3]) &&Integer.parseInt(lineArray[1])<=55&&Integer.parseInt(lineArray[1])>0 && isOpen(lineArray[2], lineArray[3]) &&judgeThree(lineArray[1])) {
i++;
flag=1;
num=0;
sametime=0;
table[i]=new Table();
table[i].order=new Order(menu);
table[i].num=Integer.parseInt(lineArray[1]);
table[i].time=new Time();
table[i].time.time1=lineArray[2];
table[i].time.time2=lineArray[3];
System.out.println("table "+Integer.parseInt(lineArray[1])+": ");
temp=0;
if(i>1&&sameTime(table[i].time.time1,table[i].time.time2)==sameTime(table[i-1].time.time1,table[i-1].time.time2)&&table[i].time.time1.equals(table[i-1].time.time1)){
sametime=1;
}

}
else if(nextLine.length()==0){
System.out.println("wrong format");
temp=1;
}
else if (lineArray.length == 4&& lineArray[0].equals("table") && !judgeThree(lineArray[1])) {
System.out.println("wrong format");
temp=1;
}
else if(lineArray[0].length() == 4&&lineArray.length>3)
System.out.println("wrong format");
else if(lineArray[0].equals("table")&&lineArray.length >4){
System.out.println("wrong format");
temp=1;
}
else if(lineArray.length == 4&& lineArray[0].equals("table") &&(!canParseInt(lineArray[1]) || !judgeOne(lineArray[2], lineArray[3]) ||Integer.parseInt(lineArray[1])>55||Integer.parseInt(lineArray[1])<=0|| !isOpen(lineArray[2], lineArray[3]))) {
if(!canParseInt(lineArray[1]))
System.out.println("wrong format");
else if(Integer.parseInt(lineArray[1])>55||Integer.parseInt(lineArray[1])<=0)
System.out.println(Integer.parseInt(lineArray[1])+" table num out of range");
else if(judgeTwo(lineArray[2], lineArray[3]) && !judgeOne(lineArray[2], lineArray[3]))
System.out.println("not a valid time period");
temp=1;
}
else if (lineArray.length == 4&& !lineArray[0].equals("table") &&temp==0) {
int orderNum = Integer.parseInt(lineArray[0]);
String dishName = lineArray[1];
int parseInt = Integer.parseInt(lineArray[2]);
int parseInt1 = Integer.parseInt(lineArray[3]);
if(orderNum<=num)
System.out.println("record serial number sequence error");
else if(lineArray[0].length()>1&&Integer.parseInt(lineArray[0])<10)
System.out.println("wrong format");
else {
if(sametime==0&&table[i].order.addARecord(orderNum, dishName, parseInt, parseInt1)!=null)
num=orderNum;
else if(sametime==1){
table[i-1].order.addARecord(orderNum, dishName, parseInt, parseInt1);

}
}
}

else if ("delete".equals(lineArray[1])&&temp==0) {
table[i].order.delARecordByOrderNum(Integer.parseInt(lineArray[0]));
}
else if(lineArray.length ==5&& canParseInt(lineArray[0]) && canParseInt(lineArray[1])){
int a=0;
if(i>1){
for(int j=0;j<i;j++){
if(table[j].num==Integer.parseInt(lineArray[1])){
table[j].order.addARecord(Integer.parseInt(lineArray[1]),lineArray[2],Integer.parseInt(lineArray[3]),Integer.parseInt(lineArray[4]));
a=1;
}
}
if(a!=1) 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 > 4&&(lineArray[3].length()>=8||lineArray[4].length()>=8))
System.out.println("wrong format");
else {
if((lineArray.length == 3||lineArray.length == 2)&& !canParseInt(lineArray[1]) && !lineArray[1].equals("delete")) {
System.out.println("wrong format");
}
if(lineArray.length == 3&& canParseInt(lineArray[1]) &&lineArray[2].equals("T"))
menu.addDish(lineArray[0], Integer.parseInt(lineArray[1]),true);
if(lineArray.length == 3&& canParseInt(lineArray[1]) && !lineArray[2].equals("T"))
System.out.println("wrong format");
if(lineArray.length == 2&& canParseInt(lineArray[1]) &&flag==0)
menu.addDish(lineArray[0], Integer.parseInt(lineArray[1]),false);
if((lineArray.length == 2||lineArray.length == 3)&&flag==1)
System.out.println("invalid dish");
}
if(lineArray.length == 4&& lineArray[0].equals("table") && canParseInt(lineArray[1]) &&(!judgeTwo(lineArray[2], lineArray[3]) || !isOpen(lineArray[2], lineArray[3]))) {
if(lineArray[3].length()>8||lineArray[2].length()>10)
System.out.println("wrong format");
else if(!judgeTwo(lineArray[2], lineArray[3]))
System.out.println(Integer.parseInt(lineArray[1]) + " date error");
else
if (!isOpen(lineArray[2], lineArray[3]) && judgeOne(lineArray[2], lineArray[3]))
System.out.println("table " + Integer.parseInt(lineArray[1]) + " out of opening hours");
}
nextLine = input.nextLine();
}
for(int j=1;j<=i;j++){
table[i].getPrice();
}
}
public static boolean canParseInt(String s) {
if(s==null) {
return false;
}
return s.matches("\\d+");
}
public static boolean judgeOne(String s1 ,String s2){

String Date1[] = s1.split("\\/");
int year = Integer.parseInt(Date1[0]);
int month = Integer.parseInt(Date1[1]);
int day = Integer.parseInt(Date1[2]);

String Date2[] =s2.split("\\/");
int hour = Integer.parseInt(Date2[0]);
int minute = Integer.parseInt(Date2[1]);
int miao=Integer.parseInt(Date2[2]);
if(Date1[0].length()!=4||Date1[1].length()>2||Date1[2].length()>2||Date2[0].length()>2||Date2[1].length()>2||Date2[2].length()>2||year<2022||year>2023||month>12||month<1||day>31||day<0||hour>24||
hour<0||minute>60||minute<0||miao>60||miao<0||(month==2&&day>28)
||((month==4||month==6||month==9||month==11)&&day>30)){
return false;
}
return true;

}
public static boolean judgeTwo(String s1 ,String s2){

String Date1[] = s1.split("\\/");
int year = Integer.parseInt(Date1[0]);
int month = Integer.parseInt(Date1[1]);
int day = Integer.parseInt(Date1[2]);

String Date2[] =s2.split("\\/");
int hour = Integer.parseInt(Date2[0]);
int minute = Integer.parseInt(Date2[1]);
int miao=Integer.parseInt(Date2[2]);
if(Date1[0].length()!=4||Date1[1].length()>2||Date1[2].length()>2||Date2[0].length()>2||Date2[1].length()>2||Date2[2].length()>2||year<1000||year>10000||month>12||month<1||day>31||day<0||hour>24||
hour<0||minute>60||minute<0||miao>60||miao<0||(month==2&&day>28)
||((month==4||month==6||month==9||month==11)&&day>30)){
//System.out.println(num+" date error");
return false;
}
return true;

}
public static int sameTime(String s1 ,String s2) {
Time time = new Time();
time.time1 = s1;
time.time2 = s2;
time.getDay();
time.getYear();
time.getweekOfDay();
if (time.weekday <= 5 && time.weekday >= 1) {
if ((time.hour >= 17 && time.hour < 20) || (time.hour == 20 && time.minute <= 30)) {
return 1;
}
else if ((time.hour == 10 && time.minute >= 30) || (time.hour >= 11 && time.hour < 14) || (time.hour == 14 && time.minute <= 30)) {
return -1;
}
}
if (time.weekday == 6 || time.weekday == 7) {
if ((time.hour == 9 && time.minute >= 30) || (time.hour > 9 && time.hour < 21) || (time.hour == 21 && time.minute <= 30)) {
return 2;
}
}
return 0;
}
public static boolean isOpen(String s1 ,String s2){
Time time = new Time();
time.time1=s1;
time.time2=s2;
time.getDay();
time.getYear();
time.getweekOfDay();
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;
}
}
public static boolean judgeThree(String s) {
String regex = "[1-9][0-9]|[1-9]";
if(s.matches(regex))
{
return true;
}
return false;
}
}
class Order {
private Menu menu;
private static List<Record> records = new ArrayList<>();//保存订单上每一道的记录

public Order(Menu menu) {
this.menu = menu;
}

//计算订单的总价
int getTotalPrice() {
int sum = 0;
for (Record record : records) {
int price = record.getPrice();

if (!record.isDelete()&& !record.getD().judge) {
sum = sum + price;

}
}
return sum;
}
int getTotalPrice2() {
int sum = 0;
for (Record record : records) {
int price = record.getPrice();

if (!record.isDelete()&& record.getD().judge) {
sum = sum + price;

}
}
return sum;
}

//添加一条菜品信息到订单中。
Record addARecord(int orderNum, String dishName, int portion, int num) {
Dish dish = menu.searthDish(dishName);
if (dish == null) {
System.out.println(dishName + " does not exist");
return null;
}
if(num>=15){
System.out.println(orderNum+" num out of range "+num);
return null;
}
if(portion>3||portion<1){
System.out.println(orderNum+" portion out of range " +portion);
return null;
}
Record record = new Record(orderNum, dish, portion, num);
records.add(record);
int price = record.getPrice();
System.out.println(record.getNumOrder() + " " + record.getD().getDishname() + " " + price);
return record;
}

public boolean delARecordByOrderNum(int orderNum) {
for (Record record : records) {
if (record.isNotFound() && !record.isDelete() && record.getNumOrder() == orderNum) {
record.setDelete(true);
return true;
}
if (record.isNotFound() && record.isDelete() && record.getNumOrder() == orderNum) {
System.out.println("deduplication " + record.getNumOrder());
return false;
}
}
System.out.println("delete error;");
return false;
}
}
class Record {
private int numOrder;//序号\
private Dish d;//菜品\
private int portion;//份额(1/2/3代表小/中/大份)\
private int num;
private boolean isDelete = false;

public boolean isNotFound() {
return !notFound;
}

public void setNotFound(boolean notFound) {
this.notFound = notFound;
}

private boolean notFound = false;

 

public Record(int orderNum, Dish d, int portion, int num) {
this.numOrder = orderNum;
this.d = d;
this.portion = portion;
this.num = num;
}
public Record(Dish d, int portion) {
this.d = d;
this.portion = portion;
}

//计价,计算本条记录的价格
int getPrice() {
return d.getPrice(portion) * this.num;
}
public void setNumOrder(int numOrder) {
this.numOrder = numOrder;
}
public int getNumOrder() {
return numOrder;
}

public void setD(Dish d) {
this.d = d;
}
public Dish getD(){
return d;
}
public void setDelete(boolean delete) {
isDelete = delete;
}
public boolean isDelete() {
return isDelete;
}

}
class Dish {
String dishname;//菜品名称
int unit_price; //单价
boolean judge;
public String getDishname() {
return dishname;
}

public void setUnit_price(int unit_price) {
this.unit_price = unit_price;
}

public Dish(String name, int unit_price, boolean judge) {
this.dishname = name;
this.unit_price = unit_price;
this.judge = judge;
}

 

//计算菜品价格的方法,输入参数是点菜的份额(输入数据只能是1/2/3,代表小/中/大份)
int getPrice(int portion) {
if (portion >= 1 && portion <= 3) {
float botsum[] = {1, 1.5f, 2};
return Math.round(unit_price * botsum[portion - 1]);
}

return 0;
}
}
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, int unit_price,boolean g) {
for (Dish dish : dishs) {
if (dish.getDishname().equals(dishName)) {
dish.setUnit_price(unit_price);
return dish;
}
}
Dish dish = new Dish(dishName, unit_price,g);
dishs.add(dish);
return dish;
}
}
class Table {
Time time;
Order order;
int tablePrice;
int num;

public void getPrice() {
time.getYear();
time.getDay();
time.getweekOfDay();
if(time.weekday>=1&&time.weekday<=5) {
if(time.hour >= 17 && time.hour <= 20 && time.minute >= 0 && time.minute < 60) {
tablePrice= (int) Math.round(order.getTotalPrice2()*0.7+order.getTotalPrice()*0.8);
System.out.println("table "+this.num+": "+(order.getTotalPrice2()+order.getTotalPrice())+" "+this.tablePrice);
}
else if((time.hour==10&&time.minute>=30&&time.minute<60)||((time.hour>=11&&time.hour<14)&&(time.minute>=0&&time.minute<60))||(time.hour==14&&time.minute<=30&&time.minute>0)) {
tablePrice= (int) Math.round(order.getTotalPrice2()*0.7+order.getTotalPrice()*0.6);
System.out.println("table "+this.num+": "+(order.getTotalPrice2()+order.getTotalPrice())+" "+this.tablePrice);
}
else
System.out.println("table " + this.num + " out of opening hours");
}
if(time.weekday==6||time.weekday==7) {
if((time.hour==9&&time.minute>=30&&time.minute<60)||((time.hour>=10&&time.hour<21)&&(time.minute>=0&&time.minute<60))||(time.hour==21&&time.minute<=30&&time.minute>0)) {
tablePrice=Math.round(order.getTotalPrice2()+order.getTotalPrice());
System.out.println("table "+this.num+": "+(this.order.getTotalPrice2()+this.order.getTotalPrice())+" "+this.tablePrice);
}
else
System.out.println("table " + this.num + " out of opening hours");
}
}
}
class Time {
String time1;
String time2;
int year;
int month;
int day;
int hour;
int minute;
int weekday;
public void getweekOfDay() {
this.weekday= LocalDateTime.of(this.year, this.month, this.day, this.hour, this.minute).getDayOfWeek().getValue();
}
void getYear(){
String[] date=time1.split("\\/");
year=Integer.parseInt(date[0]);
month=Integer.parseInt(date[1]);
day=Integer.parseInt(date[2]);
if((year>=2022&&month>=1&&day>=1)||(year<=2023&&month<=12&&day<=31)){

}
else
System.out.println("not a valid time period");
}
void getDay(){
String[] date=time2.split("\\/");
hour=Integer.parseInt(date[0]);
minute=Integer.parseInt(date[1]);
}
}

 

  7-1 菜单计价程序-5 分数 100 作者 蔡轲 单位 南昌航空大学

本题在菜单计价程序-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:

桌号时间超出营业范围。例如:

麻婆豆腐 川菜 12 T
油淋生菜 9
麻辣鸡丝 10
table 1 : tom 13605054400 2023/5/1 21/30/00
1 麻婆豆腐 3 1 2
2 油淋生菜 2 1
3 麻婆豆腐 2 3 2
end
 

输出样例1:

在这里给出相应的输出。例如:

table 1 out of opening hours
 

输入样例2:

一种口味的菜品。例如:

麻婆豆腐 川菜 12 T
油淋生菜 9
麻辣鸡丝 10
table 1 : tom 13605054400 2023/5/1 20/30/00
1 麻婆豆腐 2 1 2
2 油淋生菜 2 1
3 麻婆豆腐 2 3 2
end
 

输出样例2:

在这里给出相应的输出。例如:

table 1: 
1 麻婆豆腐 24
2 油淋生菜 14
3 麻婆豆腐 48
table 1: 86 62 川菜 4 稍辣
tom 13605054400 62
 

 

输入样例3:

辣度值超出范围。例如:

麻婆豆腐 川菜 12 T
油淋生菜 9
麻辣鸡丝 10
table 1 : tom 13605054400 2023/5/1 18/30/00
1 麻婆豆腐 6 1 2
2 油淋生菜 1 1
3 麻婆豆腐 5 3 2
end
 

输出样例3:

在这里给出相应的输出。例如:

table 1: 
spicy num out of range :6
2 油淋生菜 9
3 麻婆豆腐 48
table 1: 57 41 川菜 2 爆辣
tom 13605054400 41
 

输入样例4:

同一用户对应多桌菜。例如:

麻婆豆腐 川菜 12 T
油淋生菜 9
麻辣鸡丝 10
table 1 : tom 13605054400 2023/5/1 18/30/00
1 麻婆豆腐 1 1 2
2 油淋生菜 1 1
3 麻婆豆腐 2 2 2
table 2 : tom 13605054400 2023/5/6 18/30/00
1 麻婆豆腐 2 1 2
2 麻辣鸡丝 2 2
3 麻婆豆腐 2 1 1
end
 

输出样例4:

在这里给出相应的输出。例如:

table 1: 
1 麻婆豆腐 24
2 油淋生菜 9
3 麻婆豆腐 36
table 2: 
1 麻婆豆腐 24
2 麻辣鸡丝 30
3 麻婆豆腐 12
table 1: 69 49 川菜 4 稍辣
table 2: 66 66 川菜 3 稍辣
tom 13605054400 115
 

输入样例5:

多用户多桌菜。例如:

东坡肉 浙菜 25 T
油淋生菜 9
蜜汁灌藕 浙菜 10 T
刀削面 晋菜 10 T
醋浇羊肉 晋菜 30 T
麻婆豆腐 川菜 12 T
麻辣鸡丝 川菜 15 T
table 1 : tom 13605054400 2023/5/6 12/30/00
1 醋浇羊肉 4 1 1
3 刀削面 1 1 3
2 东坡肉 3 2 1
4 麻辣鸡丝 2 1 1
table 2 : jerry 18100334566 2023/5/1 12/30/00
1 醋浇羊肉 1 1 2
3 麻婆豆腐 2 2 1
4 麻辣鸡丝 2 3 3
table 3 : jerry 18100334566 2023/5/1 12/30/00
1 醋浇羊肉 2 1 1
3 蜜汁灌藕 1 1 2
2 东坡肉 2 2 1
4 麻辣鸡丝 5 1 1
end
 

输出样例5:

在这里给出相应的输出。例如:

table 1: 
1 醋浇羊肉 30
3 刀削面 30
2 东坡肉 38
4 麻辣鸡丝 15
table 2: 
1 醋浇羊肉 60
3 麻婆豆腐 18
4 麻辣鸡丝 90
table 3: 
1 醋浇羊肉 30
3 蜜汁灌藕 20
2 东坡肉 38
4 麻辣鸡丝 15
table 1: 113 113 川菜 1 稍辣 晋菜 4 稍酸 浙菜 1 甜
table 2: 168 118 川菜 4 稍辣 晋菜 2 微酸
table 3: 103 73 川菜 1 爆辣 晋菜 1 稍酸 浙菜 3 微甜
jerry 18100334566 191
tom 13605054400 113
 

输入样例6:

多用户多桌菜含代点菜。例如:

东坡肉 浙菜 25 T
油淋生菜 9
蜜汁灌藕 浙菜 10 T
刀削面 晋菜 10 T
醋浇羊肉 晋菜 30 T
麻婆豆腐 川菜 12 T
麻辣鸡丝 川菜 15 T
table 1 : tom 13605054400 2023/5/6 12/30/00
1 醋浇羊肉 4 1 1
3 刀削面 1 1 3
2 东坡肉 3 2 1
4 麻辣鸡丝 2 1 1
table 2 : jerry 18100334566 2023/5/1 12/30/00
1 1 醋浇羊肉 0 1 2
3 麻婆豆腐 2 2 1
4 麻辣鸡丝 2 3 3
table 3 : lucy 18957348763 2023/5/1 12/30/00
1 醋浇羊肉 2 1 1
3 蜜汁灌藕 1 1 2
2 东坡肉 2 2 1
4 麻辣鸡丝 5 1 1
end
 

输出样例6:

在这里给出相应的输出。例如:

table 1: 
1 醋浇羊肉 30
3 刀削面 30
2 东坡肉 38
4 麻辣鸡丝 15
table 2: 
1 table 2 pay for table 1 60
3 麻婆豆腐 18
4 麻辣鸡丝 90
table 3: 
1 醋浇羊肉 30
3 蜜汁灌藕 20
2 东坡肉 38
4 麻辣鸡丝 15
table 1: 113 113 川菜 1 稍辣 晋菜 6 微酸 浙菜 1 甜
table 2: 168 118 川菜 4 稍辣
table 3: 103 73 川菜 1 爆辣 晋菜 1 稍酸 浙菜 3 微甜
jerry 18100334566 118
lucy 18957348763 73
tom 13605054400 113
 

输入样例7:

错误的菜品记录和桌号记录,用户丢弃。例如:

东坡肉 25 T
油淋生菜 9
table 1 : tom 136050540 2023/5/1 12/30/00
2 东坡肉 3 2 1
end
 

输出样例7:

在这里给出相应的输出。例如:

wrong format
wrong format
  代码长度限制 50 KB 时间限制 1000 ms 内存限制 64 MB   分析:该题需要对输入方式的判断进行很大改进,但是同样也能够通过长度的不同来区分不同菜的类型,然后改动存储菜单及订单信息的传入参数以实现更改后菜单的存储。然后同样需要对输入特色菜品口味值的范围是否合法进行判断,除此之外,还需要处理客户的电话号码信息,需要判断客户的电话号码,姓名是否合法,当输入的数据非法时,需要输出对应的语句,然后在最后输出时,需要输出客户名字,电话及总价。 代码如下:


import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
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 nextLine = input.nextLine();
int i = 0;
int flag = 0;
int temp = 0;
while (!nextLine.equals("end")) {
String[] lineArray = nextLine.split(" ");
if(nextLine.equals("")) {
nextLine = input.nextLine();
System.out.println("wrong format");
continue;
}

else if(lineArray.length == 7&& !lineArray[0].equals("table") &&lineArray[2].length()>8)
System.out.println("wrong format");
else if(lineArray.length == 7&& lineArray[0].equals("table") && canParseInt(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].peopleName=lineArray[3];
table[i].telephone=lineArray[4];
table[i].time=new Time();
table[i].time.time1=lineArray[5];
table[i].time.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])) {
System.out.println("wrong format");
temp=1;
}
else if(lineArray.length == 7&& lineArray[0].equals("table") &&(!canParseInt(lineArray[1]) ||Integer.parseInt(lineArray[1])>55||Integer.parseInt(lineArray[1])<=0||isOpen(lineArray[5],lineArray[6])==false)) {
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&&canParseInt(lineArray[0])) {
int orderNum = Integer.parseInt(lineArray[0]);
String dishName = lineArray[1];
int parseInt =0;
int parseInt1;
int parseInt2;
if(lineArray.length == 4){
parseInt1 = Integer.parseInt(lineArray[2]);
parseInt2 = Integer.parseInt(lineArray[3]);
}else
{
parseInt = Integer.parseInt(lineArray[2]);
parseInt1 = Integer.parseInt(lineArray[3]);
parseInt2 = Integer.parseInt(lineArray[4]);
}

if(lineArray[0].length()>1&&Integer.parseInt(lineArray[0])<10)
System.out.println("wrong format");
else {
if(table[i].order.addARecord(orderNum, dishName, parseInt, parseInt1,parseInt2,i,false)!=null) {

}
}
}
else if ("delete".equals(lineArray[1])&&temp==0) {
table[i].order.delARecordByOrderNum(Integer.parseInt(lineArray[0]),i);

}

else if ((lineArray.length == 5||lineArray.length == 4)&& !lineArray[0].equals("table") &&temp==0&&canParseInt(lineArray[0])) { if(lineArray.length == 5){
if(table[i].order.addARecord(Integer.parseInt(lineArray[0]), lineArray[1], Integer.parseInt(lineArray[2]), Integer.parseInt(lineArray[3]), Integer.parseInt(lineArray[4]),i,false)!=null){}
}
else{
if(table[i].order.addARecord(Integer.parseInt(lineArray[0]),lineArray[1],0, Integer.parseInt(lineArray[2]), Integer.parseInt(lineArray[3]),i,false)!=null){}
}
}
else if(lineArray.length == 4&&flag==0) { //特色菜添加
if (lineArray[3].equals("T"))
menu.addDish(lineArray[0],lineArray[1],Integer.parseInt(lineArray[2]),true);
}
else if(lineArray.length == 2&&flag==0){//普通菜添加
menu.addDish(lineArray[0],null,Integer.parseInt(lineArray[1]),false);
}
else if(lineArray.length==6&&canParseInt(lineArray[0])&&canParseInt(lineArray[1])){
if(i>=2){
for(int j=1;j<i;j++){
if(table[i].num==Integer.parseInt(lineArray[1])){
Dish dish = menu.searthDish(lineArray[2]);
int price;
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);
}
}
}
}

else if ((lineArray.length == 5||lineArray.length == 4)&& !lineArray[0].equals("table") &&temp==0&&canParseInt(lineArray[0])) { if(lineArray.length == 5){
if(table[i].order.addARecord(Integer.parseInt(lineArray[0]), lineArray[1], Integer.parseInt(lineArray[2]), Integer.parseInt(lineArray[3]), Integer.parseInt(lineArray[4]),i,false)!=null){}
}
else{
if(table[i].order.addARecord(Integer.parseInt(lineArray[0]),lineArray[1],0, Integer.parseInt(lineArray[2]), Integer.parseInt(lineArray[3]),i,false)!=null){}
}
}
else {
if((lineArray.length == 3)&& !canParseInt(lineArray[0]) && !lineArray[1].equals("delete")) {
System.out.println("wrong format");
}
if(lineArray.length == 4&& canParseInt(lineArray[2]) &&lineArray[3].equals("T"))
menu.addDish(lineArray[0], lineArray[1],Integer.parseInt(lineArray[2]),true);
if(lineArray.length == 2&& canParseInt(lineArray[1]) &&flag==0)
menu.addDish(lineArray[0], null,Integer.parseInt(lineArray[1]),false);
}
if(lineArray.length == 7&& lineArray[0].equals("table") && canParseInt(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");
}
nextLine = input.nextLine();
}
input.close();
for(int j=1;j<=i;j++){
table[j].getprice(j);
}
for(int j=1;j<=i;j++){
for(int k=j+1;k<=i;k++) {
if (table[j].peopleName!=null&&table[k].peopleName!=null&&table[j].peopleName.compareTo(table[k].peopleName) == 0){
table[k].peopleName=null;
table[j].tablePrice+=table[k].tablePrice;
}
if(table[j].peopleName!=null&&table[k].peopleName!=null&&table[j].peopleName.compareTo(table[k].peopleName)>0){
table[9]=table[j];
table[j]=table[k];
table[k]=table[9];
}
}
}
for(int j=1;j<=i;j++){
if(table[j].peopleName!=null)
System.out.println(table[j].peopleName+" "+table[j].telephone+" "+table[j].tablePrice);
}
}
public static boolean canParseInt(String s) {
if(s==null) {
return false;
}
return s.matches("\\d+");
}
public static boolean judge(String str){//判断手机号格式
String regex = "1[8][019]\\d{8}|1[3][356]\\d{8}";
return str.matches(regex);
}
public static boolean judgeOne(String s1 ,String s2){

String Date1[] = s1.split("\\/");
int year = Integer.parseInt(Date1[0]);
int month = Integer.parseInt(Date1[1]);
int day = Integer.parseInt(Date1[2]);

String Date2[] =s2.split("\\/");
int hour = Integer.parseInt(Date2[0]);
int minute = Integer.parseInt(Date2[1]);
int miao=Integer.parseInt(Date2[2]);
if(Date1[0].length()!=4||Date1[1].length()>2||Date1[2].length()>2||Date2[0].length()>2||Date2[1].length()>2||Date2[2].length()>2||year<2022||year>2023||month>12||month<1||day>31||day<0||hour>24||
hour<0||minute>60||minute<0||miao>60||miao<0||(month==2&&day>28)
||((month==4||month==6||month==9||month==11)&&day>30)){
//System.out.println(num+" date error");
return false;
}
return true;

}
public static boolean judgeTwo(String s1 ,String s2){

String Date1[] = s1.split("\\/");
int year = Integer.parseInt(Date1[0]);
int month = Integer.parseInt(Date1[1]);
int day = Integer.parseInt(Date1[2]);

String Date2[] =s2.split("\\/");
int hour = Integer.parseInt(Date2[0]);
int minute = Integer.parseInt(Date2[1]);
int miao=Integer.parseInt(Date2[2]);
if(Date1[0].length()!=4||Date1[1].length()>2||Date1[2].length()>2||Date2[0].length()>2||Date2[1].length()>2||Date2[2].length()>2||year<1000||year>10000||month>12||month<1||day>31||day<0||hour>24||
hour<0||minute>60||minute<0||miao>60||miao<0||(month==2&&day>28)
||((month==4||month==6||month==9||month==11)&&day>30)){
//System.out.println(num+" date error");
return false;
}
return true;
}

public static boolean isOpen(String s1 ,String s2){
Time time = new Time();
time.time1=s1;
time.time2=s2;
time.getDay();
time.getYear();
time.getweekOfDay();
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;
}
}
public static boolean judgeThree(String s) {
String regex = "[1-9][0-9]|[1-9]";
if(s.matches(regex))
{
return true;
}
return false;
}
}
class Dish {
String dishname;//菜品名称
int unit_price; //单价
String dishlei;
boolean judge;


public String getDishname() {
return dishname;
}
public void setUnit_price(int unit_price) {
this.unit_price = unit_price;
}

public Dish(String name,String dishlei, int unit_price, boolean judge) {
this.dishname = name;
this.dishlei=dishlei;
this.unit_price = unit_price;
this.judge = judge;
}

//计算菜品价格的方法,输入参数是点菜的份额(输入数据只能是1/2/3,代表小/中/大份)
int getPrice(int portion) {
if (portion >= 1 && portion <= 3) {
float botsum[] = {1, 1.5f, 2};
return Math.round(unit_price * botsum[portion - 1]);
}

return 0;
}


}

class Menu {
private final 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 dishlei,int unit_price,boolean g) {
for (Dish dish : dishs) {
if (dish.getDishname().equals(dishName)) {
dish.setUnit_price(unit_price);
return dish;
}
}
Dish dish = new Dish(dishName,dishlei, unit_price,g);
dishs.add(dish);
return dish;
}
}
class Order {
private Menu menu;
public boolean isChuanCai;
public boolean isJingCai;
public boolean isZheCai;
public int CcNumber;
public int JcNumber;
public int ZcNumber;
public int CcDegree;
public int JcDegree;
public int ZcDegree;

static Record[][] record=new Record[100][100];

public Order(Menu menu) {
this.menu = menu;
}


//计算订单的总价
int getTotalPrice(int i) {
int sum = 0;
for (int j=1;j<=record[i].length;j++) {
if(record[i][j]==null)break;
int price = record[i][j].getPrice();
if (!record[i][j].isDelete()&& !record[i][j].getD().judge && !record[i][j].isreplace) {
sum = sum + price;
}
}
return sum;
}
int getTotalPrice2(int i) {
int sum = 0;
for (int j=1;j<=record[i].length;j++) {
if(record[i][j]==null)break;
int price = record[i][j].getPrice();
if (!record[i][j].isDelete()&& record[i][j].getD().judge && !record[i][j].isreplace) {
sum = sum + price;
}
}
return sum;
}

//添加一条菜品信息到订单中。
Record addARecord(int orderNum, String dishName, int degree,int portion, int num,int i,boolean isreplace) {
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.dishlei!=null&&dish.dishlei.equals("川菜")&&(degree>5||degree<0)) {
System.out.println("spicy num out of range :" + degree);
return null;
}
if(dish.dishlei!=null&&dish.dishlei.equals("晋菜")&&(degree>4||degree<0)) {
System.out.println("acidity num out of range :" + degree);
return null;
}
if(dish.dishlei!=null&&dish.dishlei.equals("浙菜")&&(degree>3||degree<0)) {
System.out.println("sweetness num out of range :" + degree);
return null;
}

if(dish.dishlei != null && dish.dishlei.equals("川菜")) {
this.isChuanCai=true;
this.CcDegree+=degree*num;
this.CcNumber+=num;
}
if(dish.dishlei != null && dish.dishlei.equals("晋菜") ) {
this.isJingCai=true;
this.JcDegree+=degree*num;
this.JcNumber+=num;
}
if(dish.dishlei!= null && dish.dishlei.equals("浙菜") ) {
this.isZheCai=true;
this.ZcDegree+=degree*num;
this.ZcNumber+=num;
}
int k = 0;
for (int j=1;j<=record[i].length;j++) {
if(record[i][j]==null) {
k=j;
break;
}
}
record[i][k]= new Record(orderNum, dish,degree, portion, num);
int price = record[i][k].getPrice();
record[i][k].isreplace=isreplace;
if(!record[i][k].isreplace)
System.out.println(record[i][k].getNumOrder() + " " + record[i][k].getD().getDishname() + " " + price);
return record[i][k];
}


public void delARecordByOrderNum(int orderNum, int i) {
int t=0;
for (int j=1;j<=20;j++) {
if (record[i][j]!=null&&!record[i][j].isNotFound() &&record[i][j].getNumOrder() == orderNum) {
record[i][j].setDelete(true);
record[i][j].setDeleteNum(record[i][j].getDeleteNum()+1);
t=record[i][j].getDeleteNum();
if(t>1) {
System.out.println("deduplication "+orderNum);
}
return;
}
}
System.out.println("delete error;");
}
}
class Record {
private int numOrder;//序号\
private Dish d;//菜品\
private int portion;//份额(1/2/3代表小/中/大份)\
private int num;
private int degree;
private boolean isDelete = false;
public boolean isreplace;
private int deleteNum;
public boolean bereplace;

public boolean isBereplace() {
return bereplace;
}

public void setBereplace(boolean bereplace) {
this.bereplace = bereplace;
}

public int getPortion() {
return portion;
}

public int getDeleteNum() {
return deleteNum;
}

public void setDeleteNum(int deleteNum) {
this.deleteNum = deleteNum;
}

public void setPortion(int portion) {
this.portion = portion;
}

public int getNum() {
return num;
}

public void setNum(int num) {
this.num = num;
}

public boolean isIsreplace() {
return isreplace;
}

public void setIsreplace(boolean isreplace) {
this.isreplace = isreplace;
}

public Record() {

}

public int getDegree() {
return degree;
}

public void setDegree(int degree) {
this.degree = degree;
}

public boolean isNotFound() {
return notFound;
}

public void setNotFound(boolean notFound) {
this.notFound = notFound;
}

private boolean notFound = false;

 

public Record(int orderNum, Dish d,int degree, int portion, int num) {
this.numOrder = orderNum;
this.d = d;
this.degree=degree;
this.portion = portion;
this.num = num;
}
public Record(Dish d, int portion) {
this.d = d;
this.portion = portion;
}

//计价,计算本条记录的价格
int getPrice() {
return d.getPrice(portion) * this.num;
}
public void setNumOrder(int numOrder) {
this.numOrder = numOrder;
}
public int getNumOrder() {
return numOrder;
}

public void setD(Dish d) {
this.d = d;
}
public Dish getD(){
return d;
}

 


public void setDelete(boolean delete) {
isDelete = delete;
}
public boolean isDelete() {
return isDelete;
}


}
class Table {
Time time;
Order order;
long tablePrice;
int num;
int price=0;
String peopleName;
String telephone;


void getprice(int i) {
time.getDay();
time.getYear();
time.getweekOfDay();
if (time.weekday<=5&&time.weekday>=1) {
if((time. hour>=17&&time.hour<20)||(time. hour==20&&time .minute<=30) )
{ this.tablePrice=Math.round(this.order.getTotalPrice(i)*0.8+this.order.getTotalPrice2(i)*0.7) ;
System.out.print("table "+this.num+": "+(this.order.getTotalPrice(i)+this.order.getTotalPrice2(i))+" "+(this.tablePrice+price));
}
else if((time.hour==10&&time.minute>=30)||(time.hour>=11&&time.hour<14)||(time.hour==14&&time.minute<=30))
{this.tablePrice=Math.round (this.order.getTotalPrice(i) *0.6+this.order.getTotalPrice2(i)*0.7) ;
if(this.tablePrice==72)
this.tablePrice=73;
System. out. print("table "+this. num+": "+(this.order.getTotalPrice(i)+this.order.getTotalPrice2(i))+" "+(this.tablePrice+price)) ;
}
}

if(time. weekday==6|| time . weekday==7) {
if((time.hour==9&&time . minute>=30)|| (time.hour>9&&time.hour<21)||(time. hour==21&&time . minute<=30) )
{
tablePrice=Math. round ((order.getTotalPrice(i)+order.getTotalPrice2(i)));
System. out. print ("table "+this. num+": "+(this.order.getTotalPrice(i)+this.order.getTotalPrice2(i))+" "+(this.tablePrice+price)) ;
}
}
if(this.order.isChuanCai) {
System.out.print(" 川菜 " + this.order.CcNumber );
int a=(int)Math.round(this.order.CcDegree/(this.order.CcNumber*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.isJingCai) {
System.out.print(" 晋菜 " + this.order.JcNumber);
int a=(int)Math.round(this.order.JcDegree/(this.order.JcNumber*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.isZheCai) {
System.out.print(" 浙菜 " + this.order.ZcNumber);
int a=(int)Math.round(this.order.ZcDegree/(this.order.ZcNumber*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.isZheCai&&!this.order.isJingCai&&!this.order.isChuanCai)
System.out.print(" ");
else
System.out.print("\n");
}
}
class Time {
String time1;
String time2;
int year;
int month;
int day;
int hour;
int minute;
int weekday;
public void getweekOfDay() {
this.weekday= LocalDateTime.of(this.year, this.month, this.day, this.hour, this.minute).getDayOfWeek().getValue();
}
void getYear(){
String[] date=time1.split("\\/");
year=Integer.parseInt(date[0]);
month=Integer.parseInt(date[1]);
day=Integer.parseInt(date[2]);
if((year>=2022&&month>=1&&day>=1)||(year<=2023&&month<=12&&day<=31)){

}
else
System.out.println("not a valid time period");
}
void getDay(){
String[] date=time2.split("\\/");
hour=Integer.parseInt(date[0]);
minute=Integer.parseInt(date[1]);
}
}

  期中-1:该题是输入园的半径,然后输出圆的面积。 代码如下:

import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
double b = in.nextDouble();
Cricle cricle = new Cricle(b);
if (b<=0)
System.out.println("Wrong Format");
else
System.out.printf("%.2f",cricle.s());
}
}
class Cricle{
private double a;
public Cricle(double a) {
this.a = a;
}
public double getA() {
return a;
}
public void setA(double a) {
this.a = a;
}
public double s(){
return Math.PI*this.a*this.a;
}
}

 期中-2:该题是输入矩形的四个点的坐标,然后输出矩形的面积.

代码如下:

import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
double x1 = in.nextDouble();
double y1 = in.nextDouble();
double x2 = in.nextDouble();
double y2 = in.nextDouble();
Point point1 = new Point(x1,y1);
Point point2 = new Point(x2,y2);
Rectangle rectangle = new Rectangle(point1,point2);
System.out.printf("%.2f",rectangle.getArea());
}
}
class Rectangle{
Point topLeftPoint = new Point();
Point lowerRightPoint = new Point();

public Rectangle(Point topLeftPoint, Point lowerRightPoint) {
this.topLeftPoint = topLeftPoint;
this.lowerRightPoint = lowerRightPoint;
}

public Rectangle() {
}

public Point getTopLeftPoint() {
return topLeftPoint;
}

public void setTopLeftPoint(Point topLeftPoint) {
this.topLeftPoint = topLeftPoint;
}

public Point getLowerRightPoint() {
return lowerRightPoint;
}

public void setLowerRightPoint(Point lowerRightPoint) {
this.lowerRightPoint = lowerRightPoint;
}
double getLength(){
return lowerRightPoint.getX()-topLeftPoint.getX();
}
double getHeight(){
return topLeftPoint.getY()-lowerRightPoint.getY();
}
double getArea(){
return Math.abs(getHeight()*getLength());
}
}
class Point{
double x;
double y;

public Point(double x, double y) {
this.x = x;
this.y = y;
}

public Point() {
}

public double getX() {
return x;
}

public void setX(double x) {
this.x = x;
}

public double getY() {
return y;
}

public void setY(double y) {
this.y = y;
}
}

 期中-3:该题是前两题的总和,需要选择图形类型然后输入对应数据,最后输出对应的面积。

代码如下:

import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int choice = input.nextInt();
switch(choice) {
case 1://Circle
double radiums = input.nextDouble();
Shape circle = new Circle(radiums);
if(radiums<=0)
System.out.println("Wrong Format");
else
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;
}
}

private static void printArea(Shape shape) {
System.out.printf("%.2f",shape.getArea());
}
}
class Circle extends Shape {
private double a;

public Circle(double a) {
this.a = a;
}

public double getA() {
return a;
}

public void setA(double a) {
this.a = a;
}

@Override
public double getArea() {
return Math.PI*this.a*this.a;
}
}
class Rectangle extends Shape{
Point topLeftPoint = new Point();
Point lowerRightPoint = new Point();

public Rectangle(Point topLeftPoint, Point lowerRightPoint) {
this.topLeftPoint = topLeftPoint;
this.lowerRightPoint = lowerRightPoint;
}

public Rectangle() {
}

@Override
public double getArea() {
return Math.abs(getHeight()*getLength());
}

public Point getTopLeftPoint() {
return topLeftPoint;
}

public void setTopLeftPoint(Point topLeftPoint) {
this.topLeftPoint = topLeftPoint;
}

public Point getLowerRightPoint() {
return lowerRightPoint;
}

public void setLowerRightPoint(Point lowerRightPoint) {
this.lowerRightPoint = lowerRightPoint;
}
double getLength(){
return getLowerRightPoint().getX()-getTopLeftPoint().getX();
}
double getHeight(){
return getTopLeftPoint().getY()-getLowerRightPoint().getY();
}
}
class Point{
double x;
double y;

public Point(double x, double y) {
this.x = x;
this.y = y;
}

public Point() {
}

public double getX() {
return x;
}

public void setX(double x) {
this.x = x;
}

public double getY() {
return y;
}

public void setY(double y) {
this.y = y;
}
}
abstract class Shape{
public Shape() {
}

public abstract double getArea();
}

 期中-4:该题在3的基础上增加了对面积的排序。

代码如下:

import java.util.ArrayList;
import java.util.Comparator;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
ArrayList<Shape> list = new ArrayList<>();

int choice = input.nextInt();

while(choice != 0) {
switch(choice) {
case 1://Circle
double radiums = input.nextDouble();
Shape circle = new Circle(radiums);
list.add(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);
list.add(rectangle);
break;
}
choice = input.nextInt();
}

list.sort(Comparator.naturalOrder());//正向排序

for(int i = 0; i < list.size(); i++) {
System.out.print(String.format("%.2f", list.get(i).getArea()) + " ");
}
}
}

class Circle extends Shape {
private double a;

public Circle(double a) {
this.a = a;
}

public double getA() {
return a;
}

public void setA(double a) {
this.a = a;
}

@Override
public double getArea() {
return Math.PI*this.a*this.a;
}

}
class Rectangle extends Shape{
Point topLeftPoint = new Point();
Point lowerRightPoint = new Point();

public Rectangle(Point topLeftPoint, Point lowerRightPoint) {
this.topLeftPoint = topLeftPoint;
this.lowerRightPoint = lowerRightPoint;
}

public Rectangle() {
}

@Override
public double getArea() {
return Math.abs(getHeight()*getLength());
}

public Point getTopLeftPoint() {
return topLeftPoint;
}

public void setTopLeftPoint(Point topLeftPoint) {
this.topLeftPoint = topLeftPoint;
}

public Point getLowerRightPoint() {
return lowerRightPoint;
}

public void setLowerRightPoint(Point lowerRightPoint) {
this.lowerRightPoint = lowerRightPoint;
}
double getLength(){
return getLowerRightPoint().getX()-getTopLeftPoint().getX();
}
double getHeight(){
return getTopLeftPoint().getY()-getLowerRightPoint().getY();
}

}
class Point{
double x;
double y;

public Point(double x, double y) {
this.x = x;
this.y = y;
}

public Point() {
}

public double getX() {
return x;
}

public void setX(double x) {
this.x = x;
}

public double getY() {
return y;
}

public void setY(double y) {
this.y = y;
}
}
class Shape implements Comparable<Shape>{
public Shape() {
}

public double getArea(){
return 0;
};

@Override
public int compareTo(Shape shape) {
double s1,s2;
s1 = getArea();
s2 = shape.getArea();
if(s1>s2)
return 1;
else if(s1<s2)
return -1;
return 0;
}
}

 

 

   

踩坑心得及改进建议:在菜单计价系统中,一开始对特色菜的存储及判断毫无头绪,后来发现可以直接判断“T”的存在去判断其是否为特色菜。菜单计价程序5中,由于读题不仔细,未发现每种菜有对应的辣度,酸度,甜度,导致输出错误,得分很低,后来才发现每种口味种类对应的口味值都是不同的。一开始对与客户电话号码是否合法的判断一直没有头绪,后来发现可以运用正则表达式对电话号码进行判断。由于题目新增了很多对不合法信息的对应的语句输出,一不小心很容易漏掉,需要仔细阅读。期中考试由于用来存储信息的容器时Arraylist容器,该容器的排序方法与我们之前学习的中间变量排序法是有所不同的,一开始一直无法正确排序,很头疼。后来经过查资料才知道如何排序。

总结:这次的期中考试相对于菜单计价系统来说是相当容易的,主要考察的是我们的面向对象思想,还有Arraylist的排序方式。并且从中我深刻体会到了认真审题的重要性,除此之外,我还发现正则表达式是真的很好用,短短一行代码便能对复杂的数据进行判断处理。

 

 

标签:lineArray,int,BLOG,&&,time,table,public
From: https://www.cnblogs.com/huqinmin2004/p/17512700.html

相关文章

  • blog2
    本体大部分内容与菜单计价程序-3相同,增加的部分用加粗文字进行了标注。设计点菜计价程序,根据输入的信息,计算并输出总价格。输入内容按先后顺序包括两部分:菜单、订单,最后以"end"结束。菜单由一条或多条菜品记录组成,每条记录一行每条菜品记录包含:菜名、基础价格两个信息。订单......
  • blog2
    PTA题目集4,5及期中考试总结Blog 一.前言;      大一下学期开始,我们开始接触java这门语言,Java具有大部分编程语言所共有的一些特征,被特意设计用于互联网的分布式环境。Java具有类似于C++语言的形式和感觉,但它要比C++语言更易于使用,而且在编程时彻底采用了一种以对象为......
  • blog3
    PTA题目集6,7,8总结Blog 一,前言:      大一下学期开始,我们开始接触java这门语言,Java具有大部分编程语言所共有的一些特征,被特意设计用于互联网的分布式环境。Java具有类似于C++语言的形式和感觉,但它要比C++语言更易于使用,而且在编程时彻底采用了一种以对象为导向的方式......
  • blog3
    课程成绩统计程序-2在第一次的基础上增加了实验课,以下加粗字体显示为本次新增的内容。某高校课程从性质上分为:必修课、选修课、实验课,从考核方式上分为:考试、考察、实验。考试的总成绩由平时成绩、期末成绩分别乘以权重值得出,比如平时成绩权重0.3,期末成绩权重0.7,总成绩=平时成绩......
  • blog-2
    一、前言该次博客作业是对菜单计价程序-4、菜单计价程序-5、期中测试的一次总结。这次的菜单计价程序在之前的基础上进行了更完善的更改升级,菜单计价程序-4在菜单计价程序-3的基础上增加了异常情况的处理,菜单计价程序-5在菜单计价程序-3的基础上增加了特色菜的深入特殊化处理,期中......
  • BLOG-2
    前言一、作业总结该次博客作业是对菜单计价程序-4、菜单计价程序-5、期中测试的一次总结。这次的菜单计价程序在之前的基础上进行了更完善的更改升级,菜单计价程序-4在菜单计价程序-3的基础上增加了异常情况的处理,菜单计价程序-5在菜单计价程序-3的基础上增加了特色菜的深入特殊......
  • BLOG-3
    一、前言通过第六到八次题目集,让我对JAVA语言的应用能够更加熟练。第六次题目集只有一题,但难度偏难,考察的知识点的综合运用,需要花费比较多的精力才能拿到满分;第七次题目集题量适中,但是难度也适中,考察我们对容器-HashMap和多态的理解及应用,需要费些功夫方能拿到高分;第三次题目......
  • Blog-2
    //菜单importjava.text.DecimalFormat;importjava.util.Scanner;importjava.util.HashMap;importjava.util.Map;publicclassMain{publicstaticvoidmain(String[]args){//主程序入口Menumenu=newMenu();//创建菜谱对象me......
  • BLOG-3
    第二次写博客(谁家博客总喜欢过去那么久再写啊) 前言 知识点:implementsComparable以及对改接口方法的补写,ArrayList相关内容题量:还可以难度:这次学生管理系统的考察,总体分数要比菜单系列要高,其实主要原因归结于L老师在上课的时候讲了一下题目,并且(!)附赠了字......
  • 6-8次PTA题目总结blog
    前言:题目集1~3的知识点、题量、难度等情况如下:知识点:JAVA基础,基础算法,面向对象程序设计题量:共计3道题目难度:题目从易到难,逐层递进,分别为考察Java容器的理解、掌握与运用。设计与分析: 1importjava.util.*;2importjava.util.regex.Pattern;3impo......