高考生主要分为文科生与理科生,文科生的考试科目为:语文、外语、数学和文综,理科生的考试科目为:语文、外语、数学和理综。但是参加高考考试的还有一部分考生称为艺体生,他们除了参加文化课考试外还要参加专业考试。要求使用Java语言的继承的思想设计类,使用类创建一组对象,表示不同类别的高考生信息,按普通文科生、普通理科生、文科艺术生、理科艺术生、文科体育生、理科体育生类别,按总分由高到低的顺序输出考生信息(考号、姓名、四门课成绩与总分),对于普通考生类别而言,如果总分相同,则按考号由小到大顺序输出;对于艺体生类别而言,如果总分(含专业课成绩)相同,则按专业课成绩由高到低的顺序输出,若专业课成绩也相同则按考号由小到大的顺序输出。 要求使用类的继承完成程序设计。 输入:普通文理生人数,普通文理生信息,艺体生人数,艺体生信息(普通文理生文理分类要求:1-文,2-理;艺体生先有文理分类,再有艺术、体育分类:1-艺术,2-体育) 输出:排序后的考生信息包括:学号,姓名,各科分数,总分,类别
时间: 2023-05-30 15:02:20 浏览: 103
基于java的高考信息系统
import java.util.*;
class Student {
private int id;
private String name;
private int chinese;
private int math;
private int english;
private int totalScore;
public Student(int id, String name, int chinese, int math, int english) {
this.id = id;
this.name = name;
this.chinese = chinese;
this.math = math;
this.english = english;
this.totalScore = chinese + math + english;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
public int getChinese() {
return chinese;
}
public int getMath() {
return math;
}
public int getEnglish() {
return english;
}
public int getTotalScore() {
return totalScore;
}
public String getCategory() {
return "";
}
@Override
public String toString() {
return id + "," + name + "," + chinese + "," + math + "," + english + "," + totalScore + "," + getCategory();
}
}
class ArtStudent extends Student {
private int artScore;
public ArtStudent(int id, String name, int chinese, int math, int english, int artScore) {
super(id, name, chinese, math, english);
this.artScore = artScore;
this.totalScore += artScore;
}
public int getArtScore() {
return artScore;
}
public String getCategory() {
return "艺术生";
}
@Override
public String toString() {
return super.toString() + "," + artScore;
}
}
class SportsStudent extends Student {
private int sportsScore;
public SportsStudent(int id, String name, int chinese, int math, int english, int sportsScore) {
super(id, name, chinese, math, english);
this.sportsScore = sportsScore;
this.totalScore += sportsScore;
}
public int getSportsScore() {
return sportsScore;
}
public String getCategory() {
return "体育生";
}
@Override
public String toString() {
return super.toString() + "," + sportsScore;
}
}
class ArtsStudent extends Student {
public ArtsStudent(int id, String name, int chinese, int math, int english) {
super(id, name, chinese, math, english);
}
public String getCategory() {
return "文科艺术生";
}
}
class ScienceStudent extends Student {
public ScienceStudent(int id, String name, int chinese, int math, int english) {
super(id, name, chinese, math, english);
}
public String getCategory() {
return "文科理科生";
}
}
class ArtScienceStudent extends Student {
private int artScore;
public ArtScienceStudent(int id, String name, int chinese, int math, int english, int artScore) {
super(id, name, chinese, math, english);
this.artScore = artScore;
this.totalScore += artScore;
}
public int getArtScore() {
return artScore;
}
public String getCategory() {
return "理科艺术生";
}
@Override
public String toString() {
return super.toString() + "," + artScore;
}
}
class SportsScienceStudent extends Student {
private int sportsScore;
public SportsScienceStudent(int id, String name, int chinese, int math, int english, int sportsScore) {
super(id, name, chinese, math, english);
this.sportsScore = sportsScore;
this.totalScore += sportsScore;
}
public int getSportsScore() {
return sportsScore;
}
public String getCategory() {
return "理科体育生";
}
@Override
public String toString() {
return super.toString() + "," + sportsScore;
}
}
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt(); // 普通文理生人数
List<Student> students = new ArrayList<>();
// 输入普通文理生信息
for (int i = 0; i < n; i++) {
int id = scanner.nextInt();
String name = scanner.next();
int chinese = scanner.nextInt();
int math = scanner.nextInt();
int english = scanner.nextInt();
int category = scanner.nextInt();
if (category == 1) {
students.add(new ArtsStudent(id, name, chinese, math, english));
} else {
students.add(new ScienceStudent(id, name, chinese, math, english));
}
}
int m = scanner.nextInt(); // 艺体生人数
// 输入艺体生信息
for (int i = 0; i < m; i++) {
int id = scanner.nextInt();
String name = scanner.next();
int chinese = scanner.nextInt();
int math = scanner.nextInt();
int english = scanner.nextInt();
int category = scanner.nextInt();
int score = scanner.nextInt();
if (category == 1) {
students.add(new ArtStudent(id, name, chinese, math, english, score));
} else {
students.add(new SportsStudent(id, name, chinese, math, english, score));
}
}
// 按总分由高到低排序
Collections.sort(students, new Comparator<Student>() {
@Override
public int compare(Student s1, Student s2) {
if (s1.getTotalScore() != s2.getTotalScore()) {
return s2.getTotalScore() - s1.getTotalScore();
} else {
if (s1 instanceof ArtStudent && s2 instanceof ArtStudent) {
if (((ArtStudent) s1).getArtScore() != ((ArtStudent) s2).getArtScore()) {
return ((ArtStudent) s2).getArtScore() - ((ArtStudent) s1).getArtScore();
} else {
return s1.getId() - s2.getId();
}
} else if (s1 instanceof SportsStudent && s2 instanceof SportsStudent) {
if (((SportsStudent) s1).getSportsScore() != ((SportsStudent) s2).getSportsScore()) {
return ((SportsStudent) s2).getSportsScore() - ((SportsStudent) s1).getSportsScore();
} else {
return s1.getId() - s2.getId();
}
} else {
return s1.getId() - s2.getId();
}
}
}
});
// 输出考生信息
for (Student student : students) {
System.out.println(student);
}
}
}
阅读全文