我試圖創建一個超類,它存儲了存儲常用方法的類InPatient和OutPatient的詳細信息。我設法移動了id域,沒有任何問題,但在轉向藥物治療時卻掙扎不已。在setMedication方法改變將accessor和mutator方法從一個類移動到它的超類
this.medication = medication;
時
this.getMedication() = medication;
有人告訴我,我應該插入一個變量而不是一個值,但無法弄清楚什麼變量我應該把在它的位置來代替。
我有類住院:
public class InPatient extends Patient
{
// The condition of the patient.
private String status;
// Whether the patient is cured or not.
private boolean cured;
public InPatient(String base, String id)
{
status = base;
cured = true;
}
/**
* Set the patient's medication
* The patient is no longer cured
*/
public void book(String medication)
{
setMedication(medication);
cured = false;
}
/**
* Show the patients details.
*/
public String getDetails()
{
return getID() + " at " + status + " headed for " +
getMedication();
}
/**
* Patient's status.
*/
public String getStatus()
{
return status;
}
/**
* Set the patient's medication.
*/
public void setMedication(String medication)
{
this.getMedication() = medication;
}
/**
* Show that the patient is cured
*/
public void better()
{
status = medication;
medication = null;
cured = true;
}
}
,它的超病人:
/**
* Write a description of class Patient here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Patient
{
// Patient's ID.
private String id;
// Medication the patient is on.
private String medication;
/**
* Constructor for objects of class Patient
*/
public Patient()
{
this.id = id;
medication = null;
}
/**
* The patient's ID.
*/
public String getID()
{
return id;
}
/**
* Patient's medication
*/
public String getMedication()
{
return medication;
}
}
它是什麼,我在這裏失蹤?