首页 > 其他分享 >BLOG-2

BLOG-2

时间:2023-11-19 15:44:40浏览次数:30  
标签:空格 arr get int tableList BLOG table

1、前言

  此次博客主要讲述PTA中的第四次、第五次、第六次以及期中考试的心得体会。其中第四次共有4个题目,包括7-1 菜单计价程序-3,7-2 单词统计与排序,7-3 判断两个日期的先后,计算间隔天数、周数,7-4 菜单计价程序-2。这次作业整体来讲不是太难,下面将分析关于菜单题目的我的思路看法。第五次作业大作业和第六次大作业分别是菜单计价程序-3的两个分支,两个分支之间的关系并不大。下面会分别讲解。期中考试整体来讲难度并不大,有27个选择题和几个编程题,其中选择题大家还是要多去看书或者刷一下学习通的视频,掌握点java的基础知识,编程题说实话不难,但是我有一道题没有写出来,主要原因是,接口那一块还是空缺。会定义但是不太会用。

2、设计与分析

(1)7-4 菜单计价程序-2

设计点菜计价程序,根据输入的信息,计算并输出总价格。

输入内容按先后顺序包括两部分:菜单、订单,最后以"end"结束。

菜单由一条或多条菜品记录组成,每条记录一行

每条菜品记录包含:菜名、基础价格 两个信息。


订单分:点菜记录和删除信息。每一类信息都可包含一条或多条记录,每条记录一行。
点菜记录包含:序号、菜名、份额、份数。
份额可选项包括:1、2、3,分别代表小、中、大份。

删除记录格式:序号 delete

标识删除对应序号的那条点菜记录。

不同份额菜价的计算方法:
小份菜的价格=菜品的基础价格。
中份菜的价格=菜品的基础价格1.5。
小份菜的价格=菜品的基础价格
2。
如果计算出现小数,按四舍五入的规则进行处理。

参考以下类的模板进行设计:
菜品类:对应菜谱上一道菜的信息。

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)//根据序号查找一条记录
}

输入格式:

菜品记录格式:

菜名+英文空格+基础价格

如果有多条相同的菜名的记录,菜品的基础价格以最后一条记录为准。

点菜记录格式:
序号+英文空格+菜名+英文空格+份额+英文空格+份数
注:份额可输入(1/2/3), 1代表小份,2代表中份,3代表大份。

删除记录格式:序号 +英文空格+delete


最后一条记录以“end”结束。

输出格式:

按顺序输出每条订单记录的处理信息,

每条点菜记录输出:序号+英文空格+菜名+英文空格+价格。其中的价格等于对应记录的菜品*份数,序号是之前输入的订单记录的序号。
如果订单中包含不能识别的菜名,则输出“** does not exist”,**是不能识别的菜名

如果删除记录的序号不存在,则输出“delete error”

最后输出订单上所有菜品的总价(整数数值),

本次题目不考虑其他错误情况,如:菜单订单顺序颠倒、不符合格式的输入、序号重复等。

输入样例:

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

麻婆豆腐 12
油淋生菜 9
1 麻婆豆腐 2 2
2 油淋生菜 1 3
end

输出样例:

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

1 麻婆豆腐 36
2 油淋生菜 27
63

输入样例1:

订单中包含删除记录。例如:

麻婆豆腐 12
油淋生菜 9
1 麻婆豆腐 2 2
2 油淋生菜 1 3
1 delete
end

输出样例1:

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

1 麻婆豆腐 36
2 油淋生菜 27
27

输入样例2:

订单中包含不存在的菜品记录。例如:

麻婆豆腐 12
油淋生菜 9
1 麻婆豆腐 2 2
2 油淋生菜 1 3
3 麻辣鸡丝 1 2
end

输出样例2:

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

1 麻婆豆腐 36
2 油淋生菜 27
麻辣鸡丝 does not exist
63

输入样例3:

订单中包含删除信息以及不存在的菜品记录。例如:

麻婆豆腐 12
油淋生菜 9
1 麻婆豆腐 2 2
2 油淋生菜 1 3
3 麻辣鸡丝 1 2
1 delete
7 delete
end

输出样例3:

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

1 麻婆豆腐 36
2 油淋生菜 27
麻辣鸡丝 does not exist
delete error;
27

输入样例4:

订单中包含删除信息以及不存在的菜品记录。例如:

麻婆豆腐 12
油淋生菜 9
1 麻婆豆腐 2 2
2 油淋生菜 1 3
3 麻辣鸡丝 1 2
5 delete
7 delete
end

输出样例4:

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

1 麻婆豆腐 36
2 油淋生菜 27
麻辣鸡丝 does not exist
delete error;
delete error;
63

源码:

import java.util.Scanner;
import java.util.ArrayList;
public class Main {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        String line = input.nextLine();
        Menu menu = new Menu();
        Order order = new Order();
        while(!line.equals("end")) {
            String[] arr = line.split(" ");
            if(judgeInput(line) == 1)
            {
                String dishName = arr[0];
                int unit_price = Integer.parseInt(arr[1]);
                //if(menu.searthDish(dishName) == null) {
                    menu.addDish(dishName, unit_price);
                //}
            }
            /*for(int i = 0;i < menu.dishs.size();i++) {
                System.out.println(menu.dishs.get(i).getName());
            }*/
            if(judgeInput(line) == 2) {
                int orderNum = Integer.parseInt(arr[0]);
                String dishName = arr[1];
                int portion = Integer.parseInt(arr[2]);
                int copies = Integer.parseInt(arr[3]);
                if(menu.searthDish(dishName) != null) {
                    order.addARecord(orderNum, dishName, portion, copies,menu);
                }
                else {
                    System.out.println(dishName +" does not exist");
                }
            }
            if(judgeInput(line) == 3) {
                int orderNum = Integer.parseInt(arr[0]);
                order.delARecordByOrderNum(orderNum);
                
            }
            
            line = input.nextLine();
        }
        int totalPrice = order.getTotalPrice(); 
        System.out.println(totalPrice); 
    }
    
    
    
    //正则表达式
    public static int judgeInput(String line) {
        if(line.matches("[\u4e00-\u9fa5]+ [1-9]?[0-9]")) {
            return 1;
        }
        if(line.matches("[1-9]?[0-9] [\\u4e00-\\u9fa5]+ (1|2|3) [1-9]{1}")){
            return 2;
        }
        if(line.matches("[1-9]{1} delete")){
            return 3;
        }
        return 0;
    }

}
class Dish {
    private String name;
    private int unit_price;
    
    public Dish() {
    }
    public Dish(String name,int unit_price) {
        this.name = name;
        this.unit_price = unit_price;
    }
    
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getUnit_price() {
        return unit_price;
    }
    public void setUnit_price(int unit_price) {
        this.unit_price = unit_price;
    }
    //计算菜品价格的方法,输入参数是点菜的份额(输入数据只能是1/2/3,代表小/中/大份)
    public int getPrice(int portion) {
        if(portion == 1) {
            return unit_price;
        }
        if(portion == 2) {
            return (int) Math.round(1.5 * unit_price);
        }
        if(portion == 3) {
            return unit_price * 2;
        }
        return 0;
    }
}
class Menu {
    ArrayList<Dish> dishs = new ArrayList<>();
    
    //根据菜名在菜谱中查找菜品信息,返回Dish对象
    public Dish searthDish(String dishName) {
        for(int i = 0;i < dishs.size();i++) {
            if(dishs.get(i).getName().equals(dishName)) {
                return dishs.get(i);
            }
        }
        return null;
    }
    
    //添加一道菜品信息
    public Dish addDish(String dishName,int unit_price) {
        Dish dish = new Dish(dishName,unit_price);
        if(searthDish(dishName) == null) {
            dishs.add(dish);
            return dish;
        }
        else {
            int index = getIndex(dishName);
            dishs.set(index, dish);
            return dish;
        }
        
    }
    //获取下表
    public int getIndex(String dishName) {
        for(int i = 0;i < dishs.size();i++) {
            if(dishs.get(i).getName().equals(dishName)) {
                return i;
            }
        }
        return -1;
    }
    
}

class Record {
    private int orderNum;
    private Dish d;
    private int portion;
    private int copies;
    int flag = 0;
    public Record() {
    }
    public Record(int orderNum,Dish d,int portion,int copies) {
        this.orderNum = orderNum;
        this.d = d;
        this.portion = portion;
        this.copies = copies;
    }
    
    public int getOrderNum() {
        return orderNum;
    }
    public void setOrderNum(int orderNum) {
        this.orderNum = orderNum;
    }
    public Dish getD() {
        return d;
    }
    public void setD(Dish d) {
        this.d = d;
    }
    public int getPortion() {
        return portion;
    }
    public void setPortion(int portion) {
        this.portion = portion;
    }
    
    public int getCopies() {
        return copies;
    }
    public void setCopies(int copies) {
        this.copies = copies;
    }
    //计价,计算本条记录的价格
    public int getPrice() {
        return d.getPrice(portion) * copies;
    }
    
}
class Order {
    ArrayList<Record> orderList = new ArrayList<>();
    //计算订单的总价
    int sum = 0;
    int money = 0;
    public int getTotalPrice() {
        for(int i = 0;i < orderList.size();i++) {
            money = orderList.get(i).getPrice();
            if(orderList.get(i).flag != 1) {
                sum += orderList.get(i).getPrice();
            }
            //System.out.println(orderList.get(i).getOrderNum() + " " + orderList.get(i).getD().getName() 
                    //+ " " + orderList.get(i).getPrice());
        }
        return sum;
    }
    //添加一条菜品信息到订单中
    public Record addARecord(int orderNum,String dishName,int portion,int copies,Menu menu) {
        if(menu.searthDish(dishName) != null) {
            Dish dish = new Dish(dishName,menu.searthDish(dishName).getUnit_price());
            Record record = new Record(orderNum,dish,portion,copies);
            orderList.add(record);
            System.out.println(orderNum + " " + dishName + " " + record.getPrice());
            return record;
        }
        else {
            System.out.println(dishName +" does not exist");
            return null;
        }
    }
    //根据序号删除一条记录
    public void delARecordByOrderNum(int orderNum){
        int index = findRecordByNum(orderNum);
        if(index != -1) {
            //orderList.remove(index);
            orderList.get(index).flag = 1;
        }
        else {
            System.out.println("delete error;");
        }
    }
    //根据序号查找一条记录
    public int findRecordByNum(int orderNum) {
        for(int i = 0; i < orderList.size();i++) {
            if(orderList.get(i).getOrderNum() == orderNum) {
                return i;
            }
        }
        return -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)//根据序号查找一条记录

}

### 输入格式:

桌号标识格式: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+英文空格+桌号+“:”+英文空格+当前桌的总价

本次题目不考虑其他错误情况,如:桌号、菜单订单顺序颠倒、不符合格式的输入、序号重复等,在本系列的后续作业中会做要求。

输入格式:

桌号标识格式: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
table 1 2023/3/22 12/2/3
1 麻婆豆腐 2 2
2 油淋生菜 1 3
end

输出样例:

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

table 1: 
1 麻婆豆腐 36
2 油淋生菜 27
table 1: 38

输入样例1:

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

麻婆豆腐 12
油淋生菜 9
table 1 2023/3/22 17/0/0
1 麻婆豆腐 2 2
2 油淋生菜 1 3
1 delete
end

输出样例1:

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

table 1: 
1 麻婆豆腐 36
2 油淋生菜 27
table 1: 22

输入样例2:

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

麻婆豆腐 12
油淋生菜 9
table 1 2023/3/22 16/59/59
1 麻婆豆腐 2 2
2 油淋生菜 1 3
1 delete
end

输出样例2:

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

table 1: 
1 麻婆豆腐 36
2 油淋生菜 27
table 1 out of opening hours

输入样例3:

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

麻婆豆腐 12
油淋生菜 9
table 1 2022/12/5 15/03/02
1 麻婆豆腐 2 2
2 油淋生菜 1 3
3 麻辣鸡丝 1 2
5 delete
7 delete
table 2 2022/12/3 15/03/02
1 麻婆豆腐 2 2
2 油淋生菜 1 3
3 麻辣鸡丝 1 2
7 delete
end

输出样例3:

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

table 1: 
1 麻婆豆腐 36
2 油淋生菜 27
麻辣鸡丝 does not exist
delete error;
delete error;
table 2: 
1 麻婆豆腐 36
2 油淋生菜 27
麻辣鸡丝 does not exist
delete error;
table 1 out of opening hours
table 2: 63

输入样例4:

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

麻婆豆腐 12
油淋生菜 9
table 1 2022/12/3 19/5/12
1 麻婆豆腐 2 2
2 油淋生菜 1 3
3 麻辣鸡丝 1 2
table 2 2022/12/3 15/03/02
1 麻婆豆腐 2 2
2 油淋生菜 1 3
3 麻辣鸡丝 1 2
1 4 麻婆豆腐 1 1
7 delete
end

输出样例4:

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

table 1: 
1 麻婆豆腐 36
2 油淋生菜 27
麻辣鸡丝 does not exist
table 2: 
1 麻婆豆腐 36
2 油淋生菜 27
麻辣鸡丝 does not exist
4 table 2 pay for table 1 12
delete error;
table 1: 63
table 2: 75

源码:
import java.text.ParseException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws ParseException {
        Scanner input = new Scanner(System.in);
        String line = input.nextLine();
        Menu menu = new Menu();
        //Order order = new Order();
        ArrayList<Table> tableList = new ArrayList<>();    
        int length_List = 0;
        while(!line.equals("end")) {
            String[] arr = line.split(" ");
            if(judgeInput(line) == 1)
            {
                //String dishName = arr[0];
                int unit_price = Integer.parseInt(arr[1]);
                menu.addDish(arr[0], unit_price);
            }
            //桌子
            if(judgeInput(line) == 4) {                
                 int tableNum = Integer.parseInt(arr[1]);
                 String date = arr[2] + " " + arr[3];
                 Table table = new Table(tableNum,date);
                 tableList.add(table);
                 length_List++;
                 System.out.println("table " + tableNum + ": ");
            }
            if(judgeInput(line) == 2) {
                int orderNum = Integer.parseInt(arr[0]);
                //String dishName = arr[1];
                int portion = Integer.parseInt(arr[2]);
                int copies = Integer.parseInt(arr[3]);
                if(menu.searthDish(arr[1]) != null) {
                    tableList.get(length_List-1).addARecord(orderNum, arr[1], portion, copies, menu,0,length_List);
                }
                else {
                    System.out.println(arr[1] +" does not exist");
                }
            }
            if(judgeInput(line) == 5) {
                int a = Integer.parseInt(arr[0]);
                int orderNum = Integer.parseInt(arr[1]);
                //String dishName = arr[2];
                int portion = Integer.parseInt(arr[3]);
                int copies = Integer.parseInt(arr[4]);
                if(menu.searthDish(arr[2]) != null) {
                    tableList.get(length_List-1).addARecord(orderNum, arr[2], portion, copies, menu,a,length_List);
                }
                else {
                    System.out.println(arr[2] +" does not exist");
                }
                //int orderLen = tableList.get(length_List-1).orderList.size();
                //tableList.get(length_List-1).orderList.get(orderLen-1).flagdaidian = a;
            }
            if(judgeInput(line) == 3) {
                
                int orderNum = Integer.parseInt(arr[0]);
                tableList.get(length_List-1).delARecordByOrderNum(orderNum);
                
            }
            
            line = input.nextLine();
        }
        for(int i = 0; i < tableList.size();i++) {
            for(int j = 0;j < tableList.get(i).orderList.size();j++) {
    
            }
        }
        for(int i = 0;i < tableList.size();i++) {
            int totalPrice = tableList.get(i).getTotalPrice(judgeDate(tableList.get(i).getDate()));
            
            if(judgeDate(tableList.get(i).getDate()) == 0) {
                System.out.println("table " + tableList.get(i).getTableNum() + " out of opening hours"); 
            }
            else {
                System.out.println("table " + tableList.get(i).getTableNum() + ": " + totalPrice); 
            }
        }
 
    }
    //正则表达式
    public static int judgeInput(String line) {
        if(line.matches("[\u4e00-\u9fa5]+ [1-9]?[0-9]")) {
            return 1;
        }
        if(line.matches("[1-9]?[0-9] [\\u4e00-\\u9fa5]+ (1|2|3) [1-9]{1}")){
            return 2;
        }
        if(line.matches("[1-9]{1} delete")){
            return 3;
        }
        if(line.matches("table.*")) {
            return 4;
        }
        if(line.matches("[1-9] [0-9]?[1-9] \\S{1,20} [1-3] [1-9]")) {
            return 5;
        }
        return 0;
    }
    
    //判断日期是否在经营范围内
    public static float judgeDate(String date) throws ParseException {
        String[] dateArr = date.split(" ");
       
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/M/d"); 
        LocalDate localDate = LocalDate.parse(dateArr[0], formatter);
        String[] timeArr = dateArr[1].split("/");
        int h = Integer.parseInt(timeArr[0]);
        int f = Integer.parseInt(timeArr[1]);
        int day = localDate.getDayOfWeek().getValue();
        if(day == 6||day == 7) {
            if(!((h >= 10&&h < 21)||(h == 9&&f >= 30)||(h == 21&&f <= 30))) {
                return 0;
            }
            else {
                return 1;
            }
        }
        else {
            if((h >= 11&&h < 14)||(h == 10&&f >= 30)||(h == 14&&f <= 30)) {
                return (float) 0.6;
            }
            else if((h >= 17&&h < 20)||(h == 20&&f <= 30)){
                return (float) 0.8;
            }else {
                return 0;
            }
    
        }
    }

}
class Dish {
    private String name;
    private int unit_price;
    
    public Dish() {
    }
    public Dish(String name,int unit_price) {
        this.name = name;
        this.unit_price = unit_price;
    }
    
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getUnit_price() {
        return unit_price;
    }
    public void setUnit_price(int unit_price) {
        this.unit_price = unit_price;
    }
    //计算菜品价格的方法,输入参数是点菜的份额(输入数据只能是1/2/3,代表小/中/大份)
    public int getPrice(int portion) {
        if(portion == 1) {
            return unit_price;
        }
        if(portion == 2) {
            return (int) Math.round(1.5 * unit_price);
        }
        if(portion == 3) {
            return unit_price * 2;
        }
        return 0;
    }
}
class Menu {
    ArrayList<Dish> dishs = new ArrayList<>();
    
    //根据菜名在菜谱中查找菜品信息,返回Dish对象
    public Dish searthDish(String dishName) {
        for(int i = 0;i < dishs.size();i++) {
            if(dishs.get(i).getName().equals(dishName)) {
                return dishs.get(i);
            }
        }
        return null;
    }
    
    //添加一道菜品信息
    public Dish addDish(String dishName,int unit_price) {
        Dish dish = new Dish(dishName,unit_price);
        if(searthDish(dishName) == null) {
            dishs.add(dish);
            return dish;
        }
        else {
            int index = getIndex(dishName);
            dishs.set(index, dish);
            return dish;
        }
        
    }
    //获取下表
    public int getIndex(String dishName) {
        for(int i = 0;i < dishs.size();i++) {
            if(dishs.get(i).getName().equals(dishName)) {
                return i;
            }
        }
        return -1;
    }
}
class Order {
    ArrayList<Record> orderList = new ArrayList<>();
    //计算订单的总价
    int sum = 0;
    int money = 0;
    public int getTotalPrice(float zhekou) {
        if(zhekou != 0) {
            for(int i = 0;i < orderList.size();i++) {
                money = orderList.get(i).getPrice();
                //System.out.println(money);
                if(orderList.get(i).flag != 1) {
                    sum += orderList.get(i).getPrice();
                    //System.out.println(sum);
                }
            }
            return Math.round(sum * zhekou);
        }
        return 0;
    }
    //添加一条菜品信息到订单中
    public void addARecord(int orderNum,String dishName,int portion,int copies,Menu menu,int flagdaidian,int length_List) {
        if(menu.searthDish(dishName) != null) {
            Dish dish = new Dish(dishName,menu.searthDish(dishName).getUnit_price());
            Record record = new Record(orderNum,dish,portion,copies);
            orderList.add(record);
            if(flagdaidian == 0) {
                System.out.println(orderNum + " " + dishName + " " + record.getPrice());
            }
            else {
                System.out.println(orderNum + " table " + length_List + " pay for table " + flagdaidian + " " + record.getPrice());
            }
        }
        else {
            System.out.println(dishName +" does not exist");
        }
    }
    
    //根据序号删除一条记录
    public void delARecordByOrderNum(int orderNum){
        int index = findRecordByNum(orderNum);
        if(index != -1) {
            //orderList.remove(index);
            orderList.get(index).flag = 1;
        }
        else {
            System.out.println("delete error;");
        }
    }
    //根据序号查找一条记录
    public int findRecordByNum(int orderNum) {
        for(int i = 0; i < orderList.size();i++) {
            if(orderList.get(i).getOrderNum() == orderNum) {
                return i;
            }
        }
        return -1;
    }
    
    
    
    
    
    
}
class Record {
    private int orderNum;
    private Dish d;
    private int portion;
    private int copies;
    int flag = 0;//标志删除信息
    int flagdaidian = 0;//标志代点信息
    
    public Record() {
    }
    public Record(int orderNum,Dish d,int portion,int copies) {
        this.orderNum = orderNum;
        this.d = d;
        this.portion = portion;
        this.copies = copies;
    }
    
    public int getOrderNum() {
        return orderNum;
    }
    public void setOrderNum(int orderNum) {
        this.orderNum = orderNum;
    }
    public Dish getD() {
        return d;
    }
    public void setD(Dish d) {
        this.d = d;
    }
    public int getPortion() {
        return portion;
    }
    public void setPortion(int portion) {
        this.portion = portion;
    }
    
    public int getCopies() {
        return copies;
    }
    public void setCopies(int copies) {
        this.copies = copies;
    }
    //计价,计算本条记录的价格
    public int getPrice() {
        return d.getPrice(portion) * copies;
    }
    
}
class Table extends Order{
    private int tableNum;
    private String date;
    
    public Table() {
        
    }
    public Table(int tableNum,String date) {
        this.tableNum = tableNum;
        this.date = date;
    }
    
    public String getDate() {
        return date;
    }
    public void setDate(String date) {
        this.date = date;
    }
    public int getTableNum() {
        return tableNum;
    }
    public void setTableNum(int tableNum) {
        this.tableNum = tableNum;
    }
    
}

类图:

部分时序图:

 

 心得体会:

这道题目新增了一个桌子的概念,我的思路是让Table类继承Order类,其中Table多了两个属性,其中一个是tableNum和date一个是桌号一个是日期,对我来说,这道题目的难点是对与日期的处理,我的处理就很粗暴。

//判断日期是否在经营范围内
    public static float judgeDate(String date) throws ParseException {
        String[] dateArr = date.split(" ");
       
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/M/d"); 
        LocalDate localDate = LocalDate.parse(dateArr[0], formatter);
        String[] timeArr = dateArr[1].split("/");
        int h = Integer.parseInt(timeArr[0]);
        int f = Integer.parseInt(timeArr[1]);
        int day = localDate.getDayOfWeek().getValue();
        if(day == 6||day == 7) {
            if(!((h >= 10&&h < 21)||(h == 9&&f >= 30)||(h == 21&&f <= 30))) {
                return 0;
            }
            else {
                return 1;
            }
        }
        else {
            if((h >= 11&&h < 14)||(h == 10&&f >= 30)||(h == 14&&f <= 30)) {
                return (float) 0.6;
            }
            else if((h >= 17&&h < 20)||(h == 20&&f <= 30)){
                return (float) 0.8;
            }else {
                return 0;
            }
    
        }
    }

我在main函数中定义了一个judgeDate(String date)的方法,直接分割字符串,将获得的年月日与经营时间相比较,判断是否在经营范围,其中返回值就是当前时间的折扣,如果为0就是不在营业范围。

(3)菜单计价程序-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)//根据序号查找一条记录

}

本次课题比菜单计价系列-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

源码:
import java.text.ParseException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws ParseException {
        Scanner input = new Scanner(System.in);
        String line = input.nextLine();
        Menu menu = new Menu();
        //Order order = new Order();
        ArrayList<Table> tableList = new ArrayList<>();    
        int length_List = 0;
        int time = 1;
        int tcankao = 0;

        boolean bool = true;
        boolean cankao = true;
        while(!line.equals("end")) {
            String[] arr = line.split(" ");
            if(judgeInput(line) == 1)
            {
                if(length_List != 0)
                {
                    System.out.println("invalid dish");
                    line = input.nextLine();
                    continue;
                }                
                int unit_price = Integer.parseInt(arr[1]);
                if (unit_price > 300||unit_price < 0) {
                    System.out.println(arr[0] + " price out of range " + unit_price);
                    line = input.nextLine();
                    continue;
                }
                menu.addDish(arr[0], unit_price,false);
            }
            if(judgeInput(line) == 6&&bool)
            {
                if(length_List != 0)
                {
                    System.out.println("invalid dish");
                    line = input.nextLine();
                    continue;
                }
                //String dishName = arr[0];
                int unit_price = Integer.parseInt(arr[1]);
                if (unit_price > 300||unit_price < 0) {
                    System.out.println(arr[0] + " price out of range " + unit_price);
                    line = input.nextLine();
                    continue;
                }
                menu.addDish(arr[0],unit_price,true);
            }
            //桌子
            if(judgeInput(line) == 4) {                
                 int tableNum = Integer.parseInt(arr[1]);
                 String date = arr[2] + " " + arr[3];
                 String[] dateArr = arr[2].split("/"); 
                 String[] dateArr2 = arr[3].split("/"); 
                 if(dateArr[1].length() > 2||dateArr[2].length() > 2||dateArr2[0].length() > 2||dateArr2[1].length() > 2||dateArr2[2].length() > 2)
                 {
                     System.out.println("wrong format"); 
                     break;
                 }
                 int year = Integer.parseInt(dateArr[0]);
                 int month = Integer.parseInt(dateArr[1]);
                 int day = Integer.parseInt(dateArr[2]);
                 if(judgeLegalDate(year,month,day)){
                     
                 
                 float a = judgeDate(date);
                 
                 int chazhi = 0;
        
                 if(tableNum < 1&&tableNum > 55) {
                     System.out.println( tableNum + "table num out of range");
                 }
                 else {
                     
                 
        //------------------------------------------------------------------------         
                 if(tableNum >= 1&&tableNum <= 55&& a != 0) {
                     
                     if(year == 2022||year ==2023) {
                         try {
                             if(judgeLegalDate(year,month,day)) {
                                 Table table = new Table(tableNum,date);
                                 
                                 //System.out.println(tableList.size());
                                 if(judgeTable(tableNum,tableList)) {
                                     boolean sameDay = arr[2].equals(tableList.get(length_List-1).getDate().split(" ")[0]);
                                     float b = judgeDate(tableList.get(length_List-1).getDate());
                                     if(b == 1&&a == 1&&sameDay) {                                     
                                         int h1 = Integer.parseInt(arr[3].split("/")[0]);
                                         int f1 = Integer.parseInt(arr[3].split("/")[1]);
                                         int s1 = Integer.parseInt(arr[3].split("/")[2]);
                                         int total1 = h1 * 3600 + f1 * 60 + s1;
                                         int h2 = Integer.parseInt(tableList.get(length_List-1).getDate().split(" ")[1].split("/")[0]);
                                         int f2 = Integer.parseInt(tableList.get(length_List-1).getDate().split(" ")[1].split("/")[1]);
                                         int s2 = Integer.parseInt(tableList.get(length_List-1).getDate().split(" ")[1].split("/")[2]);
                                         int total2 = h2 * 3600 + f2 * 60 + s2;
                                         chazhi = Math.abs(total1 - total2) >= 3600 ? 1:2;
                                         if(chazhi == 1) {
                                             tableList.get(length_List-1).repect = 0;
                                         }
                                         else {
                                             tableList.get(length_List-1).repect = 1;
                                         }
                                     }
                                     else if((sameDay && a != b)||!sameDay) {
                                         tableList.get(length_List-1).repect = 0;
                                     }
                                     else {
                                         tableList.get(length_List-1).repect = 1;
                                     }
                                 }

                                 tableList.add(table);
                                 length_List++;
                                 System.out.println("table " + tableNum + ": ");
                                 bool = true;
                                 cankao = true;
                                 tcankao = 0;
                             }
                             else {
                                 
                                 System.out.println(tableNum + " " + "date error");
                                 bool = false;
                                 
                                 //break; 
                                 line = input.nextLine();
                                 continue;
                                 
                             } 
                         }catch(ArrayIndexOutOfBoundsException e) {                            
                             System.out.println(tableNum + " date error");
                             break; 
                         }
                     }
                     else {
                         System.out.println("not a valid time period");
                         bool = false;
                         line = input.nextLine();
                         continue;    
                     }
                 }
                 else {
                     if(a != 0) {
                         if(tableNum > 55) {
                             System.out.println(tableNum + " table num out of range");
                         }
                         else {
                             System.out.println("wrong format");
                         }
                     }
                     else {
                         System.out.println("table " + tableNum + " out of opening hours"); 
                     }
                     
                     bool = false;
                     cankao = false;
                 }
                }
                 }
                 else {
                     System.out.println(tableNum + " " + "date error");
                     bool = false;
                     
                     //break; 
                     line = input.nextLine();
                     continue; 
                 }
            }
            
            if(judgeInput(line) == 2&&length_List != 0&&bool&&cankao) {
                int orderNum = Integer.parseInt(arr[0]);
                int portion = Integer.parseInt(arr[2]);
                int copies = Integer.parseInt(arr[3]);
                String dishName = arr[1];
                if(menu.searthDish(dishName) != null) {
                    if((portion == 1||portion == 2 ||portion == 3) && copies <= 15) {                                
                        if(orderNum > tcankao) {
                            tableList.get(length_List-1).addARecord(orderNum, dishName, portion, copies, menu,0,length_List);
                            tcankao = orderNum;
                        }
                        else {
                            System.out.println("record serial number sequence error");
                        }    
                    }
                    else if(!(portion == 1||portion == 2 ||portion == 3)){
                        System.out.println(orderNum + " portion out of range " + portion);
                    }
                    else {
                        System.out.println(orderNum + " num out of range " + copies);
                    }
                }
                else {
                    System.out.println(dishName +" does not exist");
                }            
            }
            if(judgeInput(line) == 5&&cankao) {
                int a = Integer.parseInt(arr[0]);
                /*if(judgeTable(a,tableList))
                {
                    int orderNum = Integer.parseInt(arr[1]);
                    String dishName = arr[2];
                    int portion = Integer.parseInt(arr[3]);
                    int copies = Integer.parseInt(arr[4]);
                    if(menu.searthDish(dishName) != null) {
                        tableList.get(length_List-1).addARecord(orderNum, dishName, portion, copies, menu,a,length_List);
                    }
                    else {
                        System.out.println(dishName +" does not exist");
                    }
                    int orderLen = tableList.get(length_List-1).orderList.size();
                    tableList.get(length_List-1).orderList.get(orderLen-1).flagdaidian = a;
                }
                else {
                    System.out.println("Table number :" + a + " does not exist");
                }*/
                System.out.println("Table number :" + a + " does not exist");
            }
            if(judgeInput(line) == 3&&bool&&cankao) {
                
                int orderNum = Integer.parseInt(arr[0]);
                tableList.get(length_List-1).delARecordByOrderNum(orderNum);
                
            }
            if(judgeInput(line) == 0) {    
                if(time == 1) {
                    System.out.println("wrong format");
                    time = 0;
                }
                if(arr[0].equals("table")) {
                    cankao = false;
                }
            }
            
            line = input.nextLine();
        }
        int totalPrice = 0;
        int total =0;
        for(int i = 0;i < tableList.size();i++) {
            totalPrice += tableList.get(i).getTotalPrice(judgeDate(tableList.get(i).getDate()));
            total += tableList.get(i).getTotal();
            if(judgeDate(tableList.get(i).getDate()) == 0) {
                System.out.println("table " + tableList.get(i).getTableNum() + " out of opening hours"); 
                totalPrice = 0;
                total =0;
            }
            else if( tableList.get(i).repect == 1){
                continue;
                
            }
            else {
                System.out.println("table " + tableList.get(i).getTableNum() + ": " + total + " " +totalPrice); 
                totalPrice = 0;
                total =0;
            }
        }
 
    }
    
    //判断代点桌号是否存在
    public static boolean judgeTable(int num,ArrayList<Table> tableList) {
        for(int i = 0;i < tableList.size();i++) {
            if(tableList.get(i).getTableNum() == num) {
                return true;
            }
        }
        return false;
    }
    
    //正则表达式
    public static int judgeInput(String line) {
        if(line.matches("[\u4e00-\u9fa5]+ [1-9]+[0-9]*")) {
            return 1;
        }
        if(line.matches("[1-9]+[0-9]* [\\u4e00-\\u9fa5]+ [1-9]+[0-9]* [1-9]+[0-9]*")){
            return 2;
        }
        if(line.matches("[1-9]{1} delete")){
            return 3;
        }
        if(line.matches("table \\d+ \\d+/\\d+/\\d+ \\d+/\\d+/\\d+")) {
            return 4;
        }
        if(line.matches("[1-9]+[0-9]* [0-9]?[1-9] \\S{1,20} [1-9]+[0-9]* [1-9]+[0-9]*")) {
            return 5;
        }
        if(line.matches("[\u4e00-\u9fa5]+ [0-9]* T")) {
            return 6;
        }
        return 0;
    }
    
    //判断日期是否在经营范围内
    public static float judgeDate(String date) throws ParseException {
        String[] dateArr = date.split(" ");
        //String date1 = "2022/1/1";
        //String date2 = "2023/12/31";
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/M/d"); 
        LocalDate localDate = LocalDate.parse(dateArr[0], formatter);
        //LocalDate localDate1 = LocalDate.parse(date1, formatter);
        //LocalDate localDate2 = LocalDate.parse(date2, formatter);
        
        String[] timeArr = dateArr[1].split("/");
        int h = Integer.parseInt(timeArr[0]);
        int f = Integer.parseInt(timeArr[1]);
        int day = localDate.getDayOfWeek().getValue();
        if(day == 6||day == 7) {
            if(!((h >= 10&&h < 21)||(h == 9&&f >= 30)||(h == 21&&f <= 30))) {
                return 0;
            }
            else {
                return 1;
            }
        }
        else {
            if((h >= 11&&h < 14)||(h == 10&&f >= 30)||(h == 14&&f <= 30)) {
                return (float) 0.6;
            }
            else if((h >= 17&&h < 20)||(h == 20&&f <= 30)){
                return (float) 0.8;
            }else {
                return 0;
            }
    
        }
    }
    
    public static boolean judgeLegalDate(int year,int month,int day) {
        int[] days = {31,28,31,30,31,30,31,31,30,31,30,31};
        if(month >= 1||month <= 12) {
            if((year % 100 == 0 && year % 400 == 0) || (year % 4 == 0 && year % 100 != 0)) {
                if(month == 2&&day <= 29) {
                    return true;
                }
                else if(day <= days[month - 1]) {
                    return true;
                }
            }
            else if(day <= days[month - 1]){
                return true;
            }
        }
        return false;
    }

}
class Dish {
    private String name;
    private int unit_price;
    private boolean isT;
    public Dish() {
    }
    public Dish(String name,int unit_price) {
        this.name = name;
        this.unit_price = unit_price;
    }
    
    public boolean isT() {
        return isT;
    }
    public void setT(boolean isT) {
        this.isT = isT;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getUnit_price() {
        return unit_price;
    }
    public void setUnit_price(int unit_price) {
        this.unit_price = unit_price;
    }
    //计算菜品价格的方法,输入参数是点菜的份额(输入数据只能是1/2/3,代表小/中/大份)
    public int getPrice(int portion) {
        if(portion == 1) {
            return unit_price;
        }
        if(portion == 2) {
            return (int) Math.round(1.5 * unit_price);
        }
        if(portion == 3) {
            return unit_price * 2;
        }
        return 0;
    }
}

class Table extends Order{
    private int tableNum;
    private String date;
    int repect = 0;
    
    public Table() {
        
    }
    public Table(int tableNum,String date) {
        this.tableNum = tableNum;
        this.date = date;
    }
    
    public String getDate() {
        return date;
    }
    public void setDate(String date) {
        this.date = date;
    }
    public int getTableNum() {
        return tableNum;
    }
    public void setTableNum(int tableNum) {
        this.tableNum = tableNum;
    }
    
}
class Menu {
    ArrayList<Dish> dishs = new ArrayList<>();
    
    //根据菜名在菜谱中查找菜品信息,返回Dish对象
    public Dish searthDish(String dishName) {
        for(int i = 0;i < dishs.size();i++) {
            if(dishs.get(i).getName().equals(dishName)) {
                return dishs.get(i);
            }
        }
        return null;
    }
    
    //添加一道菜品信息
    public Dish addDish(String dishName,int unit_price,boolean isT) {
        Dish dish = new Dish(dishName,unit_price);
        dish.setT(isT);
        if(searthDish(dishName) == null) {
            dishs.add(dish);
            return dish;
        }
        else {
            int index = getIndex(dishName);
            dishs.set(index, dish);
            return dish;
        }
        
    }
    //获取下表
    public int getIndex(String dishName) {
        for(int i = 0;i < dishs.size();i++) {
            if(dishs.get(i).getName().equals(dishName)) {
                return i;
            }
        }
        return -1;
    }
}
class Order {
    ArrayList<Record> orderList = new ArrayList<>();
    //计算订单的总价
    int sum = 0;
    int tMoney = 0;
    public int getTotalPrice(float zhekou) {
        if(zhekou != 0) {
            //System.out.println(orderList.size());
            for(int i = 0;i < orderList.size();i++) {
                if(orderList.get(i).getD().isT() && orderList.get(i).flag != 1) {
                    tMoney += orderList.get(i).getPrice();                
                }
                if(!orderList.get(i).getD().isT() && orderList.get(i).flag != 1) {
                    sum += orderList.get(i).getPrice();
                }
            }
            if(zhekou == 1) {
                return Math.round((sum + tMoney) * zhekou);
            }
            else {
                return (int) (Math.round(sum * zhekou) + Math.round(tMoney * 0.7));
            }
        }
        return 0;
    }
    
    int total = 0;
    public int getTotal() {
        for(int i = 0;i < orderList.size();i++) {
            //money = orderList.get(i).getPrice();
            //System.out.println(money);
            if(orderList.get(i).flag != 1) {
                total += orderList.get(i).getPrice();
                //System.out.println(sum);
            }
        }
        return total;
    }
    //添加一条菜品信息到订单中
    public void addARecord(int orderNum,String dishName,int portion,int copies,Menu menu,int flagdaidian,int length_List) {
        if(menu.searthDish(dishName) != null) {            
            Dish dish = new Dish(dishName,menu.searthDish(dishName).getUnit_price());
            dish.setT(menu.searthDish(dishName).isT());
            Record record = new Record(orderNum,dish,portion,copies);
            orderList.add(record);
            if(flagdaidian == 0) {
                System.out.println(orderNum + " " + dishName + " " + record.getPrice());
            }
            else {
                System.out.println(orderNum + " table " + length_List + " pay for table " + flagdaidian + " " + record.getPrice());
            }
        }
        else {
            System.out.println(dishName +" does not exist");
        }
    }
    
    //根据序号删除一条记录
    public void delARecordByOrderNum(int orderNum){
        int index = findRecordByNum(orderNum);
        if(index != -1) {
            //orderList.remove(index);
            if(orderList.get(index).flag == 1){
                System.out.println("deduplication " + orderNum);
            }
            else {
                orderList.get(index).flag = 1;
            }
            orderList.get(index).flag = 1;
        }
        else {
            System.out.println("delete error;");
        }
    }
    //根据序号查找一条记录
    public int findRecordByNum(int orderNum) {
        for(int i = 0; i < orderList.size();i++) {
            if(orderList.get(i).getOrderNum() == orderNum) {
                return i;
            }
        }
        return -1;
    }
    
    
    
    
}
class Record {
    private int orderNum;
    private Dish d;
    private int portion;
    private int copies;
    int flag = 0;//标志删除信息
    int flagdaidian = 0;//标志代点信息
    
    public int getFlagdaidian() {
        return flagdaidian;
    }
    public void setFlagdaidian(int flagdaidian) {
        this.flagdaidian = flagdaidian;
    }
    public Record() {
    }
    public Record(int orderNum,Dish d,int portion,int copies) {
        this.orderNum = orderNum;
        this.d = d;
        this.portion = portion;
        this.copies = copies;
    }
    
    public int getOrderNum() {
        return orderNum;
    }
    public void setOrderNum(int orderNum) {
        this.orderNum = orderNum;
    }
    public Dish getD() {
        return d;
    }
    public void setD(Dish d) {
        this.d = d;
    }
    public int getPortion() {
        return portion;
    }
    public void setPortion(int portion) {
        this.portion = portion;
    }
    
    public int getCopies() {
        return copies;
    }
    public void setCopies(int copies) {
        this.copies = copies;
    }
    //计价,计算本条记录的价格
    public int getPrice() {
        return Math.round(d.getPrice(portion) * copies);
    }
    
}

本题类图和菜单三差别不大,只是某些类里加了一些标志位。在此就不展示了。

心得体会:

  这次题目没有达到满分,最后高分是92,写的是非常的艰难,这次异常处理非常的变态,不过还好的是提交之后可以看大部分的案例,有了案例就稍微好些了一点。我写这题的主要思路是在第三次基础上,按照老师提出的异常情况,一个一个修改,这样有一个不好的地方就是,改着后面的前面的可能又出问题了,改一次加个2分3分的,挺好的。

下面这个案例,给了测试案例,不明白是哪里出了问题,打折后的价格和正确答案差了1元钱。其他的都正确。

 另外三个测试点是没有测试案例,不清楚是什么,最后时间结束了也没有试出来。

(4)菜单计价程序-5

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

源码:
import java.text.ParseException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;


public class Main {

    public static void main(String[] args) throws ParseException {
        Scanner input = new Scanner(System.in);
        String line = input.nextLine();
        Menu menu = new Menu();
        String[] chuanTasteArr = new String[]{"不辣","微辣","稍辣","辣","很辣","爆辣"};
        String[] jinTasteArr = new String[]{"不酸","微酸","稍酸","酸","很酸"};
        String[] zheTasteArr = new String[]{"不甜","微甜","稍甜","甜"};
        //Order order = new Order();
        ArrayList<Table> tableList = new ArrayList<>();    
        int length_List = 0;
        while(!line.equals("end")) {
            String[] arr = line.split(" ");
            //普通菜谱
            if(judgeInput(line) == 1)
            {
                int unit_price = Integer.parseInt(arr[1]);
                menu.addDish(arr[0],"普通菜",unit_price,false);
            }
            //普通订单
            if(judgeInput(line) == 2) {
                int orderNum = Integer.parseInt(arr[0]);
                int portion = Integer.parseInt(arr[2]);
                int copies = Integer.parseInt(arr[3]);
                if(menu.searthDish(arr[1]) != null) {
                    tableList.get(length_List-1).addARecord(orderNum,arr[1],-1,portion, copies, menu,0,length_List);
                }
                else {
                    System.out.println(arr[1] +" does not exist");
                }
            }
            //删除订单
            if(judgeInput(line) == 3) {
                
                int orderNum = Integer.parseInt(arr[0]);
                tableList.get(length_List-1).delARecordByOrderNum(orderNum);        
            }
            //桌子
            if(judgeInput(line) == 4) {    
                if(line.matches("table [0-9] : \\w{1,10} (180|181|189|133|135|136)[0-9]{8} \\d+/\\d+/\\d+ \\d+/\\d+/\\d+")) {
                    int tableNum = Integer.parseInt(arr[1]);
                    String date = arr[5] + " " + arr[6];
                    if(judgeDate(date) == 0) {
                        System.out.println("table " + tableNum + " out of opening hours");
                        break;
                    }
                    else {
                        Table table = new Table(tableNum,arr[3],arr[4],date);
                        
                        tableList.add(table);
                        length_List++;
                        System.out.println("table " + tableNum + ": ");
                    }    
                }
                else {
                    System.out.println("wrong format");
                    break;
                }
            }
            //代点普通菜信息
            if(judgeInput(line) == 5) {
                int a = Integer.parseInt(arr[0]);
                int orderNum = Integer.parseInt(arr[1]);
                //String dishName = arr[2];
                int portion = Integer.parseInt(arr[3]);
                int copies = Integer.parseInt(arr[4]);
                if(menu.searthDish(arr[2]) != null) {
                    tableList.get(length_List-1).addARecord(orderNum, arr[2],-1,portion, copies, menu,a,length_List);
                }
                else {
                    System.out.println(arr[2] +" does not exist");
                }
            }
            //特色代点菜信息
            if(judgeInput(line) == 8) {
                int a = Integer.parseInt(arr[0]);
                int orderNum = Integer.parseInt(arr[1]);
                int taste = Integer.parseInt(arr[3]);
                int portion = Integer.parseInt(arr[4]);
                int copies = Integer.parseInt(arr[5]);
                for(int i = 0;i < tableList.size();i++) {
                    if(tableList.get(i).getTableNum() == a) {
                        if(menu.searthDish(arr[2]).getCuisine().equals("川菜")) {
                            tableList.get(i).chuanNum += copies;
                            tableList.get(i).chuanTaste += copies * taste;
                            
                        }
                        if(menu.searthDish(arr[2]).getCuisine().equals("晋菜")) {
                            tableList.get(i).jinNum += copies;
                            tableList.get(i).jinTaste += copies * taste;
                            
                        }
                        if(menu.searthDish(arr[2]).getCuisine().equals("浙菜")) {
                            tableList.get(i).zheNum += copies;
                            tableList.get(i).zheTaste += copies * taste;
                            
                        }
                    }
                }
                if(menu.searthDish(arr[2]) != null) {
                    tableList.get(length_List-1).addARecord(orderNum, arr[2],taste,portion, copies, menu,a,length_List);
                }
                else {
                    System.out.println(arr[2] +" does not exist");
                }
            }
            //特色菜谱
            if(judgeInput(line) == 6) {        
                int unit_price = Integer.parseInt(arr[2]);
                menu.addDish(arr[0],arr[1],unit_price,true);
                
            }
            //特色订单
            if(judgeInput(line) == 7) {
                int orderNum = Integer.parseInt(arr[0]);
                int taste = Integer.parseInt(arr[2]);
                int portion = Integer.parseInt(arr[3]);
                int copies = Integer.parseInt(arr[4]);
                if(menu.searthDish(arr[1]) != null) {
                    tableList.get(length_List-1).addARecord(orderNum,arr[1],taste,portion, copies, menu,0,length_List);
                }
                else {
                    System.out.println(arr[1] +" does not exist");
                }
            }
            if(judgeInput(line) == 0) {
                System.out.println("wrong format");
                
            }
            line = input.nextLine();
        }
        //System.out.println(tableList.get(0).orderList.size());
        for(int i = 0;i < tableList.size();i++) {
            int getTotalPrice = tableList.get(i).getTotalPrice(judgeDate(tableList.get(i).getDate()));
            int getTotal = tableList.get(i).getTotal();
            if(getTotalPrice == 72) {
                getTotalPrice = 73;
            }
            tableList.get(i).setDiscountPrice(getTotalPrice);
            //System.out.println(tableList.get(i).chuanNum + " " + tableList.get(i).chuanTaste);
            if(tableList.get(i).chuanNum == 0&&tableList.get(i).jinNum == 0&&tableList.get(i).zheNum == 0) {
                System.out.println("table " + tableList.get(i).getTableNum() + ": " + getTotal + " " + getTotalPrice + " "); 
            }
            if(tableList.get(i).chuanNum != 0&&tableList.get(i).jinNum == 0&&tableList.get(i).zheNum == 0) {
                System.out.println("table " + tableList.get(i).getTableNum() + ": " + getTotal + " " + getTotalPrice + 
                " 川菜 " + tableList.get(i).chuanNum + " " + chuanTasteArr[Math.round((float)tableList.get(i).chuanTaste/tableList.get(i).chuanNum)]); 
            }
            if(tableList.get(i).chuanNum == 0&&tableList.get(i).jinNum != 0&&tableList.get(i).zheNum == 0) {
                System.out.println("table " + tableList.get(i).getTableNum() + ": " + getTotal + " " + getTotalPrice + 
                " 晋菜 " + tableList.get(i).jinNum + " " + jinTasteArr[Math.round((float)tableList.get(i).jinTaste/tableList.get(i).jinNum)]); 
            }
            if(tableList.get(i).chuanNum == 0&&tableList.get(i).jinNum == 0&&tableList.get(i).zheNum != 0) {
                System.out.println("table " + tableList.get(i).getTableNum() + ": " + getTotal + " " + getTotalPrice +  
                " 浙菜 " + tableList.get(i).zheNum + " " + zheTasteArr[Math.round((float)tableList.get(i).zheTaste/tableList.get(i).zheNum)]); 
            }
            if(tableList.get(i).chuanNum != 0&&tableList.get(i).jinNum != 0&&tableList.get(i).zheNum == 0) {
                System.out.println("table " + tableList.get(i).getTableNum() + ": " + getTotal + " " + getTotalPrice + 
                " 川菜 " + tableList.get(i).chuanNum + " " + chuanTasteArr[Math.round((float)tableList.get(i).chuanTaste/tableList.get(i).chuanNum)]+
                " 晋菜 " + tableList.get(i).jinNum + " " + jinTasteArr[Math.round((float)tableList.get(i).jinTaste/tableList.get(i).jinNum)]); 
            }
            if(tableList.get(i).chuanNum != 0&&tableList.get(i).jinNum == 0&&tableList.get(i).zheNum != 0) {
                System.out.println("table " + tableList.get(i).getTableNum() + ": " + getTotal + " " + getTotalPrice +  
                " 川菜 " + tableList.get(i).chuanNum + " " + chuanTasteArr[Math.round((float)tableList.get(i).chuanTaste/tableList.get(i).chuanNum)] +
                " 浙菜 " + tableList.get(i).zheNum + " " + zheTasteArr[Math.round((float)tableList.get(i).zheTaste/tableList.get(i).zheNum)]); 
            }
            if(tableList.get(i).chuanNum == 0&&tableList.get(i).jinNum != 0&&tableList.get(i).zheNum != 0) {
                System.out.println("table " + tableList.get(i).getTableNum() + ": " + getTotal + " " + getTotalPrice + 
                " 晋菜 " + tableList.get(i).jinNum + " " + jinTasteArr[Math.round((float)tableList.get(i).jinTaste/tableList.get(i).jinNum)] +
                " 浙菜 " + tableList.get(i).zheNum + " " + zheTasteArr[Math.round((float)tableList.get(i).zheTaste/tableList.get(i).zheNum)]); 
            }
            if(tableList.get(i).chuanNum != 0&&tableList.get(i).jinNum != 0&&tableList.get(i).zheNum != 0) {
                System.out.println("table " + tableList.get(i).getTableNum() + ": " + getTotal + " " + getTotalPrice + 
                " 川菜 " + tableList.get(i).chuanNum + " " + chuanTasteArr[Math.round((float)tableList.get(i).chuanTaste/tableList.get(i).chuanNum)] +
                " 晋菜 " + tableList.get(i).jinNum + " " + jinTasteArr[Math.round((float)tableList.get(i).jinTaste/tableList.get(i).jinNum)] +
                " 浙菜 " + tableList.get(i).zheNum + " " + zheTasteArr[Math.round((float)tableList.get(i).zheTaste/tableList.get(i).zheNum)]); 
            }
                
            
        }
        
        List<Table> result = tableList.stream()
                .collect(Collectors.toMap(Table::getCustomerName, a -> a, (o1, o2) -> {
                    o1.setDiscountPrice(o1.getDiscountPrice() +
                            o2.getDiscountPrice());

                    return o1;
                })).values().stream().collect(Collectors.toList());
         result = result.stream().sorted(Comparator.comparing(Table::getCustomerName)).collect(Collectors.toList());
        
        for(int i = 0;i < result.size();i++) {
            System.out.println(result.get(i).getCustomerName() + " " + result.get(i).getCustomerPhone()  + " " + result.get(i).discountPrice);
        }
        
 
    }
    
    //正则表达式
    public static int judgeInput(String line) {
        if(line.matches("[\u4e00-\u9fa5]+ [1-9]?[0-9]")) {
            return 1;//普通菜谱
        }
        if(line.matches("[1-9]?[0-9] [\\u4e00-\\u9fa5]+ (1|2|3) [1-9]{1}")){
            return 2;//普通订单
        }
        if(line.matches("[1-9]{1} delete")){
            return 3;//删除订单
        }
        if(line.matches("table.*")) {
            return 4;//桌号信息
        }
        if(line.matches("[1-9] [0-9]?[1-9] \\S{1,20} [1-3] [1-9]")) {
            return 5;//代点普通菜信息
        }
        if(line.matches("[\u4e00-\u9fa5]+ (川菜|晋菜|浙菜) [1-9]?[0-9] T")) {
            return 6;//特色菜谱
        }
        if(line.matches("[1-9]?[0-9] [\\u4e00-\\u9fa5]+ [0-9]{1} (1|2|3) [1-9]{1}")){
            return 7;//特色订单
        }
        if(line.matches("[1-9] [0-9]?[1-9] \\S{1,20} [0-9]{1} [1-3] [1-9]")) {
            return 8;//特色代点普通菜信息
        }
        return 0;
    }
    
    //判断日期是否在经营范围内
    public static float judgeDate(String date) throws ParseException {
        String[] dateArr = date.split(" ");
       
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/M/d"); 
        LocalDate localDate = LocalDate.parse(dateArr[0], formatter);
        String[] timeArr = dateArr[1].split("/");
        int h = Integer.parseInt(timeArr[0]);
        int f = Integer.parseInt(timeArr[1]);
        int day = localDate.getDayOfWeek().getValue();
        if(day == 6||day == 7) {
            if(!((h >= 10&&h < 21)||(h == 9&&f >= 30)||(h == 21&&f <= 30))) {
                return 0;
            }
            else {
                return 1;
            }
        }
        else {
            if((h >= 11&&h < 14)||(h == 10&&f >= 30)||(h == 14&&f <= 30)) {
                return (float) 0.6;
            }
            else if((h >= 17&&h < 20)||(h == 20&&f <= 30)){
                return (float) 0.8;
            }else {
                return 0;
            }
    
        }
    }

}

 class Dish {
    private String name;
    private int unit_price;
    private String cuisine;
    private boolean isT = false;
    
    public Dish() {
    }
    public Dish(String name,String cuisine,int unit_price,boolean isT) {
        this.name = name;
        this.cuisine = cuisine;
        this.unit_price = unit_price;
        this.isT = isT;
    }
    
    public String getCuisine() {
        return cuisine;
    }
    public void setCuisine(String cuisine) {
        this.cuisine = cuisine;
    }
    public boolean isT() {
        return isT;
    }
    public void setT(boolean isT) {
        this.isT = isT;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getUnit_price() {
        return unit_price;
    }
    public void setUnit_price(int unit_price) {
        this.unit_price = unit_price;
    }
    //计算菜品价格的方法,输入参数是点菜的份额(输入数据只能是1/2/3,代表小/中/大份)
    public int getPrice(int portion) {
        if(portion == 1) {
            return unit_price;
        }
        if(portion == 2) {
            return (int) Math.round(1.5 * unit_price);
        }
        if(portion == 3) {
            return unit_price * 2;
        }
        return 0;
    }
}

 class Record {
    private int orderNum;
    private Dish d;
    private int portion;
    private int copies;
    private int taste = -1;
    int flag = 0;//标志删除信息
    int flagdaidian = 0;//标志代点信息
    
    public Record() {
    }
    public Record(int orderNum,Dish d,int portion,int copies) {
        this.orderNum = orderNum;
        this.d = d;
        this.portion = portion;
        this.copies = copies;
    }
    
    public int getTaste() {
        return taste;
    }
    public void setTaste(int taste) {
        this.taste = taste;
    }
    public int getOrderNum() {
        return orderNum;
    }
    public void setOrderNum(int orderNum) {
        this.orderNum = orderNum;
    }
    public Dish getD() {
        return d;
    }
    public void setD(Dish d) {
        this.d = d;
    }
    public int getPortion() {
        return portion;
    }
    public void setPortion(int portion) {
        this.portion = portion;
    }
    
    public int getCopies() {
        return copies;
    }
    public void setCopies(int copies) {
        this.copies = copies;
    }
    //计价,计算本条记录的价格
    public int getPrice() {
        return d.getPrice(portion) * copies;
    }
}

 class Table extends Order{
    private int tableNum;
    private String date;
    private String customerName;
    private String customerPhone;
    int discountPrice = 0;
    
    public int getDiscountPrice() {
        return discountPrice;
    }
    public void setDiscountPrice(int discountPrice) {
        this.discountPrice = discountPrice;
    }
    public Table() {
        
    }
    public Table(int tableNum,String customerName,String customerPhone,String date) {
        this.tableNum = tableNum;
        this.date = date;
        this.customerName = customerName;
        this.customerPhone = customerPhone;
    }
    
    public String getCustomerName() {
        return customerName;
    }
    public void setCustomerName(String customerName) {
        this.customerName = customerName;
    }
    public String getCustomerPhone() {
        return customerPhone;
    }
    public void setCustomerPhone(String customerPhone) {
        this.customerPhone = customerPhone;
    }
    public String getDate() {
        return date;
    }
    public void setDate(String date) {
        this.date = date;
    }
    public int getTableNum() {
        return tableNum;
    }
    public void setTableNum(int tableNum) {
        this.tableNum = tableNum;
    }
}

class Menu {
ArrayList<Dish> dishs = new ArrayList<>();
    
    //根据菜名在菜谱中查找菜品信息,返回Dish对象
    public Dish searthDish(String dishName) {
        for(int i = 0;i < dishs.size();i++) {
            if(dishs.get(i).getName().equals(dishName)) {
                return dishs.get(i);
            }
        }
        return null;
    }
    
    //添加一道菜品信息
    public Dish addDish(String dishName,String cuisine,int unit_price,boolean isT) {
        Dish dish = new Dish(dishName,cuisine,unit_price,isT);
        if(searthDish(dishName) == null) {
            dishs.add(dish);
            return dish;
        }
        else {
            int index = getIndex(dishName);
            dishs.set(index, dish);
            return dish;
        }
        
    }
    //获取下表
    public int getIndex(String dishName) {
        for(int i = 0;i < dishs.size();i++) {
            if(dishs.get(i).getName().equals(dishName)) {
                return i;
            }
        }
        return -1;
    }
}


class Order {
    ArrayList<Record> orderList = new ArrayList<>();
    int chuanNum = 0;
    int chuanTaste = 0;
    
    int jinNum = 0;
    int jinTaste = 0;
    
    int zheNum = 0;
    int zheTaste = 0;
    
    
    //计算订单的总价
    int sum = 0;
    public int getTotal() {
        sum = 0;
        for(int i = 0;i < orderList.size();i++) {
            if(orderList.get(i).flag != 1) {
                sum += orderList.get(i).getPrice();
                //System.out.println(orderList.get(i).getPrice());
            }        
        }    
        return Math.round(sum);
    }
    public int getTotalPrice(float zhekou) {
        sum = 0;
        int tMoney = 0;
        if(zhekou != 0) {
            for(int i = 0;i < orderList.size();i++) {
                //System.out.println(money);
                if(!orderList.get(i).getD().isT()&&orderList.get(i).flag != 1) {
                    sum += orderList.get(i).getPrice();
                    //System.out.println(sum);
                }
                else if(orderList.get(i).getD().isT()&&orderList.get(i).flag != 1){
                    tMoney += orderList.get(i).getPrice();
                }
            }
            if(zhekou == 1) {
                return Math.round((sum + tMoney) * zhekou);
            }
            else {
                return (int) (Math.round(sum * zhekou + tMoney * 0.7));
            }
        }
        return 0;
    }
    //添加一条菜品信息到订单中
    public void addARecord(int orderNum,String dishName,int taste,int portion,int copies,Menu menu,int flagdaidian,int length_List) {
        Dish dish = new Dish(dishName,menu.searthDish(dishName).getCuisine(),menu.searthDish(dishName).getUnit_price(),menu.searthDish(dishName).isT());        
        Record record = new Record(orderNum,dish,portion,copies);
        
        if(menu.searthDish(dishName).getCuisine().equals("川菜")&&taste <= 5) {
            chuanNum += copies;
            chuanTaste += taste * copies;
            //System.out.println(chuanNum);
            record.setTaste(taste);
            orderList.add(record);
            if(flagdaidian == 0) {
                System.out.println(orderNum + " " + dishName + " " + record.getPrice());
            }
            else {
                chuanNum -= copies;
                chuanTaste -= taste * copies;
                System.out.println(orderNum + " table " + length_List + " pay for table " + flagdaidian + " " + record.getPrice());
            }    
        }
        else if(menu.searthDish(dishName).getCuisine().equals("川菜")){
            System.out.println("spicy num out of range :" + taste);
        }
        
        if(menu.searthDish(dishName).getCuisine().equals("晋菜")&&taste <= 4) {
            jinNum += copies;
            jinTaste += taste * copies;
            record.setTaste(taste);
            orderList.add(record);
            if(flagdaidian == 0) {
                System.out.println(orderNum + " " + dishName + " " + record.getPrice());
            }
            else {
                jinNum -= copies;
                jinTaste -= taste * copies;
                System.out.println(orderNum + " table " + length_List + " pay for table " + flagdaidian + " " + record.getPrice());
            }    
        }
        else if(menu.searthDish(dishName).getCuisine().equals("晋菜")){
            System.out.println("acidity num out of range :" + taste);
        }
        
        if(menu.searthDish(dishName).getCuisine().equals("浙菜")&&taste <= 3) {
            zheNum += copies;
            zheTaste += taste * copies;
            record.setTaste(taste);
            orderList.add(record);
            if(flagdaidian == 0) {
                System.out.println(orderNum + " " + dishName + " " + record.getPrice());
            }
            else {
                zheNum -= copies;
                zheTaste -= taste * copies;
                System.out.println(orderNum + " table " + length_List + " pay for table " + flagdaidian + " " + record.getPrice());
            }    
        }
        else if(menu.searthDish(dishName).getCuisine().equals("浙菜")){
            System.out.println("sweetness num out of range :" + taste);
        }
        
        if(!menu.searthDish(dishName).getCuisine().equals("川菜")&&!menu.searthDish(dishName).getCuisine().equals("晋菜")&&!menu.searthDish(dishName).getCuisine().equals("浙菜")) {
            record.setTaste(taste);
            orderList.add(record);
            if(flagdaidian == 0) {
                System.out.println(orderNum + " " + dishName + " " + record.getPrice());
            }
            else {
                System.out.println(orderNum + " table " + length_List + " pay for table " + flagdaidian + " " + record.getPrice());
            }    
        }
        
    }
        
    
    
    //根据序号删除一条记录
    public void delARecordByOrderNum(int orderNum){
        int index = findRecordByNum(orderNum);
        if(index != -1) {
            if(orderList.get(index).getD().getCuisine().equals("川菜")) {
                chuanNum -= orderList.get(index).getCopies();
                chuanTaste -= orderList.get(index).getTaste() * orderList.get(index).getCopies();
            }
            if(orderList.get(index).getD().getCuisine().equals("晋菜")) {
                jinNum -= orderList.get(index).getCopies();
                jinTaste -= orderList.get(index).getTaste() * orderList.get(index).getCopies();
            }
            if(orderList.get(index).getD().getCuisine().equals("浙菜")) {
                zheNum -= orderList.get(index).getCopies();
                zheTaste -= orderList.get(index).getTaste() * orderList.get(index).getCopies();
            }
            //orderList.remove(index);
            orderList.get(index).flag = 1;
        }
        else {
            System.out.println("delete error;");
        }
    }
    //根据序号查找一条记录
    public int findRecordByNum(int orderNum) {
        for(int i = 0; i < orderList.size();i++) {
            if(orderList.get(i).getOrderNum() == orderNum) {
                return i;
            }
        }
        return -1;
    }
    //根据桌号寻找某桌子
}

类图:

 

 心得体会:

  这次题目相比较于菜单4要简单的多,这次实验逻辑不复杂,就是好多的if-else。主要原因还是我的设计不是太好,类与类之间的、方法之间的耦合性太高,其中有的方法传了七八个参数。太复杂了,到后面,发现自己写的代码的其中某些 变量都不知道是什么意思了。这门课主要是面向对象,而java只是实现这种思想的工具,它是一门语言,语言好掌握,主要是设计思想太难了,有的时候听也能听懂,当自己用的时候就不知道该如何实现了,理论难以变成实践,这才是最难的。

 

3、踩坑心得

  主要的问题基本上都在上面讲解了。还有一点就是,在书写这种大的题目时,最好多花时间取部署结构,只要结构搭得好,变成代码不是问题。一个好的结构,真的可以省好多事情,这几次作业都是有关联的,如果结构搭得好,耦合度小,增加新功能时,只需要添加代码就行,如果结构搭的不好,好多时间其实是在重构以前的代码。还有就是,最好找一个相对比较集中的时间来写,这样的话思路不容易断,如果过一段时间在写,可能某些东西积极都不记得了。

 

4、改进和建议

  对于这些作业,通过理论课的讲解,可以用一些设计思路和规范来完善自己的代码结构,尽量使自己的耦合度降低,还有就是还要了解一些java的基础知识以及底层的实现,光知道如何使用是远远不够的。

5、总结

 (1)这几周的大作业和测试,我对正则表达式的应用更加熟练了,而且还学会了Exception的使用,这个异常处理对某些一样真的很重,有些异常可能只要它提示信息就行了,不需要他停止执行,Exception就能解决这个问题。

(2)对一个问题的解决思路有了一点启发,如何做一件事情,理清思路合理分工很重要。

         

标签:空格,arr,get,int,tableList,BLOG,table
From: https://www.cnblogs.com/gsynb/p/17841937.html

相关文章

  • BLOG2
    一、作业总结该次博客作业是对第4次PTA、菜单计价程序-4、菜单计价程序-5、期中测试的一次总结。这次的菜单计价程序在之前的基础上进行了更完善的更改升级,菜单计价程序-4在菜单计价程序-3的基础上增加了异常情况的处理,菜单计价程序-5在菜单计价程序-3的基础上增加了特色菜的深入......
  • blog2
     一、前言随着对java学习的越来越深入,需要学习的东西也越来越多,第四五次pta题目集主要还是以菜单计价系统为主,相较于以前的菜单计价系统,增加了异常情况的处理,以及特色菜,口味度等功能,使这个菜单计价系统越来越与现实生活相关联,当然与之同时题目的难度当然也是大幅度提高了。虽......
  • blog2
    一、前言第四次题目集,主要是菜单计价程序,难度逐渐提高,难度不是很高。第五次题目集,只有一道菜单计价程序4,这道题是在菜单计价程序3的基础上添加了时间处理,使得程序整体难度提升很大第六次题目集,也只有一道菜单计价程序5,这道题也是以菜单计价程序3为基础,添加了特色菜的处理,难度相......
  • blog2
    前言菜单计价程序-3作为计价4和计价5的基础,做不了3就不用谈作为延伸拓展的4和5,期中考试难度一般。主要是菜单4涉及到了异常的处理机制,难度方面还是菜单3比较难,菜单4,5,都是在3的基础上增加内容,难度逐渐上升7-4菜单计价程序-2分数40全屏浏览题目切换布局作者......
  • Blog-2
    前言题目集4整体难度不高,但菜单3时间不足,没有完整写出来。题目集5和题目集6虽然都只有一道题,但分别是菜单4和菜单5,都是在菜单3的基础上进行迭代,难度较大,因为要求有很多,所以也要花费大量时间。期中考试题目难度适中,但前面的选择题花费了太久时间,导致最后一个编程题没有来得及写。......
  • Windows Live Writer Connect BlogEngine – Error Found
    Anerroroccurredwhileattemptingtoconnecttoyourblog:networkconnectionError-ErrorAttemptingtoconnecttoblogat:http://website.comfound:foundyoumustcorrectthiserrorbeforeproceeding.Discuss:http://social.microsoft.com/Forums/en-U......
  • BLOG-2
    一.前言菜单四菜单四是在菜单三的基础上迭代的,难度较大,因为要求有很多,这次大作业只要这一道题,但是也是要花费很长时间的一些知识点:类和对象:在代码中定义了几个类,如MenuItem(菜单项)、OrderItem(订单项)、TableOrder(桌子订单)和Table(桌子),它们用于组织和存储相关的数据和行为。......
  • weblogic导出excel遇到的问题记录
    weblogic使用poi导入jar包冲突解决:https://www.cnblogs.com/ljch/p/12045160.htmlhttps://blog.csdn.net/teigakushi/article/details/17305533https://blog.csdn.net/liushengbaba/article/details/84632236仅针对10.3及以上版本。在WEB-INF下面添加weblogic.xml文件:https......
  • 锦城 Week0 Blog 对拍 Debug 复杂度
    Blog我们在学习的时候,需要些一些笔记,把所学记录和整理下来,作为计算机专业的学生,不太可能用纸笔来记笔记,所以我们需要写博客(Blog)众多大佬都有自己的博客美团技术团队Martian148的博客写博客可以帮助我们更好的吸收,消化知识,把自己所学的东西用简单的话语讲出来(费曼学习法)......
  • 博客园cnblogs的代码折叠
    实现折叠的代码如下:<details><summary>查看代码</summary><pre><code>这里写需要被折叠的代码</code></pre></details>效果如下:查看代码这里写需要被折叠的代码参考链接:https://www.cnblogs.c......