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 StudentString 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 setFirstNameString firstName
this.firstName firstName;
Getter for last name
public String getLastName
return lastName;
Setter for last name
public void setLastNameString lastName
this.lastName lastName;
Getter for student ID
public long getStudentID
return studentID;
Setter for student ID
public void setStudentIDlong studentID
this.studentID studentID;
Method to compare two students based on student ID
public boolean equalsStudent 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.printlnThere is no grade here.";
Method to display student information
public void displayStudentInfo
System.out.printlnStudent Name: firstName lastName;
System.out.printlnStudent ID: studentID;
Derived class for course work students
class StudentCourse extends Student
private String enrolmentType;
private String unitID;
private double overallMark;
private String finalGrade;
public StudentCourseString firstName, String lastName, long studentID, String enrolmentType, String unitID, double overallMark, String finalGrade
superfirstName lastName, studentID;
this.enrolmentType enrolmentType;
this.unitID unitID;
this.overallMark overallMark;
this.finalGrade finalGrade;
@Override
public void reportGrade
System.out.printlnC: getFirstName getLastName Student ID: getStudentID Unit ID: unitID Overall Mark: overallMark Final Grade: finalGrade;
Derived class for research students
class StudentResearch extends Student
private String enrolmentType;
private double overallMark;
private String finalGrade;
public StudentResearchString firstName, String lastName, long studentID, String enrolmentType, double overallMark, String finalGrade
superfirstName lastName, studentID;
this.enrolmentType enrolmentType;
this.overallMark overallMark;
this.finalGrade finalGrade;
@Override
public void reportGrade
System.out.printlnR: getFirstName getLastName Student ID: getStudentID Overall Mark: overallMark Final Grade: finalGrade;
Main class to test the implementation
public class Main
public static void mainString args
ArrayList students new ArrayList;
Create course work student
StudentCourse courseStudent new StudentCourseJohn "Doe", "Fulltime", CSA;
students.addcourseStudent;
Create research student
StudentResearch researchStudent new StudentResearchJane "Smith", "Parttime", A;
students.addresearchStudent;
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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
