The following is a definition of a class named Doctor that I created whose objects are records for a clinic’s doctors. This class is derived from the Person class I have also included below. The Doctor record has the doctor’s name (Inherited from the Person class), specialty (i.e. “Pediatrician”, “General Practitioner”), and office visit fee. I want to be sure my class has a reasonable complement of constructors and accessor methods and is accurate since I am new at this. Do you think it meets these requirements? Also, I have an error (not an expression statement) at the line that says: super(); Does anyone know what I am doing wrong there?
Thanks!
BASE CLASS:
public class Person
{
private String name;
public Person()
{
name = "No name yet.";
}
public Person(String initialName)
{
name = initialName;
}
public void setName(String newName)
{
name = newName;
}
public String getName()
{
return name;
}
public void writeOutput()
{
System.out.println("Name: " + name);
}
public boolean sameName(Person otherPerson)
{
return (this.name.equalsIgnoreCase(otherPerson.name));
}
}
DERIVED CLASS:
public class Doctor extends Person
{
private string specialty;
private double officeVisitFee;
public Doctor()
{
super();
specialty;
officeVisitFee = 0;//Indicating no number yet
}
public Doctor(String initialName, String specialty, double initialOfficeVisitFee)
{
super(initialName);
specialty = initialSpecialty;
officeVisitFee = initialOfficeVisitFee;
}
public void reset(String newName, String specialty, double newOfficeVisitFee)
{
setName(newName);
specialty = newSpecialty;
officeVisitFee = newOfficeVisitFee;
}
public double getOfficeVisitFee()
{
return officeVisitFee;
}
public void setOfficeVisitFee(double newOfficeVisitFee)
{
officeVisitFee = newOfficeVisitFee;
}
public void writeOutput()
{
System.out.println("Name: " + getName());
System.out.println("Specialty: " + getSpecialty());
System.out.println("Office Visit Fee : " + officeVisitFee);
}
public boolean equals(Doctor otherDoctor)
{
return (this.sameName(otherDoctor)
&& (this.officeVisitFee == otherDoctor.officeVisitFee));
}
}
Thanks!
BASE CLASS:
public class Person
{
private String name;
public Person()
{
name = "No name yet.";
}
public Person(String initialName)
{
name = initialName;
}
public void setName(String newName)
{
name = newName;
}
public String getName()
{
return name;
}
public void writeOutput()
{
System.out.println("Name: " + name);
}
public boolean sameName(Person otherPerson)
{
return (this.name.equalsIgnoreCase(otherPerson.name));
}
}
DERIVED CLASS:
public class Doctor extends Person
{
private string specialty;
private double officeVisitFee;
public Doctor()
{
super();
specialty;
officeVisitFee = 0;//Indicating no number yet
}
public Doctor(String initialName, String specialty, double initialOfficeVisitFee)
{
super(initialName);
specialty = initialSpecialty;
officeVisitFee = initialOfficeVisitFee;
}
public void reset(String newName, String specialty, double newOfficeVisitFee)
{
setName(newName);
specialty = newSpecialty;
officeVisitFee = newOfficeVisitFee;
}
public double getOfficeVisitFee()
{
return officeVisitFee;
}
public void setOfficeVisitFee(double newOfficeVisitFee)
{
officeVisitFee = newOfficeVisitFee;
}
public void writeOutput()
{
System.out.println("Name: " + getName());
System.out.println("Specialty: " + getSpecialty());
System.out.println("Office Visit Fee : " + officeVisitFee);
}
public boolean equals(Doctor otherDoctor)
{
return (this.sameName(otherDoctor)
&& (this.officeVisitFee == otherDoctor.officeVisitFee));
}
}