Ask Question
12 December, 18:42

Define a class named Doctor whose objects are records for a clinic's doctors. Derive this class from the class Person given in Lesson. 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 an office-visit fee (use the type double). Give your class a reasonable complement of constructors and accessor methods. Write a driver program to test all your methods.

+3
Answers (1)
  1. 12 December, 19:02
    0
    Following is defined the required class having accessor methods and test program:

    Explanation:

    class Person

    {

    private String doc_name;

    public Person (String doc_name)

    {

    this. doc_name = doc_name;

    }

    public String getDoc_Name ()

    {

    return doc_name;

    }

    }

    class Doctor extends Person

    {

    private double office_visit_fee;

    private String Specialty;

    public Doctor (String doc_name, double office_visit_fee, String Specialty)

    {

    super (doc_name);

    this. office_visit_fee = office_visit_fee;

    this. Specialty = Specialty;

    }

    //accessor methods

    public double getOffice_Visit_Fee ()

    {

    return office_visit_fee;

    }

    public String getSpecialty ()

    {

    return Specialty;

    }

    public String toString ()

    {

    return "Doctor Name "+getDoc_Name () + " Office Visit Fee : $"+office_visit_fee+

    " Specialty : "+Specialty;

    }

    }

    class Test

    {

    public static void main (String[] args)

    {

    Doctor dctr = new Doctor ("Joseph Lister",134.56,"Obstetrician");

    System. out. println (dctr);

    }

    }

    Output:

    Doctor Name Joseph Lister Office Visit Fee : $134.56 Speciality : Obstetrician
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Define a class named Doctor whose objects are records for a clinic's doctors. Derive this class from the class Person given in Lesson. A ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers