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

Define a class named Doctor whose objects are records for clinic’s doctors. Deri

ID: 3938288 • Letter: D

Question

Define a class named Doctor whose objects are records for clinic’s doctors. Derive this class from the class Person given in listing 8. A Doctor record has the doctor’s name—defined in the class Person—A specialty as a string (for example Pediatrician, Obstetrician, General Practitioner, and so on), and office visit fee (use type double). Give your class has a reasonable complement of constructors, accessor methods and an equals method as well. Write a driver program to test all your methods.

this is the test file

modify this to make the test file work

Explanation / Answer

//class doctor extended from person
class Doctor extends Person
{
    //instnace variables
    String specialty;
    double fee;
    //default construtor
    public Doctor()
    {
        super();
        specialty="";
        fee=0;
    }
    //parameterized contstructor with name as paratemetr
    public Doctor(String n)
    {
        super(n);
        specialty="";
        fee=0;
    }
    //constructor accepting name and specialty
    public Doctor(String n,String s)
    {
        super(n);
        specialty=s;
        fee=0;
    }
    //constructor accepting name and fee
    public Doctor(String n,double f)
    {
        super(n);
        specialty="";
        fee=f;
    }
    //constructor accepting name,fee and specialy
    public Doctor(String n,double f,String s)
    {
        super(n);
        specialty=s;
        fee=f;
    }
    //method to set variables for doctor
    public void set(String n,double f,String s)
    {
        set(n);
        specialty=s;
        fee=f;
    }
    //setter for fee
    public void setOfficeFee(double f)
    {
        fee=f;
    }
    //setter for spciality
    public void setSpecialty(String s)
    {
        specialty=s;
    }
    //getter for speciality
    public String getSpecialty()
    {
        return specialty;
    }
    //getter for fee
    public double getOfficeFee()
    {
        return fee;
    }
    //set fee
     public void writeOfficeFee()
    {
        fee=0;
    }
    //set specislity
    public void writeSpecialty()
    {
        specialty="No specialty yet.";
    }
    //compare two doctor objects
    public boolean equals(Doctor d)
    {
        return hasSameName(d) && fee==d.fee && specialty.equals(d.specialty);
    }
    //display doctor detais
     public void writeOutput()
    {
        super.writeOutput();
        System.out.println("Speciality: " +specialty);
        System.out.println("Fee: "+fee);
    }
}

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 void set(String newName)
    {
        name = newName;
    }
    public void writeName()
    {
        name = "No name yet.";
    }
  

    public String getName()
    {
        return name;
    }

    public void writeOutput()
    {
        System.out.println("Name: " + name);
    }

    public boolean hasSameName(Person otherPerson)
    {
        return (this.name.equalsIgnoreCase(otherPerson.getName()));
    }
}

import java.util.*;
public class DoctorTest{

     public static void main(String []args){
         Scanner keyboard = new Scanner(System.in);
    
      char repeat;
      do // repeat if user says 'yes'
      {
         // Test the six constructors (uses writeOutput method)

         Doctor drNo = new Doctor();
         System.out.println("Using default constructor:");
         System.out.println();
         System.out.println("Verify:");
         System.out.println("No name yet.");
         System.out.println("$150");
         System.out.println("None given");
         System.out.println();
         drNo.writeOutput();
         System.out.println();
         System.out.println("===============================");

         System.out.println("Using constructor with just name:");
         Doctor drJekyl = new Doctor("Jekyl");
         System.out.println();
         System.out.println("Verify:");
         System.out.println("Jekyl");
         System.out.println("$150");
         System.out.println("None given");
         System.out.println();
         drJekyl.writeOutput();
         System.out.println();
         System.out.println("===============================");

         System.out.println("Constructor with name & office fee :");
         Doctor drKildare = new Doctor("Kildare", 200.99);
         System.out.println();
         System.out.println("Verify:");
         System.out.println("Kildare");
         System.out.println("$200.99");
         System.out.println("None assigned");
         System.out.println();
         drKildare.writeOutput();
         System.out.println();
         System.out.println("===============================");

         System.out.println("Constructor with name and specialty:");
         Doctor drWelby = new Doctor("Welby", "General Practioner");
         System.out.println();
         System.out.println("Verify:");
         System.out.println("Welby");
         System.out.println("$150");
         System.out.println("General Practitioner");
         System.out.println();
         drWelby.writeOutput();
         System.out.println();
         System.out.println("===============================");

         System.out.println
            ("Constructor with name, office fee, and specialty:");
         Doctor drHoliday = new Doctor("Holiday", 5.25, "Dentist");
         System.out.println();
         System.out.println("Verify:");
         System.out.println("Holiday");
         System.out.println("$5.25");
         System.out.println("Dentist");
         System.out.println();
         drHoliday.writeOutput();
         System.out.println();
         System.out.println();
         System.out.println("===============================");

         //Test the other three write methods

         System.out.println("Write name test:");
         System.out.println();
         System.out.println("Verify:");
         System.out.println("Name: Holiday");
         System.out.println();
         drHoliday.writeName();
         System.out.println();
         System.out.println();
         System.out.println("===============================");

         System.out.println("Write office fee test:");
         System.out.println();
         System.out.println("Verify:");
         System.out.println("Office Fee: $5.25");
         System.out.println();
         drHoliday.writeOfficeFee();
         System.out.println();
         System.out.println();
         System.out.println("===============================");

         System.out.println("Write specialty test:");
         System.out.println();
         System.out.println("Verify:");
         System.out.println("Specialty: Dentist");
         System.out.println();
         drHoliday.writeSpecialty();
         System.out.println();
         System.out.println();
         System.out.println("===============================");


         //Test the four set methods

         System.out.println
                 ("Set name, office fee, and specialty:");
         System.out.println();
         System.out.println("Default parameter values before set:");
         drNo.writeOutput();
         System.out.println();
         drNo.set("No", 1234.56, "Laser Surgery");
         System.out.println("Verify parameter values after set:");
         System.out.println("No");
         System.out.println("$1234.56");
         System.out.println("Laser Surgery");
         System.out.println();
         drNo.writeOutput();
         System.out.println();
         System.out.println("===============================");

         System.out.println("Set name test:");
         System.out.println();
         System.out.println("Parameter values before set:");
         drNo.writeOutput();
         System.out.println();
         drNo.setName("Yes");
         System.out.println("Parameter values after set:");
         System.out.println("Verify Name: Yes");
         System.out.println();
         drNo.writeOutput();
         System.out.println();
         System.out.println();
         System.out.println("===============================");

         System.out.println("Set office fee test:");
         System.out.println();
         System.out.println("Parameter values before set:");
         drNo.writeOutput();
         System.out.println();
         drNo.setOfficeFee(987.65);
         System.out.println("Parameter values after set:");
         System.out.println("Verify Office Fee: $987.65");
         System.out.println();
         drNo.writeOutput();
         System.out.println();
         System.out.println();
         System.out.println("===============================");

         System.out.println("Set specialty test:");
         System.out.println();
         System.out.println("Parameter values before set:");
         drNo.writeOutput();
         System.out.println();
         drNo.setSpecialty("Psychiatry");
         System.out.println("Parameter values after set:");
         System.out.println("Verify Specialty: Psychiatry");
         System.out.println();
         drNo.writeOutput();
         System.out.println();
         System.out.println();
         System.out.println("===============================");

         //Test the three get methods

         System.out.println("Get name test:");
         System.out.println();
         System.out.println("Verify Yes");
         System.out.println();
         System.out.println(drNo.getName());
         System.out.println();
         System.out.println();
         System.out.println("===============================");

         System.out.println("Get office fee test:");
         System.out.println();
         System.out.println("Verify 987.65");
         System.out.println();
         System.out.println(drNo.getOfficeFee());
         System.out.println();
         System.out.println();
         System.out.println("===============================");

         System.out.println("Get specialty test:");
         System.out.println();
         System.out.println("Verify Psychiatry");
         System.out.println();
         System.out.println(drNo.getSpecialty());
         System.out.println();
         System.out.println();
         System.out.println("===============================");

         // test equals

         System.out.println("equals test 1:");
         System.out.println();
         //Create second Doctor with same values as drNo
         Doctor drYes = new Doctor("Yes", 987.65, "Psychiatry");
         System.out.println("First Doctor's parameter values:");
         System.out.println();
         drNo.writeOutput();
         System.out.println();
         System.out.println("Second Doctor's parameter values:");
         System.out.println();
         drYes.writeOutput();
         System.out.println("Verify true");
         System.out.println();
         System.out.println(drNo.equals(drYes));
         System.out.println();
         System.out.println();
         System.out.println("===============================");

         System.out.println("equals test 2:");
         System.out.println();
         //Change office fee of drYes
         drYes.setOfficeFee(987.66);
         System.out.println("First Doctor's parameter values:");
         System.out.println();
         drNo.writeOutput();
         System.out.println();
         System.out.println("Second Doctor's parameter values:");
         System.out.println();
         drYes.writeOutput();
         System.out.println("Verify false");
         System.out.println();
         System.out.println(drNo.equals(drYes));
         System.out.println();
         System.out.println();
         System.out.println("===============================");

         System.out.println("equals test 3:");
         System.out.println();
         //Change office fee back to 987.65
         //and specialty to psychology
         drYes.setOfficeFee(987.65);
         drYes.setSpecialty("Psychololgy");
         System.out.println("First Doctor's parameter values:");
         System.out.println();
         drNo.writeOutput();
         System.out.println();
         System.out.println("Second Doctor's parameter values:");
         System.out.println();
         drYes.writeOutput();
         System.out.println("Verify false");
         System.out.println();
         System.out.println(drNo.equals(drYes));
         System.out.println();
         System.out.println();
         System.out.println("===============================");

         System.out.println("Do again? (Y for Yes, or N for No)");
         repeat = keyboard.next().charAt(0);

      }while((repeat == 'y') || (repeat == 'Y'));
     }
}

Sample output:

equals test 3:                                                                                                                                                  

                                                                                                                                                                

First Doctor's parameter values:                                                                                                                                

                                                                                                                                                                

Name: Yes                                                                                                                                                       

Speciality: Psychiatry                                                                                                                                          

Fee: 987.65                                                                                                                                                     

                                                                                                                                                                

Second Doctor's parameter values:                                                                                                                               

                                                                                                                                                                

Name: Yes                                                                                                                                                       

Speciality: Psychololgy                                                                                                                                         

Fee: 987.65                                                                                                                                                     

Verify false                                                                                                                                                    

                                                                                                                                                                

false                                                                                                                                                           

                                                                                                                                                                

                                                                                                                                                                

===============================                                                                                                                                 

Do again? (Y for Yes, or N for No)                                                                                                                              

No                

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote