首页 > 其他分享 >第一次blog总

第一次blog总

时间:2024-04-21 13:33:50浏览次数:20  
标签:String int matcher 第一次 blog private str public

一、前言:

  • 第一次pta作业:
    1.知识点:简单的类的设计,类和对象的使用,类的数组类型的基本应用,类间的关联等基础的类间关系设计,实现对类的封装等操作。
    2.题量:4道简单题,1道迭代的难题。
    3.难度:前4道题比较简单;最后一道第一次写难度较大。

  • 第二次pta作业:
    1.知识点:考察类实现Comparable接口,重写compareTo方法。类的属性基本计算。
    2.题量:3道简单题,1道迭代难题。
    3.难度:这次最后一道题在上次的基础上添加了多张试卷和答卷。在第一次的基础上难度增加的不算太大。

  • 第三次pta作业:
    1.知识点:类的封装性,日期类的基本使用,类间关系的设计。
    2.题量:2道简单题,1道迭代的难题。
    3.难度:感觉最后一题这次难度在第二次作业上大幅加大。

二、设计分析

  • 第一次pta作业:

1.Question类:这个类表示一个问题,包括问题的编号、问题内容和问题答案。通过构造函数初始化问题的信息,并且提供打印问题内容的方法以及获取问题答案的方法。

点击查看代码
class Question{
    private int num;
    private String question;
    private String answer;

    public Question(int num,String question,String answer){
        this.num=num;
        this.question=question;
        this.answer=answer;
    }
    public void printQuestion(){
        System.out.println("num="+num+"!question="+question+"!ans="+answer);
    }

    public String getAnswer(){return answer;}
    public String getQuestion(){return question;}
}
2.Test类:这个类表示一张考试试卷,包括试题数组和试题数量。通过构造函数初始化试题数组和试题数量。
点击查看代码
class Test{
    private int quantity;
    private Question[] text_paper;

    public Test(Question[] question,int  quantity){
        this.text_paper=question;
        this.quantity=quantity;
    }
}
3.AnswerSheet类:这个类表示一个答题卡,包括答题数量、答案数组和结果数组。通过构造函数初始化答题数量和答案数组,然后提供判题方法和打印答题卡的方法。
点击查看代码
class AnswerSheet{
    private int quantity;
    private String[] answer;
    private boolean[] result;

    public AnswerSheet(int quantity,String[] answer){
        this.quantity=quantity;
        this.answer=answer;
        this.result=new boolean[quantity+1];
        for(int i=0;i<=quantity;i++) this.result[i]=false;
    }
    public void judge(Question[] questions){
        for(int i=1;i<=quantity;i++){
            String standardAnswer=questions[i].getAnswer();
            if(answer[i].equals(standardAnswer)==true) result[i]=true;
            else result[i]=false;
        }
    }
    public void printSheet(){
        for(int i=1;i<=quantity;i++){
            System.out.print("answer=["+answer[i]+"] result=["+result[i]+"]\n");
        }
    }
    public String getindexOfAnswer(int i){
        return answer[i];
    }
    public boolean getindexOfResult(int i){
        return result[i];
    }
}
4.Main类:这个类包含了主要的程序逻辑,包括从输入中读取题目信息,构建Question对象数组,创建Test对象,读取答案信息,创建AnswerSheet对象,判卷并输出结果。其中getnum、getque、getans方法: 这些方法用于从输入的字符串中提取题目编号、题目内容和题目答案。
点击查看代码
public class Main{
    public static int getnum(String str){
        String a[]=str.split("#N: *");
        String b[]=a[1].split(" *#Q");
        int res=Integer.parseInt(b[0]);
        return res;
    }
    public static String getque(String str){
        String a[]=str.split("#Q: *");
        String b[]=a[1].split(" *#A");
        return b[0];
    }
    public static String getans(String str){
        str+="#A:";
        String a[]=str.split(" *#A: *");
        return a[1];
    }
    public static void main(String[] args){
        Scanner in=new Scanner(System.in);
        int quantity=in.nextInt();
        in.nextLine();
        Question[] questions=new Question[quantity+1];
        for(int i=1;i<=quantity;i++){
            String str=in.nextLine();
            int num=getnum(str);
            String question=getque(str);
            String answer=getans(str);
            questions[num]=new Question(num,question,answer);
        }
        //for(int i=1;i<=quantity;i++) questions[i].printQuestion();

        Test text=new Test(questions,quantity);
        if(quantity!=0){
            String str=in.nextLine();
            String ans[]=str.split(" ?#A:");
            AnswerSheet sheet = new AnswerSheet(quantity,ans);
            //for(int i=1;i<=quantity;i++) System.out.printf("a[%d]=%s\n",i,ans[i]);
            sheet.judge(questions);
            for(int i=1;i<=quantity;i++) System.out.println(questions[i].getQuestion()+"~"+sheet.getindexOfAnswer(i));
            System.out.print(sheet.getindexOfResult(1));
            for(int i=2;i<=quantity;i++) System.out.print(" "+sheet.getindexOfResult(i));
        }
        //String end=in.nextLine();
    }
}
  • 第二次pta作业:
    1.Question类:表示一个问题,包含问题编号、问题内容和标准答案。提供了获取问题信息的方法。
点击查看代码
class Question{
    private int num;
    private String question;
    private String standardAnswer;

    public Question(int num,String question,String standardAnswer){
        this.num=num;
        this.question=question;
        this.standardAnswer=standardAnswer;
    }
    public int getNum() {
        return num;
    }
    public String getQuestion() {
        return question;
    }
    public String getStandardAnswer() {
        return standardAnswer;
    }
}
2.TestPaper类:表示一张试卷,包含试题数量、试卷编号、试题数组、分数数组和总分。提供了添加试题、计算总分以及获取试卷信息的方法。
点击查看代码
class TestPaper{
    private int amount;
    private int testID;
    private Question[] testPaper;
    private int[] score;
    private int sumScore=0;

    public TestPaper(int n,int testID){
        this.amount=n;
        this.testID=testID;
        testPaper=new Question[n+1];
        score=new int[n+1];
    }
    public void add(int n,Question question,int score){
        this.testPaper[n]=question;
        this.score[n]=score;
    }

    public void GenerateSumScore(){
        for(int i=1;i<=amount;i++) sumScore+=score[i];
    }

    public int getTestID(){
        return testID;
    }
    public int getSumScore(){
        return sumScore;
    }
    public int getAmount() {
        return amount;
    }
    public String getQuestion(int n){
        return testPaper[n].getQuestion();
    }
    public String getStandardAnswer(int n){
        return testPaper[n].getStandardAnswer();
    }
    public int getScore(int n) {
        return score[n];
    }
}
3.AnswerSheet类:表示一个答题卡,包含答题数量、试卷编号、问题数组、答案数组、结果数组和分数数组。提供了判卷和打印答题卡的方法。
点击查看代码
class AnswerSheet{
    int amount;
    int testID;
    private String[] questions;
    private String[] answers;
    private boolean[] results;
    private int[] scores;

    public AnswerSheet(int testID,TestPaper testPaper,String[] answer){
        int n=testPaper.getAmount();
        this.amount=n;
        this.testID=testID;
        this.questions=new String[n+1];
        this.answers=new String[n+1];
        this.results=new boolean[n+1];
        this.scores=new int[n+1];

        this.answers=answer;
        for (int i=1;i<=n;i++) questions[i]=testPaper.getQuestion(i);
    }

    public int getTestID(){
        return testID;
    }

    public void judge(TestPaper testPaper){
        int i=0;
        for(i=1;i<answers.length;i++){
            String standardAnswer=testPaper.getStandardAnswer(i);
            if(answers[i].equals(standardAnswer)){
                results[i]=true;
                scores[i]=testPaper.getScore(i);
            }
            else{
                results[i]=false;
                scores[i]=0;
            }
        }
        for(;i<=amount;i++){
            results[i]=false;
            scores[i]=0;
        }

    }

    public void print(){
        int i;
        for(i=1;i<answers.length;i++) {
            System.out.println(questions[i]+"~"+answers[i]+"~"+results[i]);
        }
        for(;i<=amount;i++) System.out.println("answer is null");
        int sumScore=scores[1];
        System.out.print(scores[1]);
        for(i=2;i<=amount;i++){
            System.out.print(" "+scores[i]);
            sumScore+=scores[i];
        }
        System.out.println("~"+sumScore);
    }
}
4.Main类:包含主要程序逻辑,通过正则表达式解析输入的字符串,构建题目、试卷和答题卡,然后进行评分并输出结果。
点击查看代码
public class Main {
    public static HashMap<Integer,Question> questions=new HashMap<>();
    public static HashMap<Integer,TestPaper> tests=new HashMap<>();
    public static ArrayList<AnswerSheet> answerSheets=new ArrayList<>();
    public static int max=0;
    public static void addQuestion(String str){
        Pattern pattern=Pattern.compile("#N:(.+)#Q:(.+)#A:(.+)");
        Matcher matcher=pattern.matcher(str);
        if(matcher.find()){
            int n=Integer.parseInt(matcher.group(1).trim());
            String question=matcher.group(2).trim();
            String standardAnswer=matcher.group(3).trim();
            Question ques=new Question(n,question,standardAnswer);
            questions.put(n,ques);
        }
    }
    public static void addTestPaper(String str){
        String[] t=str.split("-");
        int amount=t.length-1;
        int i=0;
        Matcher matcherAmount=Pattern.compile("#T: *(\\d+)").matcher(str);
        if(matcherAmount.find()) i=Integer.parseInt(matcherAmount.group(1));
        if(max<i) max=i;
        TestPaper test=new TestPaper(amount,i);
        Pattern pattern=Pattern.compile("(\\d+)-(\\d+)");
        Matcher matcher=pattern.matcher(str);
        int cnt=0;
        while(matcher.find()){
            int n=Integer.parseInt(matcher.group(1));
            int score=Integer.parseInt(matcher.group(2));
            test.add(++cnt,questions.get(n),score);
        }
        test.GenerateSumScore();
        tests.put(i,test);
    }
    public static void addAnswerSheet(String str){
        int i=0;
        Matcher matcher1=Pattern.compile("#S: *(\\d+)").matcher(str);
        if(matcher1.find()){
            i=Integer.parseInt(matcher1.group(1));
        }
        String[] answer=str.split(" *#A: *");
        int amount=answer.length-1;//ans[0]="";
        answer[amount].trim();
        AnswerSheet answerSheet;
        if(i>max){
            answerSheet=new AnswerSheet(i,tests.get(1),answer);
        }
        else answerSheet=new AnswerSheet(i,tests.get(i),answer);
        answerSheets.add(answerSheet);
    }
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        String str;
        while(!(str=in.nextLine()).equals("end")){
            if(str.contains("#N:")) addQuestion(str);
            else if(str.contains("#T:")) addTestPaper(str);
            else if(str.contains("#S:")) addAnswerSheet(str);
        }
        for(TestPaper i:tests.values()){
            if(i.getSumScore()!=100) {
                System.out.println("alert: full score of test paper"+i.getTestID()+" is not 100 points");
            }
        }
        for(AnswerSheet i:answerSheets){
            int k=i.getTestID();
            if(tests.get(k)==null) System.out.println("The test paper number does not exist");
            else{
                i.judge(tests.get(k));
                i.print();
            }
        }
    }

5.HashMap和ArrayList:使用HashMap存储题目和试卷信息,使用ArrayList存储答题卡信息,方便根据编号查找信息。
  • 第三次pta作业:
    1.Question类:表示一个问题,包含问题的编号(num)、表示问题的内容(question)、表示问题的标准答案(standardAnswer)、表示问题的状态(status)。提供了获取问题的编号、获取问题的内容、获取问题的标准答案获取问题的状态、设置问题的状态的方法。
点击查看代码
class Question{
    private int num;
    private String question;
    private String standardAnswer;
    private int status;
    
    public Question(int num,String question,String standardAnswer){
        this.num=num;
        this.question=question;
        this.standardAnswer=standardAnswer;
        this.status=1;
    }
    public int getNum() {
        return num;
    }
    public String getQuestion() {
        return question;
    }
    public String getStandardAnswer() {
        return standardAnswer;
    }
    public int getStatus(){
        return status;
    }
    public void setStatus(int status){
        this.status=status;
    }
}
2.TestPaper类:表示一张试卷,包含试卷中问题的数量(amount)、试卷的编号(testID)、Question类型的数组,用于存储试卷中的问题(questions)、整型数组,用于存储每个问题的状态(status)、整型数组,用于存储每个问题的分数(score)、试卷的总分(sumScore)。提供了向试卷中添加问题,并指定问题的分数。将向试卷中添加问题,并指定问题的状态设置为 2。删除指定编号的问题,将其状态设置为 3。获取试卷的编号。获取试卷中问题的数量。获取指定问题的内容。获取指定问题的编号。获取指定问题的标准答案。获取指定问题的状态。获取指定问题的分数。计算试卷的总分。将指定问题的状态设置为 1。设置试卷的总分。方法。
点击查看代码
class TestPaper{
    private int amount;
    private int testID;
    private Question[] questions;
    private int[] status;
    private int[] score;
    private int sumScore;
    
    public TestPaper(int testID,int amount){
        this.amount=amount;
        this.testID=testID;
        questions=new Question[amount+1];
        status=new int[amount+1];
        score=new int[amount+1];
    }
    
    public void add(int i,Question question,int score){
        this.questions[i]=question;
        this.score[i]=score;
        this.status[i]=question.getStatus();
    }
    public void add(int n){
        this.status[n]=2;
    }
    
    public void delete(int n){
        for(int i=1;i<=amount;i++){
            if(status[i]==1&&questions[i].getNum()==n){
                status[i]=3;
            }
        }
    }
    
    public int getTestID(){
        return testID;
    }
    public int getAmount() {
        return amount;
    }
    public String getQuestion(int n){
        return questions[n].getQuestion();
    }
    public int getNum(int n){
        return questions[n].getNum();
    }
    public String getStandardAnswer(int n){
        return questions[n].getStandardAnswer();
    }
    public int getStatus(int n){
        return status[n];
    }
    public int getScore(int n) {
        return score[n];
    }
    public int getSumscore() {
        return sumScore;
    }
    public int getSumScore(){
        int sumScore=0;
        for(int i=1;i<=amount;i++) sumScore+=score[i];
        return  sumScore;
    }
    public void setStatus1(int n){
        this.status[n]=1;
    }
    public void setSumscore(int Sumscore){
        this.sumScore=Sumscore;
    }
    
}
3.AnswerSheet类:表示学生的答题卡,包含了表示答题卡对应的试卷编号(testID)、表示答题卡中问题的数量(amount)、表示学生的学号(studentID)、String 类型的数组,用于存储问题(questions)、String 类型的数组,用于存储学生的答案(answers)、boolean 类型的数组,用于存储每个问题的回答是否正确(results)、整型数组,用于存储每个问题的得分(scores)的成员变量。提供了向答题卡中添加学生对第 n 题的答案、获取答题卡对应的试卷编号、获取学生对第 i 题的答案、获取第 i 题的回答是否正确、获取学生的学号、设置第 i 题的回答是否正确、设置第 i 题的得分、打印学生的得分情况,包括每题得分和总分的方法。
点击查看代码
class AnswerSheet{
    int testID;
    int amount;
    String studentID;
    private String[] questions;
    private String[] answers;
    private boolean[] results;
    private int[] scores;
    
    public AnswerSheet(int testID,int amount,String studentID){
        this.testID=testID;
        this.studentID=studentID;
        this.amount=amount;
        this.questions=new String[amount+1];
        this.answers=new String[amount+1];
        this.results=new boolean[amount+1];
        this.scores=new int[amount+1];
    }
    public AnswerSheet(int testID){
        this.testID=testID;
    }
    
    public void add(int n,String answer){
        this.answers[n]=answer;
    }
    
    public int getTestID(){
        return testID;
    }
    public String getAnswer(int i){
        return answers[i];
    }
    public boolean getResult(int i){
        return results[i];
    }
    public String getStudentID(){
        return studentID;
    }
    
    public void setResult(int i,boolean result){
        this.results[i]=result;
    }
    public void setScore(int i,int score){
        this.scores[i]=score;
    }
    
    public void print(){
        int sumScore=0;
        for(int i=1;i<=amount;i++) {
            sumScore+=scores[i];
            System.out.print(" "+scores[i]);
        }
        System.out.println("~"+sumScore);
    }
}
4.Student类:表示学生信息,包含表示学生的学号(ID)、表示学生的姓名(name)的私有成员变量。提供了获取学生的学号、设置学生的学号、获取学生的姓名、设置学生的姓名的方法。
点击查看代码
class Student{
    private String ID;
    private String name;
    
    public Student(String ID,String name){
        this.ID=ID;
        this.name=name;
    }
    public String getID() {
        return ID;
    }
    public void setID(String ID) {
        this.ID = ID;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
}
5.Judge类:用于评分学生的试卷答案,包含了表示试卷对象,包含了题目、答案等信息(testPaper)、表示答题卡对象,存储了学生的答题情况(answerSheet)的私有成员变量。提供了批改答卷的方法correct(HashMap<integer, question=""> questionBank):该方法用于批改学生的答卷,传入了一个题库的 HashMap,遍历试卷中的每一道题目进行评分。首先通过 testPaper.getAmount() 获取试卷中题目的数量,然后通过循环逐个评分。如果答题卡中第 i 题的答案不为空,进入评分流程。如果题目状态为 2,表示题目不存在,输出提示信息。如果题目状态为 3,表示题目无效,输出提示信息。否则,比较学生的答案和标准答案,根据比较结果设置答题卡的结果和得分,并输出评分信息。如果答题卡中第 i 题的答案为空,输出提示信息。相当于一个评分器类,用于根据标准答案批改学生的答卷,并输出评分结果。通过传入试卷、答题卡和题库信息,实现了对学生答卷的自动评分功能。
点击查看代码
class Judge{
    private TestPaper testPaper;
    private AnswerSheet answerSheet;
    public Judge(TestPaper testPaper,AnswerSheet answerSheet){
        this.testPaper=testPaper;
        this.answerSheet=answerSheet;
    }
    public void correct(HashMap<Integer,Question> questionBank){
        for(int i=1;i<=testPaper.getAmount();i++){
            if(answerSheet.getAnswer(i)!=null){
                if(testPaper.getStatus(i)==2){
                    System.out.println("non-existent question~0");
                }
                else if(testPaper.getStatus(i)==3)
                    System.out.printf("the question %d invalid~0\n",testPaper.getNum(i));
                else{
                    String standardAnswer=testPaper.getStandardAnswer(i);
                    String answer=answerSheet.getAnswer(i);
                    if(answer.equals(standardAnswer)){
                        answerSheet.setResult(i,true);
                        answerSheet.setScore(i,testPaper.getScore(i));
                    }
                    else{
                        answerSheet.setResult(i,false);
                        answerSheet.setScore(i,0);
                    }
                    System.out.println(testPaper.getQuestion(i)+"~"+answer+"~"+answerSheet.getResult(i));
                }
                
            }
            else System.out.println("answer is null");
        }
    }
}
6.Main类:主要功能是读取输入的字符串,解析题目、试卷、答题卡、学生信息等,并进行相应的处理。成员变量有questionBank:存储题库中的题目,使用题号作为 key,题目对象作为 value。tests:存储所有的试卷,使用试卷编号作为 key,试卷对象作为 value。students:存储学生信息,使用学生编号作为 key,学生对象作为 value。answerSheets:存储所有的答题卡。提供了addQuestion(String str):解析输入的字符串,提取题目信息并加入题库中、addTestPaper(String str):解析输入的字符串,创建试卷对象并加入试卷集合中、addAnswerSheet(String str):解析输入的字符串,创建答题卡对象并加入答题卡集合中、addStudent(String str):解析输入的字符串,创建学生对象并加入学生集合中、deleteOp(String str):解析输入的字符串,删除题库中特定题目,并在所有试卷中删除该题目的方法。
点击查看代码
public class Main {
    public static HashMap<Integer,Question> questionBank=new HashMap<>();
    public static HashMap<Integer,TestPaper> tests=new HashMap<>();
    public static HashMap<String,Student> students=new HashMap<>();
    public static ArrayList<AnswerSheet> answerSheets=new ArrayList<>();
    
    public static void addQuestion(String str){
        String regex="^#N: *(\\d+) *#Q:(.*)#A:(.*)";
        Matcher format=Pattern.compile(regex).matcher(str);
        if(!format.find()){
            System.out.println("wrong format:"+str);
            return;
        }
        
        Pattern pattern=Pattern.compile("#N:(.*)#Q:(.*)#A:(.*)");
        Matcher matcher=pattern.matcher(str);
        if(matcher.find()){
            int n=Integer.parseInt(matcher.group(1).trim());
            String question=matcher.group(2).trim();
            String standardAnswer=matcher.group(3).trim();
            Question ques=new Question(n,question,standardAnswer);
            questionBank.put(n,ques);
        }
    }
    public static void addTestPaper(String str){
        String regex="^#T: *\\d+ *((\\d+ *- *\\d+ *)+)$";
        Matcher format=Pattern.compile(regex).matcher(str);
        if(!format.find()){
            System.out.println("wrong format:"+str);
            return;
        }
        
        int testID=0;
        int amount=str.split("-").length-1;
        
        Matcher matcherAmount=Pattern.compile("#T: *(\\d+)").matcher(str);
        if(matcherAmount.find()) testID=Integer.parseInt(matcherAmount.group(1));
        
        TestPaper test=new TestPaper(testID,amount);
        Pattern pattern=Pattern.compile("(\\d+) *- *(\\d+)");
        Matcher matcher=pattern.matcher(str);
        
        int cnt=0;
        int sum=0;
        while(matcher.find()){
            int n=Integer.parseInt(matcher.group(1));
            int score=Integer.parseInt(matcher.group(2));
            sum+=score;
            if(questionBank.containsKey(n)) test.add(++cnt,questionBank.get(n),score);
            else test.add(++cnt);
        }
        test.setSumscore(sum);
        tests.put(testID,test);
    }
    public static void addAnswerSheet(String str){
        String regex="^#S: *\\d+ +\\d+ *(.*?)$";
        Matcher format=Pattern.compile(regex).matcher(str);
        if(!format.find()){
            System.out.println("wrong format:"+str);
            return;
        }
        int testID=0;
        String studentID="";
        Matcher matcher1=Pattern.compile("#S: *(\\d+) +(\\d+)").matcher(str);
        if(matcher1.find()) {
            testID=Integer.parseInt(matcher1.group(1));
            studentID=matcher1.group(2);
        }
        //if(!students.containsKey(studentID)) studentID="-1";
        
        if(tests.containsKey(testID)){
            int amount=tests.get(testID).getAmount();
            AnswerSheet answerSheet=new AnswerSheet(testID,amount,studentID);
            
            Matcher matcher=Pattern.compile("#A: *(\\d+) *- *(.*?) *(?=#A:|\\n|$)").matcher(str);
            while(matcher.find()){
                int questionID=Integer.parseInt(matcher.group(1).trim());
                String answer=matcher.group(2).trim();
                amount=tests.get(testID).getAmount();
                if(questionID>amount) continue;
                //if(questions.get(questionID)!=null) continue;
                
                answerSheet.add(questionID,answer);
            }
            answerSheets.add(answerSheet);
            
            //answerSheet.print();
        }
        else{
            AnswerSheet answerSheet=new AnswerSheet(testID);
            answerSheets.add(answerSheet);
        }
    }
    public static void addStudent(String str){
        String regex="^#X: *( *\\d+ *\\w+ *-*)*$";
        Matcher format=Pattern.compile(regex).matcher(str);
        if(!format.find()){
            System.out.println("wrong format:"+str);
            return;
        }
        Matcher matcher=Pattern.compile("(\\d+) *(\\w+)").matcher(str);
        while(matcher.find()){
            String ID=matcher.group(1),name=matcher.group(2);
            if(students.containsKey(ID)) continue;
            Student student=new Student(ID,name);
            students.put(ID,student);
        }
    }
    public static void deleteOp(String str){
        String regex="^#D: *N *- *(.+)$";
        Matcher format=Pattern.compile(regex).matcher(str);
        if(!format.find()){
            System.out.println("wrong format:"+str);
            return;
        }
        Matcher matcher=Pattern.compile("(\\w) *- *(\\d+)").matcher(str);
        if(matcher.find()){
            int n=Integer.parseInt(matcher.group(2));
            if(questionBank.containsKey(n)){
                questionBank.get(n).setStatus(3);
                for(TestPaper i:tests.values())
                    i.delete(n);
            }
        }
    }
    
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        ArrayList<String> pretreatment = new ArrayList<>();
        String str;
        
        while(true){
            str=in.nextLine();
            if(str.contains("end")) break;
            if(str.contains("#N:")) addQuestion(str);
            else if(str.contains("#D:")) deleteOp(str);
            else if(str.contains("#T:")) addTestPaper(str);
            else if(str.contains("#S:")) addAnswerSheet(str);
            else if(str.contains("#X:")) addStudent(str);
            else System.out.println("wrong format:"+str);
        }
        
        for(TestPaper i:tests.values()){
            if(i.getSumscore()!=100)
                System.out.printf("alert: full score of test paper%d is not 100 points\n",i.getTestID());
        }
        
        for(AnswerSheet i:answerSheets){
            int testID=i.getTestID();
            if(!tests.containsKey(testID)){
                System.out.println("The test paper number does not exist");
                continue;
            }
            
            Judge judge=new Judge(tests.get(testID),i);
            judge.correct(questionBank);
            
            String studentID=i.getStudentID();
            if(!students.containsKey(studentID)){
                System.out.println( studentID+" not found");
                continue;
            }
            System.out.print(studentID+" "+students.get(studentID).getName()+":");
            i.print();
        }
    }
}

三、踩坑心得

  • 第一次pta作业:
    1.输入的内容可能有多个空格,用split分开字符串之后应当删除首尾空格,不然会有两个测试点格式错误。
  • 第二次pta作业:
    1.这次题目都是一遍通过所有样例,没有踩太多的坑。
  • 第三次pta作业:
    1.一开始匹配信息的各个正则表达式都有一些错误,比如匹配题目没用用匹配字符串首的"^"导致一些格式错误的题目输入没有被匹配到。
    2.没有对题目的空答案和答卷的空答案做处理导致有4个缺失答案的测试点一直没过。
    3.最后一题的输出顺序不对,最后有4个点因为Wrong Format的输出顺序和试卷是否满分的顺序不对导致一直没过。

四、改进建议

  • 第一次pta作业:
    1.输入的字符串里的信息可以用正则表达式去匹配。这样就不会匹配无用的空格,就不会有格式错误。
  • 第二次pta作业:
    1.最后一题第一次提交是用数组来储存试卷与答卷,后来觉得用数组不太合理,于是改成了用HashMap来存
  • 第三次pta作业:
    1.第三次各个类中的功能要更复杂,导致一个类中方法过多,应当适当修改设计,把一些与类关系不大的方法分离出去单独设计成一个类,而不是全放在一个类中,比如前两次Judge这个方法是放在AnswerSheet类中的,但其实这个Judge可以单独拎出来设计成一个判题类。还有解析输入的字符串并提取内容这些方法,可以单独设计成一个类而不是放在Main类中,让Main过于臃肿。以及可以单独设计一个类用来保存题目、试卷、答卷等数据。

五、总结

  • 这三次作业学会了怎么用正则表达式,学会了一些基本的设计原理,比如单一职责、开闭原则、迪米特法则等。看了老师发的设计思路,发现自己还有好多需要修改的东西,比如我只设计了最基本的那几个类,题目试卷答卷类,应当修改修改类的设计。

标签:String,int,matcher,第一次,blog,private,str,public
From: https://www.cnblogs.com/DHMO/p/18148645

相关文章

  • 第一次Blog
    前言第一次题目集是对类的设计,类与对象的使用和类与数组关联类的考察。第二次题目集是类与对象之间的创建以及运用的考察。第三次题目集是对类的封装性以及Java自带时间包的运用的考察。总而言之,三次题目集的题目量并不算大,题目集的难度也是比较中等。设计与分析这是答题......
  • 第一次OOPBlog
    PTA也写过了三次作业了,虽然很遗憾都没有拿到满分,不过在练习的过程中也很直观的学到了一点:做题不能因为不会就轻易放弃,要学会钻研。借着这次机会,好好的和之前的自己“算个帐”。首先是第一次作业中:1.涉及到了对象的包装,即面向对象的程序的三大技术之一,如:设计一个风扇类:点击查......
  • PTA三次题目集总结性Blog
    (1)前言1.第一次题目集知识点主要涉及类的设计和实现、构造方法的使用、成员变量和访问器/修改器的定义、方法的重写(toString方法)、对象的创建和调用方法、控制台输入和输出的使用、浮点数的格式化输出等,题量比较适中,难度也比较适中,要求实现的功能较为基础,但需要一定的类设计和方......
  • OOP课程第一次博客
    目录1.前言2.设计与分析1.第一次pta作业2.第二次pta作业3.第三次pta作业3.踩坑心得4.改进建议5.总结1.前言前三次pta题目集的最后一题主要是实现一个模拟小型测试的答题判题程序,第二次题目集在第一次的基础上新增了一个答卷类,第三次题目集在第二次题目集上新增了一个学生类并且......
  • 关于发布题目集1~3的总结性Blog
    前言:这几次关于答题判题程序是通过从键盘中输入提取出对应的信息(比如说题目,试卷,答卷等等)然后再进行逐一判断。从中考查的知识点是正则表达式的运用,加上了split函数的运用,类的数组运用等等。主要的还是这三点。由于一直的迭代,导致最终它的题目要求越来越多,导致难度直线上升。也从8......
  • 题目集1~3的总结性Blog
    一、前言第一次题集知识点主要是掌握类和对象的使用创建,以及类与类之间的关系,还有正则表达式的运用,动态数组ArrayList类的使用,以及方法。这一次的题集难度不是很大,因为是第一次所以来说题量有点大。也是艰难完成了。第二次题集知识点与第一次的类似主要还是对正则表达式的使......
  • blog1
    1前言1.1知识点总结(1)在题目集1里分别有类与对象的使用(包括方法的定义(void方法,int类型返回等等)与属性的定义(例如整形,布尔型的定义等等),如何对类与对象进行引用(使用new创建一个新类,并进行有参构造或无参构造对类里的属性进行赋值))(2)类与类之间的引用,包括方法之间的互相调用(包括一个......
  • blog.admin net8发布二级目录,及图片上传路径处理
    1、发布二级目录,修改以下配置,及对应的二级目录名跟配置的一致 2、图片上传a、修改后台api代码imgController.cspublicasyncTask<MessageModel<string>>InsertPicture([FromForm]UploadFileDtodto){if(dto.file==null||!dto.file.Any())returnFail......
  • memory-cnblog
    linux虚拟内存系统进程的虚拟内存用户区分段:代码段、数据段、堆、共享库、栈内核区:存放进程信息,PID\程序计数器、打开文件列表、task和mm(描述虚拟内存)结构等Linux加载进程时(exec系列系统调用)会为该地址空间每个段分配VMA,VMA数据结构(vm_area_struct)会描述该段的虚拟空间......
  • 4.18第一次冲刺
    晨会1.人员:袁兴兰、齐飞跃、王瑞2.会议讨论袁兴兰:1.今天打算完成寻找免费api,完成博客的整理齐飞跃:1.今天打算学习调用第三方库或第三方api王瑞:1.今天打算画出安卓前端页面2.遇到的问题:调用摄像头报错,版本不兼容3.任务看板 4.合照 ......