提交 ff505d03 编写于 作者: 2 2301_76699619

Thu Apr 18 21:49:00 CST 2024 inscode

上级 255f6106
无法预览此类型文件
public 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;
}
}
public class Student extends Person {
private String studentId;
private String classStatus;
private String college;
public Student(String name, String address, String phoneNumber, String email, String studentId, String classStatus, String college) {
super(name, address, phoneNumber, email);
this.studentId = studentId;
this.classStatus = classStatus;
this.college = college;
}
// Getters and Setters
public String getStudentId() {
return studentId;
}
public void setStudentId(String studentId) {
this.studentId = studentId;
}
public String getClassStatus() {
return classStatus;
}
public void setClassStatus(String classStatus) {
this.classStatus = classStatus;
}
public String getCollege() {
return college;
}
public void setCollege(String college) {
this.college = college;
}
}
public class Employee extends Person {
private String officeNumber;
private double salary;
private Date hireDate;
public Employee(String name, String address, String phoneNumber, String email, String officeNumber, double salary, Date hireDate) {
super(name, address, phoneNumber, email);
this.officeNumber = officeNumber;
this.salary = salary;
this.hireDate = hireDate;
}
// Getters and Setters
public String getOfficeNumber() {
return officeNumber;
}
public void setOfficeNumber(String officeNumber) {
this.officeNumber = officeNumber;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
public Date getHireDate() {
return hireDate;
}
public void setHireDate(Date hireDate) {
this.hireDate = hireDate;
}
}
public class Faculty extends Employee {
private String officeHours;
private String rank;
public Faculty(String name, String address, String phoneNumber, String email, String officeNumber, double salary, Date hireDate, String officeHours, String rank) {
super(name, address, phoneNumber, email, officeNumber, salary, hireDate);
this.officeHours = officeHours;
this.rank = rank;
}
// Getters and Setters
public String getOfficeHours() {
return officeHours;
}
public void setOfficeHours(String officeHours) {
this.officeHours = officeHours;
}
public String getRank() {
return rank;
}
public void setRank(String rank) {
this.rank = rank;
}
}
public class Staff extends Employee {
private String title;
public Staff(String name, String address, String phoneNumber, String email, String officeNumber, double salary, Date hireDate, String title) {
super(name, address, phoneNumber, email, officeNumber, salary, hireDate);
this.title = title;
}
// Getters and Setters
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}
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.
先完成此消息的编辑!
想要评论请 注册