Question: Write Java code to define a class that represents a Person (Person.java). The attributes should be the first name, last name, middle initial (a single
Write Java code to define a class that represents a Person (Person.java). The attributes should be the first name, last name, middle initial (a single character) and gender (a string such as male or female).
a. Define a constructor without parameters that sets appropriate initial values for the attributes.
b. Define a constructor with parameters that sets appropriate initial values for the attributes based on the given parameters.
c. Define a method that prints the values of the attributes.
d. Define a toString method that returns the value of all of the attributes.
Write Java code to define a class that represents a Doctor (Doctor.java), inherited from the class Person. This class will have an attribute to store a doctors specialty (Anesthesiologist, Cardiologist, etc.).
Define appropriate constructors and methods to initialize, access, and manipulate the data members.
Write Java code to define a class that represents a Patient (Patient.java), inherited from the class Person. This class will have an attribute to store a patients identification number and age.
Define appropriate constructors and methods to initialize, access, and manipulate the data members.
Define a method that prints the values of the attributes.
Write a test class (Anynameyouwant.java) to create objects from the Person, Doctor and Patient classes and exercise all of the methods of your classes.
For example, you should be able to show how you would create a Patient object and show how you would set the name and gender.
You should think about several different process of creating objects. In order to receive full credit, your code must have a good set of testing. A couple of lines of code in your main method wont grant much credit.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
