首页 > 其他分享 >pta题目集6-8

pta题目集6-8

时间:2023-06-28 23:44:09浏览次数:32  
标签:num 题目 String temp int pta 课程 public

1.前言:这次pta较之前的点菜程序难度有所减小,但是有更多需要注意的细节,并且有很多测试点非常的极限。

题目集6:

7-1 课程成绩统计程序-1 分数 100 作者 蔡轲 单位 南昌航空大学

某高校课程从性质上分为:必修课、选修课,从考核方式上分为:考试、考察。

考试的总成绩由平时成绩、期末成绩分别乘以权重值得出,比如平时成绩权重0.3,期末成绩权重0.7,总成绩=平时成绩*0.3+期末成绩*0.7。

考察的总成绩直接等于期末成绩

必修课的考核方式必须为考试,选修课可以选择考试、考察任一考核方式。

1、输入:

包括课程、课程成绩两类信息。

课程信息包括:课程名称、课程性质、考核方式(可选,如果性质是必修课,考核方式可以没有)三个数据项。

课程信息格式:课程名称+英文空格+课程性质+英文空格+考核方式

课程性质输入项:必修、选修

考核方式输入选项:考试、考察

课程成绩信息包括:学号、姓名、课程名称、平时成绩(可选)、期末成绩

课程信息格式:学号+英文空格+姓名+英文空格+课程名称+英文空格+平时成绩+英文空格+期末成绩

以上信息的相关约束:

1)平时成绩和期末成绩的权重默认为0.3、0.7

2)成绩是整数,不包含小数部分,成绩的取值范围是【0,100】

3)学号由8位数字组成

4)姓名不超过10个字符

5)课程名称不超过10个字符

6)不特别输入班级信息,班级号是学号的前6位。

2、输出:

输出包含三个部分,包括学生所有课程总成绩的平均分、单门课程成绩平均分、单门课程总成绩平均分、班级所有课程总成绩平均分。

为避免误差,平均分的计算方法为累加所有符合条件的单个成绩,最后除以总数。

1)学生课程总成绩平均分按学号由低到高排序输出

格式:学号+英文空格+姓名+英文空格+总成绩平均分

如果某个学生没有任何成绩信息,输出:学号+英文空格+姓名+英文空格+"did not take any exams"

2)单门课程成绩平均分分为三个分值:平时成绩平均分(可选)、期末考试平均分、总成绩平均分,按课程名称的字符顺序输出

格式:课程名称+英文空格+平时成绩平均分+英文空格+期末考试平均分+英文空格+总成绩平均分

如果某门课程没有任何成绩信息,输出:课程名称+英文空格+"has no grades yet"

3)班级所有课程总成绩平均分按班级由低到高排序输出

格式:班级号+英文空格+总成绩平均分

如果某个班级没有任何成绩信息,输出:班级名称+英文空格+ "has no grades yet"

异常情况:

1)如果解析某个成绩信息时,课程名称不在已输入的课程列表中,输出:学号+英文空格+姓名+英文空格+":"+课程名称+英文空格+"does not exist"

2)如果解析某个成绩信息时,输入的成绩数量和课程的考核方式不匹配,输出:学号+英文空格+姓名+英文空格+": access mode mismatch"

以上两种情况如果同时出现,按第一种情况输出结果。

3)如果解析某个课程信息时,输入的课程性质和课程的考核方式不匹配,输出:课程名称+" : course type & access mode mismatch"

4)格式错误以及其他信息异常如成绩超出范围等,均按格式错误处理,输出"wrong format"

5)若出现重复的课程/成绩信息,只保留第一个课程信息,忽略后面输入的。

信息约束:

1)成绩平均分只取整数部分,小数部分丢弃

代码如下:

import java.util.*;
import java.text.*;
public class Main {
    public static void main(String[] args) {
        ArrayList<course> courses = new ArrayList<>();
        ArrayList<Student> students = new ArrayList<>();
        ArrayList<Classroom> classrooms = new ArrayList<>();
        Scanner input = new Scanner(System.in);
        choose[] chooses = new choose[20];
        int p = 0, m=0;
        for (int i = 0; i < 20; i++) {
            chooses[i] = new choose();
        }
        boolean ifNewCourse = true, ifNewStudent = true, ifNewClass = true;
        String[] same = new String[20];
        while (true) {
            String st = input.nextLine();
            boolean re = false;
            same[m] = st;
            for (int i = 0; i < m; i++) {
                    if (same[i].equals(st)) {
                        re = true;
                    }
                }
            if(re){continue;}
            String[] temp = st.split(" ");
            int s = temp.length;
            if (st.equals("end")) {
                break;
            }
            if (s == 3) {
                course course1 = new course();
                if (course1.getCourse(temp[0], temp[1], temp[2])) {boolean courseSame=false;
                    if(!ifNewCourse){
                        for (int i=0;i<courses.size();i++)
                        {
                            if(temp[0].equals(courses.get(i).name))
                            {courseSame = true;}
                        }
                    }
                    if(courseSame){continue;}
                    courses.add(course1);
                    ifNewCourse = false;
                }
            }
            if (s == 4) {boolean chooseSame= false;
                chooses[p].Choose = temp;
                for(int i=0;i<p;i++)
                {
                    if((chooses[i].Choose[0] == temp[0])&&(chooses[i].Choose[1] ==temp[1])&&(chooses[i].Choose[2] == temp[2]))
                    {
                        chooseSame = true;
                    }
                }
                if(chooseSame){continue;}
                if (chooses[p].getChoose(courses, temp, students, classrooms)) {
                    for (int i = 0; i < courses.size(); i++) {
                        if (courses.get(i).name.equals(temp[2])) courses.get(i).add(Integer.parseInt(temp[3]));
                    }
                    if (ifNewStudent) {
                        Student student1 = new Student();
                        student1.getStudent(temp);
                        students.add(student1);
                        ifNewStudent = false;
                    } else {
                        boolean New = true;
                        for (int i = 0; i < students.size(); i++) {
                            if (students.get(i).number.equals(temp[0])) {
                                students.get(i).add(Integer.parseInt(temp[3]));
                                New = false;
                                break;
                            }
                        }
                        if (New) {
                            Student student1 = new Student();
                            student1.getStudent(temp);
                            students.add(student1);
                        }
                    }
                    if (ifNewClass) {
                        Classroom classroom1 = new Classroom();
                        classroom1.getClass(temp);
                        classrooms.add(classroom1);
                        ifNewClass = false;
                    } else {
                        boolean New = true;
                        for (int i = 0; i < classrooms.size(); i++) {
                            if (classrooms.get(i).number.equals(temp[0].substring(0, 6))) {
                                classrooms.get(i).add(Integer.parseInt(temp[3]));
                                New = false;
                                break;
                            }
                        }
                        if (New) {
                            Classroom classroom1 = new Classroom();
                            classroom1.getClass(temp);
                            classrooms.add(classroom1);
                        }
                    }
                    p++;
                }
            }
            if (s == 5) {boolean chooseSame= false;
                chooses[p].Choose = temp;
                for(int i=0;i<p;i++)
                {
                    if((chooses[i].Choose[0] == temp[0])&&(chooses[i].Choose[1] ==temp[1])&&(chooses[i].Choose[2] == temp[2]))
                    {
                        chooseSame = true;
                    }
                }
                if(chooseSame){continue;}
                if (chooses[p].GetChoose(courses, temp, students, classrooms)) {
                    int a = Integer.parseInt(temp[3]), b = Integer.parseInt(temp[4]);
                    int c = (int) (a * 0.3 + b * 0.7);
                    for (int i = 0; i < courses.size(); i++) {
                        if (courses.get(i).name.equals(temp[2])) courses.get(i).Add(a, b);
                    }
                    if (ifNewStudent) {
                        Student student1 = new Student();
                        student1.GetStudent(temp, c);
                        students.add(student1);
                        ifNewStudent = false;
                    } else {
                        boolean New = true;
                        for (int i = 0; i < students.size(); i++) {
                            if (students.get(i).number.equals(temp[0])) {
                                students.get(i).add(c);
                                New = false;
                                break;
                            }
                        }
                        if (New) {
                            Student student1 = new Student();
                            student1.GetStudent(temp, c);
                            students.add(student1);
                        }
                    }
                    if (ifNewClass) {
                        Classroom classroom1 = new Classroom();
                        classroom1.GetClass(temp, c);
                        classrooms.add(classroom1);
                        ifNewClass = false;
                    } else {
                        boolean New = true;
                        for (int i = 0; i < classrooms.size(); i++) {
                            if (classrooms.get(i).number.equals(temp[0].substring(0, 6))) {
                                classrooms.get(i).add(c);
                                New = false;
                                break;
                            }
                        }
                        if (New) {
                            Classroom classroom1 = new Classroom();
                            classroom1.GetClass(temp, c);
                            classrooms.add(classroom1);
                        }
                    }
                    p++;
                }
            }
            m++;
        }
        Collections.sort(students, new studentComparator());
        Collections.sort(classrooms, new classroomComparator());
        Collections.sort(courses, new courseComparator());
        for (int i = 0; i < students.size(); i++) {
            if (students.get(i).total != 0) {
                System.out.println(students.get(i).number + " " + students.get(i).name + " " + students.get(i).total / students.get(i).num);
            } else {
                System.out.println(students.get(i).number + " " + students.get(i).name + " " + "did not take any exams");
            }
        }
        for (int i = 0; i < courses.size(); i++) {
            if (courses.get(i).usual != 0 || courses.get(i).exam != 0) {
                if (courses.get(i).required) {
                    ;
                    courses.get(i).Print();
                } else {
                    courses.get(i).print();
                }
            } else {
                System.out.println(courses.get(i).name+" "+"has no grades yet");
            }
        }
        for (int i = 0; i < classrooms.size(); i++) {
            if (classrooms.get(i).total != 0) {
                classrooms.get(i).print();
            } else {
                System.out.println(classrooms.get(i).number+" "+"has no grades yet");
            }
        }
    }
}
class studentComparator implements Comparator<Student>
{
    public int compare(Student student1, Student student2)
    {
        return Integer.parseInt(student1.number)-Integer.parseInt(student2.number);
    }
}
class classroomComparator implements Comparator<Classroom>
{
    public int compare(Classroom classroom1, Classroom classroom2)
    {
        return Integer.parseInt(classroom1.number)-Integer.parseInt(classroom2.number);
    }
}
class courseComparator implements Comparator<course>
{
    @Override
    public int compare(course o1, course o2)
    {
        Comparator<Object> compare = Collator.getInstance(java.util.Locale.CHINA);
        return compare.compare(o1.name, o2.name);}


}
class Student
{
    String number;
    String name;
    int total;
    int num;
    Student()
    {
        this.total=0;
        this.num=0;
    }
    public void getStudent(String[] temp)
    {
        this.number = temp[0];
        this.name = temp[1];
        this.total = Integer.parseInt(temp[3]);
        num++;
    }
    public void GetStudent(String[] temp, int a)
    {
        this.number = temp[0];
        this.name = temp[1];
        this.total = a;
        num++;
    }
    public void add(int a)
    {
        total+=a;
        num++;
    }

}
class Classroom
{
    String number;
    int total;
    int num;
    Classroom()
    {
        num=0;
        total=0;
    }
    public void getClass(String[] temp)
    {
        this.number = temp[0].substring(0,6);
        this.total = Integer.parseInt(temp[3]);
        num++;
    }
    public void GetClass(String[] temp, int a)
    {
        this.number = temp[0].substring(0,6);
        this.total = a;
        num++;
    }
    public void add(int a)
    {
        total+=a;
        num++;
    }
    public void print()
    {
        System.out.println(number+" "+total/num);
    }
}
class course
{
    String name;
    boolean required;
    int usual;
    int exam;
    int total;
    int num;
    public boolean getCourse(String name, String Required, String way)
    {
        if(name.length()>10){System.out.println("wrong format");return false;}
        this.name = name;
        if(Required.equals("必修"))
        {
            if(way.equals("考察"))
            {
                System.out.println(name+" : course type & access mode mismatch");
                return false;
            }
            this.required = true;
        }
        if(Required.equals("选修"))
        {
            if(way.equals("考察"))
            {
                this.required = false;
            }
            else
            {
                this.required = true;
            }
        }
        return true;
    }
    public void add(int a)
    {
        usual+=a;
        num++;
    }
    public void print()
    {
        total=usual/num;
        System.out.println(name+" "+total+" "+total);
    }
    public void Add(int a, int b)
    {
        usual+=a;
        exam+=b;
        num++;
    }
    public void Print()
    {
        total= (int) ((int)usual/num*0.3+(int)exam/num*0.7);
        System.out.println(name+" "+(int)usual/num+" "+(int)exam/num+" "+total);
    }
}
class choose
{
    Student student;
    Classroom classroom;
    course course;
    String[] Choose;
    choose()
    {
        student = new Student();
        classroom = new Classroom();
        course = new course();
    }
    public boolean getChoose(ArrayList<course> courses, String[] temp, ArrayList<Student> students, ArrayList<Classroom> classrooms)
    {
        int p=0,i=0;
        int a = Integer.parseInt(temp[3]);
        if(temp[0].length()!=8||temp[1].length()>10||a<0||a>100){System.out.println("wrong format");return false;}
        for(;i<courses.size();i++)
        {
            if(temp[2].equals(courses.get(i).name)&&courses.get(i).required)
            {   Student student1 = new Student();student1.number=temp[0];student1.name=temp[1];students.add(student1);
                Classroom classroom1 = new Classroom();classroom1.number=temp[0].substring(0,6);classrooms.add(classroom1);
                System.out.println(temp[0]+" "+temp[1]+" : access mode mismatch");return false;}
            if(!courses.get(i).name.equals(temp[2])){p++;}
        }
        if(i==0||p==i)
        {   Student student1 = new Student();student1.number=temp[0];student1.name=temp[1];students.add(student1);
            Classroom classroom1 = new Classroom();classroom1.number=temp[0].substring(0,6);classrooms.add(classroom1);
            System.out.println(temp[2]+" does not exist");return false;}
        return true;
    }
    public boolean GetChoose(ArrayList<course> courses, String[] temp, ArrayList<Student> students, ArrayList<Classroom> classrooms)
    {
        int p=0,i=0;
        int a = Integer.parseInt(temp[3]);
        int b = Integer.parseInt(temp[4]);
        if(temp[0].length()!=8||temp[1].length()>10||a<0||a>100||b<0||b>100){System.out.println("wrong format");return false;}
        for(;i<courses.size();i++)
        {
            if((temp[2].equals(courses.get(i).name))&&(!courses.get(i).required))
            {   Student student1 = new Student();student1.number=temp[0];student1.name=temp[1];students.add(student1);
                Classroom classroom1 = new Classroom();classroom1.number=temp[0].substring(0,6);classrooms.add(classroom1);
                System.out.println(temp[0]+" "+temp[1]+temp[2]+" : access mode mismatch");return false;}
            if(!courses.get(i).name.equals(temp[2])){p++;}
        }
        if(i==0||p==i)
        {   Student student1 = new Student();student1.number=temp[0];student1.name=temp[1];students.add(student1);
            Classroom classroom1 = new Classroom();classroom1.number=temp[0].substring(0,6);classrooms.add(classroom1);
            System.out.println(temp[2]+" does not exist");return false;}
        return true;
    }
}
课程成绩统计程序-1

在完成这次作业时由于时间较紧张,代码未能很好地完善,最终堪堪及格,许多较为极限的测试点过不去。

 

题目集6:

 

7-3 课程成绩统计程序-2 分数 60 作者 蔡轲 单位 南昌航空大学

课程成绩统计程序-2在第一次的基础上增加了实验课,以下加粗字体显示为本次新增的内容。

某高校课程从性质上分为:必修课、选修课、实验课,从考核方式上分为:考试、考察、实验。

考试的总成绩由平时成绩、期末成绩分别乘以权重值得出,比如平时成绩权重0.3,期末成绩权重0.7,总成绩=平时成绩*0.3+期末成绩*0.7。

考察的总成绩直接等于期末成绩

实验的总成绩等于课程每次实验成绩的平均分

必修课的考核方式必须为考试,选修课可以选择考试、考察任一考核方式。实验课的成绩必须为实验。

1、输入:

包括课程、课程成绩两类信息。

课程信息包括:课程名称、课程性质、考核方式(可选,如果性质是必修课,考核方式可以没有)三个数据项。

课程信息格式:课程名称+英文空格+课程性质+英文空格+考核方式

课程性质输入项:必修、选修、实验

考核方式输入选项:考试、考察、实验

考试/考查课程成绩信息包括:学号、姓名、课程名称、平时成绩(可选)、期末成绩

考试/考查课程信息格式:学号+英文空格+姓名+英文空格+课程名称+英文空格+平时成绩+英文空格+期末成绩

实验课程成绩信息包括:学号、姓名、课程名称、实验次数、每次成绩

实验次数至少4次,不超过9次

实验课程信息格式:学号+英文空格+姓名+英文空格+课程名称+英文空格+实验次数+英文空格+第一次实验成绩+...+英文空格+最后一次实验成绩

以上信息的相关约束:

1)平时成绩和期末成绩的权重默认为0.3、0.7

2)成绩是整数,不包含小数部分,成绩的取值范围是【0,100】

3)学号由8位数字组成

4)姓名不超过10个字符

5)课程名称不超过10个字符

6)不特别输入班级信息,班级号是学号的前6位。

2、输出:

输出包含三个部分,包括学生所有课程总成绩的平均分、单门课程成绩平均分、单门课程总成绩平均分、班级所有课程总成绩平均分。

为避免误差,平均分的计算方法为累加所有符合条件的单个成绩,最后除以总数。

1)学生课程总成绩平均分按学号由低到高排序输出

格式:学号+英文空格+姓名+英文空格+总成绩平均分

如果某个学生没有任何成绩信息,输出:学号+英文空格+姓名+英文空格+"did not take any exams"

2)单门课程成绩平均分分为三个分值:平时成绩平均分(可选)、期末考试平均分、总成绩平均分,按课程名称的字符顺序输出

考试/考察课程成绩格式:课程名称+英文空格+平时成绩平均分+英文空格+期末考试平均分+英文空格+总成绩平均分

实验课成绩格式:课程名称+英文空格+总成绩平均分

如果某门课程没有任何成绩信息,输出:课程名称+英文空格+"has no grades yet"

3)班级所有课程总成绩平均分按班级由低到高排序输出

格式:班级号+英文空格+总成绩平均分

如果某个班级没有任何成绩信息,输出:班级名称+英文空格+ "has no grades yet"

异常情况:

1)如果解析某个成绩信息时,课程名称不在已输入的课程列表中,输出:学号+英文空格+姓名+英文空格+":"+课程名称+英文空格+"does not exist"

2)如果解析某个成绩信息时,输入的成绩数量和课程的考核方式不匹配,输出:学号+英文空格+姓名+英文空格+": access mode mismatch"

以上两种情况如果同时出现,按第一种情况输出结果。

3)如果解析某个课程信息时,输入的课程性质和课程的考核方式不匹配,输出:课程名称+" : course type & access mode mismatch"

4)格式错误以及其他信息异常如成绩超出范围等,均按格式错误处理,输出"wrong format"

5)若出现重复的课程/成绩信息,只保留第一个课程信息,忽略后面输入的。

import java.util.*;
import java.text.*;
public class Main {
    public static void main(String[] args) {
        ArrayList<course> courses = new ArrayList<>();
        ArrayList<Student> students = new ArrayList<>();
        ArrayList<Classroom> classrooms = new ArrayList<>();
        Scanner input = new Scanner(System.in);
        choose[] chooses = new choose[30];
        int p = 0, m=0;
        for (int i = 0; i < 30; i++) {
            chooses[i] = new choose();
        }
        boolean ifNewCourse = true, ifNewStudent = true, ifNewClass = true;
        String[] same = new String[30];
        while (true) {
            String st = input.nextLine();
            boolean re = false;
            same[m] = st;
            for (int i = 0; i < m; i++) {
                if (same[i].equals(st)) {
                    re = true;
                }
            }
            if(re){continue;}
            String[] temp = st.split(" ");
            int s = temp.length;
            if (st.equals("end")) {
                break;
            }
            if(s>5)
            {boolean chooseSame= false;
                int sum = 0;
                chooses[p].Choose = temp;
                for(int i=0;i<p;i++)
                {
                    if((chooses[i].Choose[0].equals(temp[0]))&&(chooses[i].Choose[1].equals(temp[1]))&&(chooses[i].Choose[2].equals(temp[2])))
                    {
                        chooseSame = true;
                    }
                }
                if(chooseSame){continue;}
                boolean judge = true;

            if(judge)
            {
                boolean out = false;
                if(Integer.parseInt(temp[3])<4||Integer.parseInt(temp[3])>9){System.out.println("wrong format");continue;}
                if(temp.length!=(Integer.parseInt(temp[3])+4))
                {   Student student1 = new Student();student1.number=temp[0];student1.name=temp[1];students.add(student1);
                    Classroom classroom1 = new Classroom();classroom1.number=temp[0].substring(0,6);classrooms.add(classroom1);
                    System.out.println(temp[0]+" "+temp[1]+" : access mode mismatch");continue;}
                for(int i=4;i<temp.length;i++)
                {
                    if(Integer.parseInt(temp[i])<=100&&Integer.parseInt(temp[i])>=0)
                    {
                        sum+=Integer.parseInt(temp[i]);
                    }
                    else {out=true;}
                }
                sum = (sum/Integer.parseInt(temp[3]));
                if(out){System.out.println("wrong format");continue;}
                for (int i = 0; i < courses.size(); i++) {
                    if (courses.get(i).name.equals(temp[2])&&courses.get(i).type){courses.get(i).ADD(sum);}
                }
                if (ifNewStudent) {
                    Student student1 = new Student();
                    student1.GetStudent(temp, sum);
                    students.add(student1);
                    ifNewStudent = false;
                } else {
                    boolean New = true;
                    for (int i = 0; i < students.size(); i++) {
                        if (students.get(i).number.equals(temp[0])) {
                            students.get(i).add(sum);
                            New = false;
                            break;
                        }
                    }
                    if (New) {
                        Student student1 = new Student();
                        student1.GetStudent(temp, sum);
                        students.add(student1);
                    }
                }
                if (ifNewClass) {
                    Classroom classroom1 = new Classroom();
                    classroom1.GetClass(temp, sum);
                    classrooms.add(classroom1);
                    ifNewClass = false;
                } else {
                    boolean New = true;
                    for (int i = 0; i < classrooms.size(); i++) {
                        if (classrooms.get(i).number.equals(temp[0].substring(0, 6))) {
                            classrooms.get(i).add(sum);
                            New = false;
                            break;
                        }
                    }
                    if (New) {
                        Classroom classroom1 = new Classroom();
                        classroom1.GetClass(temp, sum);
                        classrooms.add(classroom1);
                    }
                }
                p++;
            }
            }
            if (s == 3) {
                course course1 = new course();
                if (course1.getCourse(temp[0], temp[1], temp[2])) {boolean courseSame=false;
                    if(!ifNewCourse){
                        for (int i=0;i<courses.size();i++)
                        {
                            if(temp[0].equals(courses.get(i).name))
                            {courseSame = true;}
                        }
                    }
                    if(courseSame){continue;}
                    courses.add(course1);
                    ifNewCourse = false;
                }
            }
            if (s == 4) {boolean chooseSame= false;
                chooses[p].Choose = temp;
                for(int i=0;i<p;i++)
                {
                    if((chooses[i].Choose[0].equals(temp[0]))&&(chooses[i].Choose[1].equals(temp[1]))&&(chooses[i].Choose[2].equals(temp[2])))
                    {
                        chooseSame = true;
                    }
                }
                if(chooseSame){continue;}
                if (chooses[p].getChoose(courses, temp, students, classrooms)) {
                    for (int i = 0; i < courses.size(); i++) {
                        if (courses.get(i).name.equals(temp[2])) courses.get(i).add(Integer.parseInt(temp[3]));
                    }
                    if (ifNewStudent) {
                        Student student1 = new Student();
                        student1.getStudent(temp);
                        students.add(student1);
                        ifNewStudent = false;
                    } else {
                        boolean New = true;
                        for (int i = 0; i < students.size(); i++) {
                            if (students.get(i).number.equals(temp[0])) {
                                students.get(i).add(Integer.parseInt(temp[3]));
                                New = false;
                                break;
                            }
                        }
                        if (New) {
                            Student student1 = new Student();
                            student1.getStudent(temp);
                            students.add(student1);
                        }
                    }
                    if (ifNewClass) {
                        Classroom classroom1 = new Classroom();
                        classroom1.getClass(temp);
                        classrooms.add(classroom1);
                        ifNewClass = false;
                    } else {
                        boolean New = true;
                        for (int i = 0; i < classrooms.size(); i++) {
                            if (classrooms.get(i).number.equals(temp[0].substring(0, 6))) {
                                classrooms.get(i).add(Integer.parseInt(temp[3]));
                                New = false;
                                break;
                            }
                        }
                        if (New) {
                            Classroom classroom1 = new Classroom();
                            classroom1.getClass(temp);
                            classrooms.add(classroom1);
                        }
                    }
                    p++;
                }
            }
            if (s == 5) {boolean chooseSame= false;
                chooses[p].Choose = temp;
                for(int i=0;i<p;i++)
                {
                    if((chooses[i].Choose[0].equals(temp[0]))&&(chooses[i].Choose[1].equals(temp[1]))&&(chooses[i].Choose[2].equals(temp[2])))
                    {
                        chooseSame = true;
                    }
                }
                if(chooseSame){continue;}
                if (chooses[p].GetChoose(courses, temp, students, classrooms)) {
                    int a = Integer.parseInt(temp[3]), b = Integer.parseInt(temp[4]);
                    int c = (int) (a * 0.3 + b * 0.7);
                    for (int i = 0; i < courses.size(); i++) {
                        if (courses.get(i).name.equals(temp[2])) courses.get(i).Add(a, b);
                    }
                    if (ifNewStudent) {
                        Student student1 = new Student();
                        student1.GetStudent(temp, c);
                        students.add(student1);
                        ifNewStudent = false;
                    } else {
                        boolean New = true;
                        for (int i = 0; i < students.size(); i++) {
                            if (students.get(i).number.equals(temp[0])) {
                                students.get(i).add(c);
                                New = false;
                                break;
                            }
                        }
                        if (New) {
                            Student student1 = new Student();
                            student1.GetStudent(temp, c);
                            students.add(student1);
                        }
                    }
                    if (ifNewClass) {
                        Classroom classroom1 = new Classroom();
                        classroom1.GetClass(temp, c);
                        classrooms.add(classroom1);
                        ifNewClass = false;
                    } else {
                        boolean New = true;
                        for (int i = 0; i < classrooms.size(); i++) {
                            if (classrooms.get(i).number.equals(temp[0].substring(0, 6))) {
                                classrooms.get(i).add(c);
                                New = false;
                                break;
                            }
                        }
                        if (New) {
                            Classroom classroom1 = new Classroom();
                            classroom1.GetClass(temp, c);
                            classrooms.add(classroom1);
                        }
                    }
                    p++;
                }
            }
            m++;
        }
        Collections.sort(students, new studentComparator());
        Collections.sort(classrooms, new classroomComparator());
        Collections.sort(courses, new courseComparator());
        for (int i = 0; i < students.size(); i++) {
            if (students.get(i).total != 0) {
                System.out.println(students.get(i).number + " " + students.get(i).name + " " + students.get(i).total / students.get(i).num);
            } else {
                System.out.println(students.get(i).number + " " + students.get(i).name + " " + "did not take any exams");
            }
        }
        for (int i = 0; i < courses.size(); i++) {
            if (courses.get(i).usual != 0 || courses.get(i).exam != 0 ||courses.get(i).total!=0) {
                if (courses.get(i).required) {
                    courses.get(i).Print();
                }
                if(!courses.get(i).required&&!courses.get(i).type)
                {
                    courses.get(i).print();
                }
                if(courses.get(i).type)
                {courses.get(i).PRINT();}
            } else {
                System.out.println(courses.get(i).name+" "+"has no grades yet");
            }
        }
        for (int i = 0; i < classrooms.size(); i++) {
            if (classrooms.get(i).total != 0) {
                classrooms.get(i).print();
            } else {
                System.out.println(classrooms.get(i).number+" "+"has no grades yet");
            }
        }
    }
}
class studentComparator implements Comparator<Student>
{
    public int compare(Student student1, Student student2)
    {
        return Integer.parseInt(student1.number)-Integer.parseInt(student2.number);
    }
}
class classroomComparator implements Comparator<Classroom>
{
    public int compare(Classroom classroom1, Classroom classroom2)
    {
        return Integer.parseInt(classroom1.number)-Integer.parseInt(classroom2.number);
    }
}
class courseComparator implements Comparator<course>
{
    @Override
    public int compare(course o1, course o2)
    {
        Comparator<Object> compare = Collator.getInstance(java.util.Locale.CHINA);
        return compare.compare(o1.name, o2.name);}


}
class Student
{
    String number;
    String name;
    int total;
    int num;
    Student()
    {
        this.total=0;
        this.num=0;
    }
    public void getStudent(String[] temp)
    {
        this.number = temp[0];
        this.name = temp[1];
        this.total = Integer.parseInt(temp[3]);
        num++;
    }
    public void GetStudent(String[] temp, int a)
    {
        this.number = temp[0];
        this.name = temp[1];
        this.total = a;
        num++;
    }

    public void add(int a)
    {
        total+=a;
        num++;
    }

}
class Classroom
{
    String number;
    int total;
    int num;
    Classroom()
    {
        num=0;
        total=0;
    }
    public void getClass(String[] temp)
    {
        this.number = temp[0].substring(0,6);
        this.total = Integer.parseInt(temp[3]);
        num++;
    }
    public void GetClass(String[] temp, int a)
    {
        this.number = temp[0].substring(0,6);
        this.total = a;
        num++;
    }
    public void add(int a)
    {
        total+=a;
        num++;
    }
    public void print()
    {
        System.out.println(number+" "+total/num);
    }
}
class course
{
    String name;
    boolean required;
    boolean type;
    int usual;
    int exam;
    int total;
    int num;
    public boolean getCourse(String name, String Required, String way)
    {
        if(name.length()>10){System.out.println("wrong format");return false;}
        this.name = name;
        if(Required.equals("必修"))
        {
            if(way.equals("考察")||way.equals("实验"))
            {
                System.out.println(name+" : course type & access mode mismatch");
                return false;
            }
            this.required = true;
            type=false;
        }
        if(Required.equals("选修"))
        {
            if(way.equals("考察"))
            {
                this.required = false;
                type=false;
            }
            if(way.equals("考试"))
            {
                this.required = true;
                type=false;
            }
            if(way.equals("实验"))
            {
                System.out.println(name+" : course type & access mode mismatch");
                return false;
            }
        }
        if(Required.equals("实验"))
        {
            if(!way.equals("实验"))
            {
                System.out.println(name+" : course type & access mode mismatch");
                return false;
            }
            this.required = false;
            this.type = true;
        }
        return true;
    }
    public void add(int a)
    {
        usual+=a;
        num++;
    }
    public void print()
    {
        total=usual/num;
        System.out.println(name+" "+total+" "+total);
    }
    public void Add(int a, int b)
    {
        usual+=a;
        exam+=b;
        num++;
    }
    public void Print()
    {
        total= (int) ((int)(usual/num*0.3)+(int)(exam/num*0.7));
        System.out.println(name+" "+(int)usual/num+" "+(int)exam/num+" "+total);
    }
    public void ADD(int a)
    {
        total+=a;
        num++;
    }
    public void PRINT()
    {
        total = (int)(total/num);
        System.out.println(name+" "+total);
    }

}
class choose
{
    Student student;
    Classroom classroom;
    course course;
    String[] Choose;
    choose()
    {
        student = new Student();
        classroom = new Classroom();
        course = new course();
    }
    public boolean getChoose(ArrayList<course> courses, String[] temp, ArrayList<Student> students, ArrayList<Classroom> classrooms)
    {
        int p=0,i=0;
        int a = Integer.parseInt(temp[3]);
        if(temp[0].length()!=8||temp[1].length()>10||a<0||a>100){System.out.println("wrong format");return false;}
        for(;i<courses.size();i++)
        {
            if(temp[2].equals(courses.get(i).name)&&courses.get(i).required)
            {   Student student1 = new Student();student1.number=temp[0];student1.name=temp[1];students.add(student1);
                Classroom classroom1 = new Classroom();classroom1.number=temp[0].substring(0,6);classrooms.add(classroom1);
                System.out.println(temp[0]+" "+temp[1]+" : access mode mismatch");return false;}
            if(!courses.get(i).name.equals(temp[2])){p++;}
        }
        if(i==0||p==i)
        {   Student student1 = new Student();student1.number=temp[0];student1.name=temp[1];students.add(student1);
            Classroom classroom1 = new Classroom();classroom1.number=temp[0].substring(0,6);classrooms.add(classroom1);
            System.out.println(temp[2]+" does not exist");return false;}
        return true;
    }
    public boolean GetChoose(ArrayList<course> courses, String[] temp, ArrayList<Student> students, ArrayList<Classroom> classrooms)
    {
        int p=0,i=0;
        int a = Integer.parseInt(temp[3]);
        int b = Integer.parseInt(temp[4]);
        if(temp[0].length()!=8||temp[1].length()>10||a<0||a>100||b<0||b>100){System.out.println("wrong format");return false;}
        for(;i<courses.size();i++)
        {
            if((temp[2].equals(courses.get(i).name))&&(!courses.get(i).required))
            {   Student student1 = new Student();student1.number=temp[0];student1.name=temp[1];students.add(student1);
                Classroom classroom1 = new Classroom();classroom1.number=temp[0].substring(0,6);classrooms.add(classroom1);
                System.out.println(temp[0]+" "+temp[1]+temp[2]+" : access mode mismatch");return false;}
            if(!courses.get(i).name.equals(temp[2])){p++;}
        }
        if(i==0||p==i)
        {   Student student1 = new Student();student1.number=temp[0];student1.name=temp[1];students.add(student1);
            Classroom classroom1 = new Classroom();classroom1.number=temp[0].substring(0,6);classrooms.add(classroom1);
            System.out.println(temp[2]+" does not exist");return false;}
        return true;
    }
}

这次测试点较少,所以改进之后只有三个极限测试点没有通过。

题目集8:

7-3 jmu-Java-02基本语法-03-身份证排序 分数 9 作者 郑如滨 单位 集美大学
  1. 输入n,然后连续输入n个身份证号。
  2. 然后根据输入的是sort1还是sort2,执行不同的功能。输入的不是sort1或sort2,则输出exit并退出。
    输入sort1,将每个身份证的年月日抽取出来,按年-月-日格式组装,然后对组装后的年-月-日升序输出。
    输入sort2,将所有身份证按照里面的年月日升序输出。
代码如下:
import java.util.Arrays;
import java.util.Scanner;
    public class Main {
        public static void main(String[] args) {
            Scanner sc=new Scanner (System.in);
            int n;
            n=sc.nextInt();
            String s[]=new String[n];
            String birth[]=new String[n];
            
            String str;
            for(int i=0;i<n;i++) {
                s[i]=sc.next();
            }
            while(true) {
                str=sc.next();
                if(str.equals("e")) {
                    System.out.println("exit");
                    break;
                }else if(str.equals("sort1")) {
                    for(int i=0;i<n;i++) {
                        birth[i]=s[i].substring(6,10 )+'-'+    s[i].substring(10, 12)+'-'+s[i].substring(12, 14);
                        
                    }
                    Arrays.sort(birth);
                    for(int i=0;i<n;i++) {
                        System.out.println(birth[i]);
                    }
                }else if(str.equals("sort2")) {
                    for(int i=0;i<n;i++) {
                        birth[i]=s[i].substring(6,10 )+    s[i].substring(10, 12)+s[i].substring(12, 14);
                    }
                    Arrays.sort(birth);
                    for(int i=0;i<n;i++) {
                        for(int j=0;j<n;j++){
                            if(s[j].contains(birth[i])) {
                                System.out.println(s[j]);
                                break;
                            }
                        }
                    }
                }
            }
        }

}
7-4 jmu-Java-04面向对象进阶-03-接口-自定义接口ArrayIntegerStack 分数 10 作者 郑如滨 单位 集美大学

定义IntegerStack接口,用于声明一个存放Integer元素的栈的常见方法:

 
public Integer push(Integer item);
//如果item为null,则不入栈直接返回null。如果栈满,也返回null。如果插入成功,返回item。

public Integer pop();   //出栈,如果为空,则返回null。出栈时只移动栈顶指针,相应位置不置为null
public Integer peek();  //获得栈顶元素,如果为空,则返回null.
public boolean empty(); //如果为空返回true
public int size();      //返回栈中元素个数
 

定义IntegerStack的实现类ArrayIntegerStack,内部使用数组实现。创建时,可指定内部数组大小。

main方法说明

  1. 输入n,建立可包含n个元素的ArrayIntegerStack对象
  2. 输入m个值,均入栈。每次入栈均打印入栈返回结果。
  3. 输出栈顶元素,输出是否为空,输出size
  4. 使用Arrays.toString()输出内部数组中的值。
  5. 输入x,然后出栈x次,每次出栈均打印。
  6. 输出栈顶元素,输出是否为空,输出size
  7. 使用Arrays.toString()输出内部数组中的值。

 

代码如下:

import java.util.*;
 
interface IntegerStack{
    public Integer push(Integer item);
    public Integer pop(); 
    public Integer peek();
    public boolean empty();
    public int size();
}
 
class ArrayIntegerStack implements IntegerStack{
    Integer A[];
    int Max,Size = 0;
    public ArrayIntegerStack(int n) {
        A = new Integer[n];
        Max = n;
    }
    public Integer push(Integer item) {
        if(item == null)
            return null;
        else if(Size == Max)
            return null;
        else {
            A[Size] = item;
            Size++;
            return item;
        }            
    }
    
    public Integer pop() {
        if(Size == 0)
            return null;
        Size--;
        return A[Size];
    }
    
    public Integer peek() {
        if(Size == 0)
            return null;
        else
            return A[Size - 1];
    }
    
    public boolean empty() {
        if(Size == 0)
            return true;
        else
            return false;
    }
    
    public int size() {
        return Size;
    }
    
    public String toString() {
        return Arrays.toString(A);
    }
    
}
public class Main {
 
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        ArrayIntegerStack A = new ArrayIntegerStack(n);
        int m = in.nextInt();
        for(int i = 0;i < m;i++) {
            System.out.println(A.push(in.nextInt()));
        }
        
        System.out.println(A.peek() + "," + A.empty() + "," + A.size());
        System.out.println(A.toString());
        
        int x = in.nextInt();
        for(int i = 0;i < x;i++) {
            System.out.println(A.pop());
        }
        
        System.out.println(A.peek() + "," + A.empty() + "," + A.size());
        System.out.println(A.toString());
        in.close();
    }
 
}

3.总结:

这几次pta的作业给了我很大的触动,首先就是可持续性改进,在课程成绩统计程序中写下的代码,在接下来的课程成绩统计程序2课程成绩统计程序3中都只要做小小的改进甚至不需要改进就能拿来用,之后只需要随着题目的改动来写出新的类和改动主类就行,这几个题目不仅增强了我对类的属性,方法的思考,而且深化了我对面对对象程序设计的理解,同时,对于idea的使用,比如调试,插件的安装与查找等技能,也得到了很好的锻炼!我的独立思考能力也逐渐增强,对写代码的热情也越来越高!我认为还需改进的地方就是代码的健壮性不足,仍需要多多钻研。我认为实验题目也同样可以让学生写一篇博客来回顾自己的学习经历,对于pta题目的话我认为可以在每次作业之后开一个补题集给学生不断的进行改进。以上是我的全部内容。

 

标签:num,题目,String,temp,int,pta,课程,public
From: https://www.cnblogs.com/henhendexie/p/17512847.html

相关文章

  • PTA6-8总结报告
    前言:题目集六涉及的知识点有:1.利用Arrays.sort()方法根据某些标准对对象进行排序。2.异常处理(NumberFormatException)和条件语句来检查不正确的输入格式。3.类和对象:代码中使用了Class、Student和Lesson等类来表示班级、学生和课程。4.数组:代码使用了不同类型的数组,如班级、学生和......
  • blog-6-8次PTA题目集(成绩计算系列)
    (1)前言:第6次题目集课程成绩统计程序-1在规范性输入时涉及到了正则表达式,数组列表及其相关方法的使用,if-else,for,foreach循环的使用,以及字符串中的substring()方法,equals()方法的使用,Integer.toString等相关类型之间转化的方式,数据域的封装,Comparable接口的实现,Collections.sort......
  • 题目集6~8总结
    一.前言Java编程语言是当今最流行的编程语言之一,由于其跨平台性、面向对象性和安全性等特点,受到广泛的应用。作为一名计算机专业的学生,在学习Java编程语言时,我们需要完成多个作业来巩固所学知识。在前三次Java作业中,我们已经学习了Java的基础知识和常用技术,通过完成这些作业,我们......
  • 6-8题目集
    前言:在这个六到八次题目集中,主要用课程管理系统来考察以下的知识点,:输入输出、字符串处理、数据结构(HashMap、ArrayList、List、Set)、循环、条件判断、类与对象、继承与多态、异常处理等。题量从小变大,难度大的也主要是那些学生课程成绩管理系统的解决,输入信息的解析和存储、成绩......
  • 第六到第八次题目集总结
    第六到第八次题目集总结一、题目集六课程成绩统计程序-1第一题题目内容:课程成绩统计程序-1publicclassGrade{privatefinalCourseGradecourseGrade;privatefinalSubGradesubGrade;publicGrade(CourseGradecourseGrade,SubGradesubGrade){......
  • 6-8次PTA题目总结blog
    前言:题目集1~3的知识点、题量、难度等情况如下:知识点:JAVA基础,基础算法,面向对象程序设计题量:共计3道题目难度:题目从易到难,逐层递进,分别为考察Java容器的理解、掌握与运用。设计与分析: 1importjava.util.*;2importjava.util.regex.Pattern;3impo......
  • PTA题目集6-8总结
    (1)前言题目集6只有一个课程成绩统计程序-1,难点总体来说中等,考察的也是对java类的定义和使用,以及如何设计能使程序往后修改方便,可以根据给出的类图来进行设计。题目集7中有上一次程序的进阶版课程成绩统计程序-2,相比于之前添加了实验这一课程性质,总的来说改变不大,只需要在......
  • PTA题目集6~8
    (1)前言前面的点菜系统结束后,以为终于解脱了,没想到是另一个噩梦。以下是PTA6到8的相关问题。题目集6,只有一题,课程成绩统计程序-1,难度嘛,中等偏上吧,至少对我来说,因为我接口基本没学懂。题目集7,有四题,容器-HashMap-检索,容器-HashMap-排序,课程成绩统计程序-2,动物发声模拟器(多态)。前面......
  • pta题目集6~8次总结性blog
    一、前言总结三次题目集的知识点、题量、难度等情况第六次题目集开始了新的迭代系统,万恶的点菜系统终于结束了,取而代之的是课程成绩统计程序,虽说更换了迭代系统但是感觉换汤不换药,很多要用到的知识点和内容和菜单非常类似,甚至是比点菜系统要简单很多(听说是不让平时分那么难看),万......
  • 面向对象程序编程6-8次PTA题目集(成绩计算系列)的总结性Blog
    1.对之前发布的6-8次PTA题目集(成绩计算系列),内容要求如下:(1)前言:总结之前所涉及到的知识点、题量、难度等情况第六次PTA题目集:知识点:此次PTA题目仅只有这一个题目,主要考的内容就是对类的使用(类似现实,对有关联的各个数据合并在一起,便于一起使用),运用正则表达式(比较苦难使用,要记住那......