提交 5631fbf1 编写于 作者: 2 2301_76699619

Thu Apr 18 23:01:00 CST 2024 inscode

上级 ff505d03
import java.util.Arrays;
import java.util.Scanner;
class Person {
private String name;
private String address;
private String phoneNumber;
private String email;
public Person(String name, String address, String phoneNumber, String email) {
this.name = name;
this.address = address;
this.phoneNumber = phoneNumber;
this.email = email;
}
// Getters and Setters
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public String getAddress() { return address; }
public void setAddress(String address) { this.address = address; }
public String getPhoneNumber() { return phoneNumber; }
public void setPhoneNumber(String phoneNumber) { this.phoneNumber = phoneNumber; }
public String getEmail() { return email; }
public void setEmail(String email) { this.email = email; }
@Override
public String toString() {
return "Name: " + name + ", Address: " + address + ", Phone: " + phoneNumber + ", Email: " + email;
}
}
class Student extends Person {
private String studentId;
private String classStatus;
private String college;
private double englishScore;
private double mathScore;
private double computerScore;
private double totalScore;
public Student(String name, String address, String phoneNumber, String email,
String studentId, String classStatus, String college,
double englishScore, double mathScore, double computerScore) {
super(name, address, phoneNumber, email);
this.studentId = studentId;
this.classStatus = classStatus;
this.college = college;
this.englishScore = englishScore;
this.mathScore = mathScore;
this.computerScore = computerScore;
sum();
}
// Getters and Setters
public double getEnglishScore() { return englishScore; }
public void setEnglishScore(double englishScore) {
this.englishScore = englishScore;
sum();
}
public double getMathScore() { return mathScore; }
public void setMathScore(double mathScore) {
this.mathScore = mathScore;
sum();
}
public double getComputerScore() { return computerScore; }
public void setComputerScore(double computerScore) {
this.computerScore = computerScore;
sum();
}
public double getTotalScore() { return totalScore; }
// Methods
public void sum() {
totalScore = englishScore + mathScore + computerScore;
}
public int compare(Student other) {
return Double.compare(this.totalScore, other.totalScore);
}
public double testScore() {
return (englishScore + mathScore + computerScore) / 3;
}
@Override
public String toString() {
return super.toString() + ", StudentID: " + studentId + ", Class Status: " + classStatus +
", College: " + college + ", Scores: [English: " + englishScore +
", Math: " + mathScore + ", Computer: " + computerScore +
", Total: " + totalScore + "]";
}
}
class StudentCommittee extends Student {
private String responsibility;
private String tenure;
public StudentCommittee(String name, String address, String phoneNumber, String email,
String studentId, String classStatus, String college,
double englishScore, double mathScore, double computerScore,
String responsibility, String tenure) {
super(name, address, phoneNumber, email, studentId, classStatus, college,
englishScore, mathScore, computerScore);
this.responsibility = responsibility;
this.tenure = tenure;
}
@Override
public double testScore() {
return super.testScore() + 3;
}
@Override
public String toString() {
return super.toString() + ", Responsibility: " + responsibility + ", Tenure: " + tenure;
}
}
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Student[] students = new Student[4];
for (int i = 0; i < students.length; i++) {
System.out.println("Enter details for student " + (i + 1));
System.out.print("Name: ");
String name = scanner.nextLine();
System.out.print("Address: ");
String address = scanner.nextLine();
System.out.print("Phone: ");
String phone = scanner.nextLine();
System.out.print("Email: ");
String email = scanner.nextLine();
System.out.print("Student ID: ");
String studentId = scanner.nextLine();
System.out.print("Class Status: ");
String classStatus = scanner.nextLine();
}
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册