Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Objective: Define a class named Doctor whose objects are records for a clinics d

ID: 3566970 • Letter: O

Question

Objective:  

Define a class named Doctor whose objects are records for a clinics doctors. Derive the class from the class Person.

A Doctor record has the doctors name defined in the class Person a specialty (such as Pediatrician, Obstetrician, etc.), and an office visit fee (use double). Give your class a set of accessors, mutators (with error checking), constructors, and an equals method.  

Write a separate driver class that tests ALL the methods. This doesnt require any input from the user, as it simply goes through and tests all the methods such as the accessors, mutators,

Example Dialog:

Testing the Doctor Class

Creating Doctor via default constructor

Printing Doctors Information.

Name: No Name Yet.

Specialty: None

Fee: $0

Changing default Doctors name, specialty, and fee via mutators.

Printing Doctors Information.

Name: Tom Baker

Specialty: Time Lord

Fee: $4.95

Creating Doctor via parameterized constructor

Printing Doctors Information.

Name: Albert W. Wiley

Specialty: Robotics

Fee: $1987

Testing if the two doctors are equal.

False

Done!

Explanation / Answer

// Person.java

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 hasSameName(Person otherPerson)
{
return this.name.equalsIgnoreCase(otherPerson.name);
}
}

// Doctor.java

class Doctor extends Person
{
private String specialty;
private double fee;
  

public Doctor(String initialName, String specialty, double fee)
{
super(initialName);
this.specialty = specialty;
this.fee = fee;
}

public Doctor()
{
super();
specialty = "None";
fee = 0;

}
  
public double getFee() {
return fee;
}

public void setFee(double fee) {
this.fee = fee;
}

public String getSpecialty() {
return specialty;
}

public void setSpecialty(String specialty) {
this.specialty = specialty;
}

  
  
@Override
public void writeOutput( )
{
System.out.println("Name: " + getName()+" Specialty: "+specialty+" Fee: $"+fee);
}

@Override
public boolean equals(Object obj)
{

final Doctor other = (Doctor) obj;
  
if(!this.getName().equals(other.getName()))
{
return false;
}
  
if (!this.specialty.equals(other.specialty))
{
return false;
}
if (this.fee != other.fee) {
return false;
}
  
return true;
}


  
  
  
}

// Test Class

public class PersonDriver
{
public static void main(String args[])
{
System.out.println("Testing the Doctor Class Creating Doctor via default constructor ");
Doctor d1 = new Doctor();

System.out.println("Printing Doctor