题目集4,5的总结性blog

发布时间 2023-07-01 19:56:22作者: 诳语05号机

前言:

题目集4和5 的知识点、题量、难度等情况如下:

  • 知识点:JAVA基础,基础算法,面向对象程序设计

  • 题量:共计 2 道题目

  • 难度:题目较难,有挑战性和突破性

设计与分析:

本次 Blog 重点分析成绩计算系列题目,即题目集 4的 7-1、题目集5的7-1。这两道题都是计价系统的迭代,延用前几次题目集的设计与分析

  • 题目集4的7-1在之前的基础上增加了许多报错信息 和一个特色菜系统

    //特色菜系统,由输入格式判断输入的是否为特色菜,若是则存储的时候改变IsT变量以供后续识别
    if (str1.matches("[\\S]* [\\d]* T")) {
                    String[] token = str1.split(" ");
                    temp.name = token[0];
                    temp.unit_price = Integer.parseInt(token[1]);
                    if (temp.unit_price > 300) {
                        System.out.println(temp.name + " price out of range " + temp.unit_price);
                        continue;
                    }
                    temp.isT = true;
                    isRepeat = menu.searchDish(temp.name);
                    if (isRepeat != -1) {
                        menu.dishs.remove(isRepeat);
                    }
                    menu.dishs.add(temp);
    //信息的读入以及时间系统的创建和报错
    if (str1.matches(
                            "table [1-9][\\d]* [\\d]*/[\\d][\\d]?/[\\d][\\d]? [\\d][\\d]?/[\\d][\\d]?/[\\d][\\d]?")) {
                        String[] token = str1.split(" ");
                        String[] Date = token[2].split("/");
                        String[] Time = token[3].split("/");
                        int[] intDate = new int[3];
                        int[] intTime = new int[3];
                        for (i = 0; i < 3; i++) {
                            intDate[i] = Integer.parseInt(Date[i]);
                            intTime[i] = Integer.parseInt(Time[i]);
                        }
                        temp.num = Integer.parseInt(token[1]);
                        if (temp.num > 55) {
                            System.out.println(temp.num + " table num out of range");
                            str1 = input.nextLine();
                            continue;
    
                        }
                        try {
                            temp.time = LocalDateTime.of(intDate[0], intDate[1], intDate[2], intTime[0], intTime[1],
                                    intTime[2]);
                            temp.getWeekDay();
                        } catch (DateTimeException e) {
                            System.out.println(temp.num + " date error");
                            str1 = input.nextLine();
                            continue;
                        }
                        if (!temp.isOpen()) {
                            System.out.println("table " + temp.num + " out of opening hours");
                            str1 = input.nextLine();
                            continue;
                        }
                        if (!(temp.time.isAfter(LocalDateTime.of(2022, 1, 1, 0, 0, 0))
                                && temp.time.isBefore(LocalDateTime.of(2024, 1, 1, 0, 0, 0)))) {
                            System.out.println("not a valid time period");
                            str1 = input.nextLine();
                            continue;
                        }
    // 判断桌号是否重复
                        if (temp.isOpen()) {
                            for (i = 0; i < tables.size(); i++) {
                                // 有重复的桌号
                                if (temp.num == tables.get(i).num && tables.get(i).isOpen()) {
                                    Duration duration = Duration.between(temp.time, tables.get(i).time);
                                    // 同一天
                                    if (duration.toDays() == 0) {
                                        // 在周一到周五
                                        if (temp.weekday > 0 && temp.weekday < 6) {
                                            // 在同一时间段
                                            if (temp.time.getHour() < 15 && tables.get(i).time.getHour() < 15) {
                                                isRepeat = true;
                                                repeatNum = i;
                                                break;
                                            }
                                        }
                                        // 在周末
                                        else {
                                            // 时间相差小于一小时
                                            if (duration.toHours() < 3600) {
                                                repeatNum = i;
                                                isRepeat = true;
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                        }
    //各类报错信息
    if (temp.order.records.size() > 0) {
                                if (Integer.parseInt(
                                        token[0]) <= temp.order.records.get(temp.order.records.size() - 1).orderNum) {
                                    System.out.println("record serial number sequence error");
                                    continue;
                                }
                            }
                            if (menu.searchDish(token[1]) == -1) {
                                System.out.println(token[1] + " does not exist");
                                continue;
                            }
                            if (portion > 3 || portion < 1) {
                                System.out.println(Integer.parseInt(token[0]) + " portion out of range " + portion);
                                continue;
                            }
                            if (quota > 15) {
                                System.out.println(Integer.parseInt(token[0]) + " num out of range " + quota);
                                continue;
                            }
    // 判断是否为夹杂菜单
                        else if (str1.matches("[\\S]* [\\d]*")) {
                            System.out.println("invalid dish");
                            continue;
                        } else if (str1.matches("[\\S]* [\\d]* T")) {
                            System.out.println("invalid dish");
                            continue;
                        }

     

  • 第五次题目集为第三次题目集的不同迭代分支,与第四次不同,因此应在第三次题目集的代码上做修改
  • 本分支着重了第四次题目集中的特色菜系统
    //新的特色菜系统
    if (str1.matches("[\\S]* [\\S]* [\\d]* T")) {
                    String[] token = str1.split(" ");
                    temp.name = token[0];
                    temp.unit_price = Integer.parseInt(token[2]);
                    temp.isT = true;
                    switch (token[1]) {
                    case "川菜":
                        temp.FlavorType = "spicy";
                        temp.MaxFlavor = 5;
                        break;
                    case "晋菜":
                        temp.FlavorType = "acidity";
                        temp.MaxFlavor = 4;
                        break;
                    case "浙菜":
                        temp.FlavorType = "sweetness";
                        temp.MaxFlavor = 3;
                        break;
                    default :str1 = input.nextLine();
                    System.out.println("wrong format");
                    continue;
                            
                    }
                    isRepeat = menu.searchDish(temp.name);
                    if (isRepeat != -1) {
                        menu.dishs.remove(isRepeat);
                    }
                    menu.dishs.add(temp);
                }

     

  • 第八次题目集的7-2:新增了每次成绩的占比,改变了原有的计算成绩方式,要求将每次成绩计算的小数点保留后累加,最后舍弃小数位。实验课程的信息输入模式也进行了一些修改。需要将原有的类进行修改
    复制代码
    //对原本的课程输入函数进行修改
    if (str1.matches ("[\\D]{0,11} [\\S]+ [\\S]+ .*")) {
                    String[] token = str1.split (" ");
                    if (!(token[1].equals ("必修") || token[1].equals ("选修") || token[1].equals ("实验"))) {
                        System.out.println ("wrong format");
                        str1 = input.nextLine ();
                        continue;
                    }
                    if (!(token[2].equals ("考试") || token[2].equals ("考察") || token[2].equals ("实验"))) {
                        System.out.println ("wrong format");
                        str1 = input.nextLine ();
                        continue;
                    }
                    if (schedule.searchCourseByName (token[0]) != -1) {
                        str1 = input.nextLine ();
                        continue;
                    }
                    schedule.addACourse (token);
                    str1 = input.nextLine ();
                }
    
    
    
    
    
    
    //对课程信息的输出函数进行修改
    public void showEndScores () {
            courses.sort (new Comparator<Course> () {
                @Override
                public int compare (Course o1, Course o2) {
                    Collator collator = Collator.getInstance (java.util.Locale.CHINA);
                    return collator.compare (o1.name, o2.name);
                }
            });
            for (int i = 0; i < courses.size (); i++) {
                courses.get (i).showEndScore ();
            }
        }
    复制代码