「已注销」 2023-04-11 17:30 采纳率: 33.3%
浏览 47
已结题

Java问题好难,怎么做

怎么用Java写 :一个班级包含一些学生,每个学生有固定的学号与姓名,有JAVA,计算机网络,英语三门课的成绩。试采用面向对象程序设计方法,实现如下功能:
分别找出班上总成绩及单科成绩最高的学生(若有多个,应都找出来),并输出这些学生的信息;分别找出班上至少有一门课成绩低于60分、至少有两门课成绩低于60及三门课成绩均低于60分的学生,并输出这些学生的信息。允许通过输入一个学生的学号或姓名(姓名可能重复,因此可能找到多个学生)寻找学生,并输出其信息(或找到多个,则都输出)。

  • 写回答

1条回答 默认 最新

  • 守时间的孤岛 2023-04-11 20:56
    关注

    该回答引用chatgpt:有问题多交流

    import java.util.ArrayList;
    import java.util.List;
    
    public class Student {
        private String name;
        private int id;
        private int javaScore;
        private int computerNetworkScore;
        private int englishScore;
    
        public Student(String name, int id, int javaScore, int computerNetworkScore, int englishScore) {
            this.name = name;
            this.id = id;
            this.javaScore = javaScore;
            this.computerNetworkScore = computerNetworkScore;
            this.englishScore = englishScore;
        }
    
        public String getName() {
            return name;
        }
    
        public int getId() {
            return id;
        }
    
        public int getJavaScore() {
            return javaScore;
        }
    
        public int getComputerNetworkScore() {
            return computerNetworkScore;
        }
    
        public int getEnglishScore() {
            return englishScore;
        }
    
        public int getTotalScore() {
            return javaScore + computerNetworkScore + englishScore;
        }
    
        public boolean isScoreLow() {
            return javaScore < 60 || computerNetworkScore < 60 || englishScore < 60;
        }
    
        public boolean isTwoScoreLow() {
            int lowCount = 0;
            if (javaScore < 60) {
                lowCount++;
            }
            if (computerNetworkScore < 60) {
                lowCount++;
            }
            if (englishScore < 60) {
                lowCount++;
            }
            return lowCount >= 2;
        }
    
        public boolean isAllScoreLow() {
            return javaScore < 60 && computerNetworkScore < 60 && englishScore < 60;
        }
    
        @Override
        public String toString() {
            return "Student{" +
                    "name='" + name + '\'' +
                    ", id=" + id +
                    ", javaScore=" + javaScore +
                    ", computerNetworkScore=" + computerNetworkScore +
                    ", englishScore=" + englishScore +
                    '}';
        }
    
        public static void main(String[] args) {
            List<Student> studentList = new ArrayList<>();
            studentList.add(new Student("Alice", 1001, 80, 75, 90));
            studentList.add(new Student("Bob", 1002, 90, 85, 80));
            studentList.add(new Student("Charlie", 1003, 70, 60, 65));
            studentList.add(new Student("David", 1004, 85, 65, 55));
            studentList.add(new Student("Eve", 1005, 60, 75, 70));
    
            List<Student> totalScoreMaxStudents = new ArrayList<>();
            int totalScoreMax = 0;
            for (Student student : studentList) {
                int totalScore = student.getTotalScore();
                if (totalScore > totalScoreMax) {
                    totalScoreMaxStudents.clear();
                    totalScoreMaxStudents.add(student);
                    totalScoreMax = totalScore;
                } else if (totalScore == totalScoreMax) {
                    totalScoreMaxStudents.add(student);
                }
            }
            System.out.println("Total score max students: ");
            for (Student student : totalScoreMaxStudents) {
                System.out.println(student);
            }
    
            List<Student> javaScoreMaxStudents = new ArrayList<>();
            int javaScoreMax = 0;
            for (Student student : studentList) {
                int javaScore = student.getJavaScore();
                if (javaScore > javaScoreMax) {
                    javaScoreMaxStudents.clear();
                    javaScoreMaxStudents.add(student);
                    javaScoreMax = javaScore;
                } else if (javaScore == javaScoreMax) {
                javaScoreMaxStudents.add(student);
            }
        }
        System.out.println("Java score max students: ");
        for (Student student : javaScoreMaxStudents) {
            System.out.println(student);
        }
    
        List<Student> computerNetworkScoreMaxStudents = new ArrayList<>();
        int computerNetworkScoreMax = 0;
        for (Student student : studentList) {
            int computerNetworkScore = student.getComputerNetworkScore();
            if (computerNetworkScore > computerNetworkScoreMax) {
                computerNetworkScoreMaxStudents.clear();
                computerNetworkScoreMaxStudents.add(student);
                computerNetworkScoreMax = computerNetworkScore;
            } else if (computerNetworkScore == computerNetworkScoreMax) {
                computerNetworkScoreMaxStudents.add(student);
            }
        }
        System.out.println("Computer network score max students: ");
        for (Student student : computerNetworkScoreMaxStudents) {
            System.out.println(student);
        }
    
        List<Student> englishScoreMaxStudents = new ArrayList<>();
        int englishScoreMax = 0;
        for (Student student : studentList) {
            int englishScore = student.getEnglishScore();
            if (englishScore > englishScoreMax) {
                englishScoreMaxStudents.clear();
                englishScoreMaxStudents.add(student);
                englishScoreMax = englishScore;
            } else if (englishScore == englishScoreMax) {
                englishScoreMaxStudents.add(student);
            }
        }
        System.out.println("English score max students: ");
        for (Student student : englishScoreMaxStudents) {
            System.out.println(student);
        }
    
        List<Student> scoreLowStudents = new ArrayList<>();
        for (Student student : studentList) {
            if (student.isScoreLow()) {
                scoreLowStudents.add(student);
            }
        }
        System.out.println("Score low students: ");
        for (Student student : scoreLowStudents) {
            System.out.println(student);
        }
    
        List<Student> twoScoreLowStudents = new ArrayList<>();
        for (Student student : studentList) {
            if (student.isTwoScoreLow()) {
                twoScoreLowStudents.add(student);
            }
        }
        System.out.println("Two score low students: ");
        for (Student student : twoScoreLowStudents) {
            System.out.println(student);
        }
    
        List<Student> allScoreLowStudents = new ArrayList<>();
        for (Student student : studentList) {
            if (student.isAllScoreLow()) {
                allScoreLowStudents.add(student);
            }
        }
        System.out.println("All score low students: ");
        for (Student student : allScoreLowStudents) {
            System.out.println(student);
        }
    
        String name = "Alice";
        List<Student> studentsByName = new ArrayList<>();
        for (Student student : studentList) {
            if (student.getName().equals(name)) {
                studentsByName.add(student);
            }
        }
        System.out.println("Students by name: " + name);
        for (Student student : studentsByName) {
            System.out.println(student);
        }
    
        int id = 1002;
        List<Student> studentsById = new ArrayList<>();
        for (Student student : studentList) {
            if (student.getId() == id) {
                studentsById.add(student);
            }
        }
        System.out.println("Students by ID: " + id);
        for (Student student : studentsById) {
            System.out.println(student);
        }
    }
    }
    
    

    上述代码中,Student类表示一个学生,包含学号、姓名和三门课的成绩。main方法中创建了一个学生列表,然后分别找出班上总成绩及单科成绩最高的学

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 4月20日
  • 已采纳回答 4月12日
  • 创建了问题 4月11日

悬赏问题

  • ¥15 表达式必须是可修改的左值
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题