Question: Need help implementing findInstructor and addInstructor method to school class In java School class: Modification 1: Add a new method called addInstructor that, if the
Need help implementing findInstructor and addInstructor method to school class
In java
School class:
Modification 1: Add a new method called addInstructor that, if the parameter is not null, adds a copy of it to the listOfInstructors instance variable. If the parameter is null, it adds null to the
listOfInstructors instance variable.
public void addInstructor(Instructor instrObj)
{
// write implementation
}
Modification 2: Add a new method called findInstructor that returns the value returned by calling the find method on the listOfInstructors instance variable passing the instrFirst and instrLast parameters.
private Instructor findInstructor(String instrFirst, String instrLast)
{
// write implementation
}
public class Student
{
//data members of the class student
String firstName,lastName,dateOfJoining,branch;
int id;
Object object;
//default constructor
public Student()
{
}
//overloaded constructor to set the student id
public Student(int id)
{
this.id = id;
}
//overloaded constructor to initialize data members of the class
public Student(String fName,String lName, int sId, String doj, String branch, Object object)
{
firstName=fName;
lastName=lName;
dateOfJoining=doj;
branch=branch;
id=sId;
this.object=object;
}
//method to return the object into readable format
@Override
public String toString()
{
return "Student [firstName=" + firstName + ", lastName=" + lastName + ", dateOfJoining=" + dateOfJoining
+ ", branch=" + branch + ", id=" + id + ", object=" + object + "]";
}
}
Create class clalled DualEnrolledStudent.
DualEnrolledStudent.java source code:
//inheritance
public class DualEnrolledStudent extends Student
{
//data members of the class student
String fname,lname,doj,decision,schoolname;
int cid;
Object ob;
//default constructor
DualEnrolledStudent()
{
}
//overloaded constructor to initialize data members of the class
public DualEnrolledStudent(String fname, String lname, int id, String doj, String decision, Object ob,
String schoolname, int cid)
{
//calls the Student class constructor and sets the student id
super(id);
this.fname=fname;
this.lname=lname;
this.doj=doj;
this.decision=decision;
this.schoolname=schoolname;
this.ob=ob;
this.cid=cid;
}
//method to return the object into readable format
@Override
public String toString()
{
return "DualEnrolledStudent [fname=" + fname + ", lname=" + lname + ", id=" + id + ", decision=" + decision
+ ", schoolname=" + schoolname + ", doj=" + doj + ", cid=" + cid + ", ob=" + ob + "]";
}
}
Create class clalled TransientStudent.
TransientStudent.java source code:
//inheritance
public class TransientStudent extends Student
{
String fname,lname,doj,branch,schoolname;
Object ob;
//default constructor
TransientStudent()
{
}
//overloaded constructor to initialize data members of the class
public TransientStudent(String fname, String lname, int id, String doj, String branch, Object ob,
String schoolname)
{
//calls the Student class constructor and sets the student id
super(id);
this.fname=fname;
this.lname=lname;
this.doj=doj;
this.branch= branch;
this.schoolname=schoolname;
this.ob=ob;
}
//method to return the object into readable format
@Override
public String toString()
{
return "TransientStudent [fname=" + fname + ", lname=" + lname + ", doj=" + doj + ", branch=" + branch
+ ", schoolname=" + schoolname + ", id=" + id + ", ob=" + ob + "]";
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
