The OnCampusStudent class is a direct subclass of Student. It adds new instance
ID: 639729 • Letter: T
Question
The OnCampusStudent class is a direct subclass of Student. It adds new instance variables that are specific to on-campus
students:
mResident True if the OnCampusStudent is a resident, false for non-resident.
mProgramFee Certain OnCampusStudent's pay an additional program fee. This value may be 0.
The OnCampusStudent instance methods are mostly straightforward to implement so we shall only discuss two of them.
+OnCampusStudent(pId: String, pFname: String, pLname: String): <>
Must call the superclass constructor passing pId, pFname, and pLname as parameters.
+calcTuition(): void <>
Must implement the rules described in Section 3 Background. Note that we cannot directly access the mTuition instance
variable of an OnCampus Student because it is declared as private in Student. So how do we write to mTuition? By calling
the protected setTuition() method that is inherited from Student. The pseudocode for calcTuition() is:
Override Method calcTuititon() Returns Nothing
Declare double variable t
If getResidency() returns true Then
t = TuitionConstants.ONCAMP_RES_BASE
Else
t = TuitionConstants.ONCAMP_NONRES_BASE
End if
t = t + getProgramFee();
If getCredits() > TuitionConstants.MAX_CREDITS Then
t = t + (getCredits() - TuitionConstants.MAX_CREDITS)
Explanation / Answer
Comment if you have any doubts.
//OnCampusStudent class
public class OnCampusStudent extends Student
{
private boolean mResident;
private double mProgramFee;
public OnCampusStudent(String pId, String pFname, String pLname) {
super(pId, pFname, pLname);
}
public boolean getResidency()
{
return this.mResident;
}
public double getProgramFee()
{
return this.mProgramFee;
}
public void calcTuition()
{
double t;
if(this.getResidency())
{
t=TuitionConstants.ONCAMP_RES_BASE;
}else t=TuitionConstants.ONCAMP_NONRES_BASE;
t+=this.getProgramFee();
if(this.getCredits()>TuitionConstants.MAX_CREDITS)
{
t+=(this.getCredits()-TuitionConstants.MAX_CREDITS)*TuitionConstants.ONCAMP_ADD_CREDITS;
}
this.setTuition(t);
}
}
//################################################################################
//OnlineStudent class
public class OnlineStudent extends Student
{
private boolean mTechFee;
public OnlineStudent(String pId, String pFname, String pLname) {
super(pId, pFname, pLname);
}
public boolean getTechFee()
{
return this.mTechFee;
}
public void calcTuition()
{
double t=this.getCredits()*TuitionConstants.ONLINE_CREDIT_RATE;
if(this.getTechFee())t+=TuitionConstants.ONLINE_TECH_FEE;
this.setTuition(t);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.