Question: Would this work? / / Base class Student public class Student { / / Private attributes private String firstName; private String lastName; private long studentID;

Would this work?
// Base class Student
public class Student {
// Private attributes
private String firstName;
private String lastName;
private long studentID;
// Constructor to initialize all fields
public Student(String firstName, String lastName, long studentID){
this.firstName = firstName;
this.lastName = lastName;
this.studentID = studentID;
}
// Getter for first name
public String getFirstName(){
return firstName;
}
// Setter for first name
public void setFirstName(String firstName){
this.firstName = firstName;
}
// Getter for last name
public String getLastName(){
return lastName;
}
// Setter for last name
public void setLastName(String lastName){
this.lastName = lastName;
}
// Getter for student ID
public long getStudentID(){
return studentID;
}
// Setter for student ID
public void setStudentID(long studentID){
this.studentID = studentID;
}
// Method to compare two students based on student ID
public boolean equals(Student otherStudent){
return this.studentID == otherStudent.studentID;
}
// Method to report grade (prints a message, meant to be overridden in child classes)
public void reportGrade(){
System.out.println("There is no grade here.");
}
// Method to display student information
public void displayStudentInfo(){
System.out.println("Student Name: "+ firstName +""+ lastName);
System.out.println("Student ID: "+ studentID);
}
}
// Derived class for course work students
class Student_Course extends Student {
private String enrolmentType;
private String unitID;
private double overallMark;
private String finalGrade;
public Student_Course(String firstName, String lastName, long studentID, String enrolmentType, String unitID, double overallMark, String finalGrade){
super(firstName, lastName, studentID);
this.enrolmentType = enrolmentType;
this.unitID = unitID;
this.overallMark = overallMark;
this.finalGrade = finalGrade;
}
@Override
public void reportGrade(){
System.out.println("C: "+ getFirstName()+""+ getLastName()+", Student ID: "+ getStudentID()+", Unit ID: "+ unitID +", Overall Mark: "+ overallMark +", Final Grade: "+ finalGrade);
}
}
// Derived class for research students
class Student_Research extends Student {
private String enrolmentType;
private double overallMark;
private String finalGrade;
public Student_Research(String firstName, String lastName, long studentID, String enrolmentType, double overallMark, String finalGrade){
super(firstName, lastName, studentID);
this.enrolmentType = enrolmentType;
this.overallMark = overallMark;
this.finalGrade = finalGrade;
}
@Override
public void reportGrade(){
System.out.println("R: "+ getFirstName()+""+ getLastName()+", Student ID: "+ getStudentID()+", Overall Mark: "+ overallMark +", Final Grade: "+ finalGrade);
}
}
// Main class to test the implementation
public class Main {
public static void main(String[] args){
ArrayList students = new ArrayList<>();
// Create course work student
Student_Course courseStudent = new Student_Course("John", "Doe", 123456, "Full-time", "CS101",85.5,"A");
students.add(courseStudent);
// Create research student
Student_Research researchStudent = new Student_Research("Jane", "Smith", 654321, "Part-time", 90.0,"A+");
students.add(researchStudent);
// Display information and report grades for all students
for (Student student : students){
student.displayStudentInfo();
student.reportGrade();
System.out.println();
}
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!