일반적인 메서드를 저장하는 클래스 InPatient 및 OutPatient에 대한 세부 정보를 저장하는 수퍼 클래스를 만들려고합니다. 나는 id 필드를 넘어서 아무 문제없이 움직일 수 있었지만 약물 치료를하는 데 있어서는 어려움을 겪고있다. setMedication 방법에 내가 변수 대신 값을 삽입해야하지만 대신 장소에 나는 퍼팅해야 어떤 변수 알아낼 수 없다는 이야기입니다한 클래스에서 수퍼 클래스로 액세서 및 변경자 메서드 이동
this.getMedication() = medication;
에
this.medication = 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;
}
}
그것이 내가 여기에 누락 것이 무엇입니까?