Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transactions On Large Scale Data And Knowledge Centered Systems Xxviii Special Issue On Database And Expert Systems Applications Lncs 9940

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Qimin Chen

1st Edition

3662534541, 978-3662534540

More Books

Students also viewed these Databases questions