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

This question is using Chapter 10 from Java Programming Ed.8th but the actual qu

ID: 3804242 • Letter: T

Question

This question is using Chapter 10 from Java Programming Ed.8th but the actual question is not in the book only examples using "extending classes". I have the three setups we did in class and by using this three setups my question will be below.  

/*                                                                                                                                                                                                                   

* Chapter 10 & 11 -Inheritance
* Interface Class
* Create a patient list for a doctor
*/
package medicaloffice;

import java.util.Scanner;

public class MedicalOffice
{
    //Scanner
    static Scanner kb = new Scanner(System.in);
   
    //Make a Person
    static Person me = new Person();
   
    //Make a Patient]
    static Patient patient1 = new Patient();
   
    //Class Variables
    static String fn, ln, pID;
    static int patientAge;
   
    public static void main(String[] args)
    {
       newPerson();
       newPatient();
    }//end main
   
    //Enter a new Person
    public static void newPerson()
           
    {
       //Input
        System.out.print("Enter the Person's first name: ");
        fn = kb.next();
       
        System.out.print("Enter the Person's last name: ");
        ln = kb.next();
       
        //Using Setter methods
        me.setFirstName(fn);
        me.setLastName(ln);
       
        //Using Getter methods
        System.out.println("Your first name is " + me.getFirstName());
        System.out.println("Your last name is " + me.getLastName());
       
        //Using Output Method
        System.out.println("Your name is " + me.displayName());
       
        System.out.println();
    }//end newPerson()  
   
    //Enter a new Patient
    public static void newPatient()      
    {
       //Input
        System.out.print("Enter the Patient's id: ");
        pID = kb.next();
       
        System.out.print("Enter the Patient's first name: ");
        fn = kb.next();
       
        System.out.print("Enter the Patient's last name: ");
        ln = kb.next();
       
        System.out.print("Enter Patient's age: ");
        patientAge = kb.nextInt();

        //Using Setter methods
        patient1.setPatientID(pID);
        patient1.setFirstName(fn);
        patient1.setLastName(ln);
        patient1.setAge(patientAge);
       
        //Using Getter methods
        System.out.println("Your first name is " + me.getFirstName());
        System.out.println("Your last name is " + me.getLastName());
       
        //Using Output Methods
        System.out.println();
        System.out.println("Your patient ID name is " + patient1.getPatientID());
        System.out.println("Your patient's first name is " + patient1.getFirstName());
        System.out.println("Your patient's name is " + patient1.getLastName());
        System.out.println("Your age is " + patient1.getAge());
       
        //Use output method
        System.out.println("Your patient information is " + patient1.displayName());
    }//end newPatient  
}//end class

*********** Part 2.******************

/*

* Patient Class Definition
* Set and Get patientID, name and age of Patient
*/
package medicaloffice;

public class Patient extends Person //pg 496
{
    //Instance Variable
    private String patientID;
    private int age;
   
    //Constructor
    public Patient()
    {
        super(); //pg 514
        patientID = "";
        age = 0;
    }//end patient

    //Setter Methods
    public void setPatientID(String patientID)
    {
        this.patientID = patientID;
    }//end setPatientID()
   
    public void setAge(int age)
    {
        this.age = age;
    }//end setAge()
   
    //Getter Methods
    public String getPatientID()
    {
        return patientID;
    }//end getPatientID
   
    public int getAge()
    {
        return age;
    }//end getAge
   
    //Display Name
    @Override //pg 504
    public String displayName()
    {
        return patientID + ": " + super.displayName() + ", " + age;
    }//end displayName()
}//end class

*********** Part 3.******************

/*
* Person Class Definition
* Set and Get name of a Person
*/
package medicaloffice;


public class Person
{
    //Instance Variables
    String firstName, lastName;
   
    //Constructor use setter methods
    public Person()
    {
        firstName = "";
        lastName = "";
    }//end constructor
   
    //Setter Methods
    public void setFirstName(String firstName)
    {
        this.firstName = firstName;
    }//end setFirstName
   
    public void setLastName(String lastName)
    {
        this.lastName = lastName;
    }//end setFirstName
   
    //Getter Methods
    public String getFirstName()
    {
         return firstName;      
    }//end getFirstName
   
     public String getLastName()
    {
         return lastName;      
    }//end getLastName
   
     //Display Name]
     public String displayName()
     {
         return firstName + " " + lastName;
     }//end displayName ()
}//end person

This is the question:

1. Using the MedicalOffice project we completed in class, create a Doctor sublcass (extends Person) with a data field for "specialty" (ie , surgeon, pediatric, etc) and a constructor with no parameters which asks the user for the values then sets the values with setter method(s).  

2. Write another method which overrides the displayName() method in Person to display the Doctor's name along with specialty.

3. Using the same Interface we created in class, create an instance of the Doctor: use the setter & getter method to add the doctor information.

4. Call the override displayName method for each instance of Doctor

Explanation / Answer

please find the code

Doctor Class

/*
* Doctor's Class Definition
* Set and Get name, speciality of a Doctor
*/

package medicaloffice;

import java.util.Scanner;

public class Doctor extends Person {
   String speciality;
   public Doctor(){
      
   }
   public String getSpeciality() {
       return speciality;
   }
   public void setSpeciality(String speciality) {
       this.speciality = speciality;
   }
  
   public String displayName()
{
       return this.getFirstName()+" "+this.getLastName()+" is a specialist in "+this.getSpeciality();
}
  
}

MedicalOffice.java with new function newDoctor()

package medicaloffice;

import java.util.Scanner;

public class MedicalOffice
{
//Scanner
static Scanner kb = new Scanner(System.in);

//Make a Person
static Person me = new Person();

//Make a Patient]
static Patient patient1 = new Patient();

//Class Variables
static String fn, ln, pID;
static int patientAge;

public static void main(String[] args)
{
newPerson();
newPatient();
newDoctor();
}//end main

//Enter a new Dcotor
public static void newDoctor()
  
{
   Doctor d = new Doctor();
  
//Input
System.out.print("Enter the Person's first name: ");
fn = kb.next();

System.out.print("Enter the Person's last name: ");
ln = kb.next();
System.out.println("Enter speciality of doctor");
String speciality = kb.next();
  
  
//Using Setter methods
d.setFirstName(fn);
d.setLastName(ln);
d.setSpeciality(speciality);
//Using Getter methods
System.out.println("Your first name is " + d.getFirstName());
System.out.println("Your last name is " + d.getLastName());

//Using Output Method
System.out.println("Your name is " + d.displayName());

System.out.println();
}//end newDoctor()
//Enter a new Person
public static void newPerson()

{
//Input
System.out.print("Enter the Person's first name: ");
fn = kb.next();

System.out.print("Enter the Person's last name: ");
ln = kb.next();

//Using Setter methods
me.setFirstName(fn);
me.setLastName(ln);

//Using Getter methods
System.out.println("Your first name is " + me.getFirstName());
System.out.println("Your last name is " + me.getLastName());

//Using Output Method
System.out.println("Your name is " + me.displayName());

System.out.println();
}//end newPerson()

//Enter a new Patient
public static void newPatient()
{
//Input
System.out.print("Enter the Patient's id: ");
pID = kb.next();

System.out.print("Enter the Patient's first name: ");
fn = kb.next();

System.out.print("Enter the Patient's last name: ");
ln = kb.next();

System.out.print("Enter Patient's age: ");
patientAge = kb.nextInt();
//Using Setter methods
patient1.setPatientID(pID);
patient1.setFirstName(fn);
patient1.setLastName(ln);
patient1.setAge(patientAge);

//Using Getter methods
System.out.println("Your first name is " + me.getFirstName());
System.out.println("Your last name is " + me.getLastName());

//Using Output Methods
System.out.println();
System.out.println("Your patient ID name is " + patient1.getPatientID());
System.out.println("Your patient's first name is " + patient1.getFirstName());
System.out.println("Your patient's name is " + patient1.getLastName());
System.out.println("Your age is " + patient1.getAge());

//Use output method
System.out.println("Your patient information is " + patient1.displayName());
}//end newPatient
}//end class

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