package studentmanagement; import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class test { static class person {//公共类 private String name; public String getName() { return name; } public void setName(String name) { this.name = name; } } static class Student extends person { private String classId;//课程号 private String subject;//科目 private String studentClass;//所在班级 private double score;//分数 private double showScore;//额外表现分数 private double endScore;//最终成绩 public double getScore() { return score; } public void setScore(double score) { this.score = score; } public String getClassId() { return classId; } public void setClassId(String classId) { this.classId = classId; } public String getStudentClass() { return studentClass; } public void setStudentClass(String studentClass) { this.studentClass = studentClass; } public String getSubject() { return subject; } public void setSubject(String subject) { this.subject = subject; } public double getShowScore() { return showScore; } public void setShowScore(double showScore) { this.showScore = showScore; } public double getEndScore() { return endScore; } public void setEndScore(double endScore) { this.endScore = endScore; } //额外表现分 public double biaoXianFen(double score, double showScore) { endScore = score+showScore*0.8; return endScore; } } public static void main(String[] args) { System.out.println("您好欢迎来到成绩录入系统,请输入录入学生个数"); Scanner scanner=new Scanner(System.in);//输入流 int n= Integer.parseInt(scanner.nextLine());//String强转为一个Int类型 System.out.println("请输入您将要录入学生的基本信息"); List<Student> list=new ArrayList<Student>();//List集合,可以录入多个学生的成绩 for(int i=1;i<=n;i++) { Student student = new Student();//实例化,new一个空的学生实体 System.out.println("第"+i+"个学生姓名"); String name=scanner.nextLine(); student.setName(name); System.out.println("第"+i+"个学生班级"); String studentClass=scanner.nextLine(); student.setStudentClass(studentClass); System.out.println("第"+i+"个学生课程号"); String classId=scanner.nextLine(); student.setClassId(classId); System.out.println("第"+i+"个学生科目"); String subject=scanner.nextLine(); student.setSubject(subject); System.out.println("第"+i+"个学生成绩,实际得分以及额外表现分数"); double score=scanner.nextDouble(); double showScore=scanner.nextDouble(); Double endScore = student.biaoXianFen(score, showScore);//返回最终成绩 student.setScore(score); student.setShowScore(showScore); student.setEndScore(endScore); scanner.nextLine(); list.add(student);//通过list集合打点调用add方法 } for(Student student:list) {//for遍历,把所有的学生查出来,放入到了a中 System.out.println("已成功录入学生姓名为:"+student.getName()+"同学,课程号为: "+student.getClassId()+"科目: "+student.getSubject() +"最终得分成绩为: "+student.getEndScore()+"额外表现分为: "+student.getShowScore()); } } }