Question

In: Computer Science

Problem 6: (20 pts) Create two subclasses called outpatient and inpatient which inherit from the patient...

Problem 6: (20 pts) Create two subclasses called outpatient and inpatient which inherit from the patient base class. The outpatient class has an additional data field called doctorOfficeID and the inpatient class has an additional data item called hospitalID. Write a main method that creates inpatient and outpatient objects. Sets data for these objects and display the data.

Solutions

Expert Solution

import java.io.*;


class patient{
        String name,healthIssue,arrivalDate;
        int age;
        //constructor
        patient(String name,int age,String healthIssue,String arrivalDate){
                this.name = name;
                this.age = age;
                this.healthIssue = healthIssue;
                this.arrivalDate = arrivalDate;
        }
}

class outpatient extends patient{
        int doctorOfficeID;
        //constructor
        outpatient(String name,int age,String healthIssue,String arrivalDate,int doctorOfficeID){
                super(name,age,healthIssue,arrivalDate);
                this.doctorOfficeID = doctorOfficeID;
        }
        void display() {
                System.out.println("Name: " + name);
                System.out.println("Age: " + age);
                System.out.println("Health Issue: " + healthIssue);
                System.out.println("Arrival Date: " + arrivalDate);
                System.out.println("Doctor Office ID: " + doctorOfficeID + "\n");       
        }
}

class inpatient extends patient{
int hospitalID;
        //constructor
        inpatient(String name,int age,String healthIssue,String arrivalDate,int hospitalID){
                super(name,age,healthIssue,arrivalDate);
                this.hospitalID = hospitalID;
        }
        
        void display() {
                System.out.println("Name: " + name);
                System.out.println("Age: " + age);
                System.out.println("Health Issue: " + healthIssue);
                System.out.println("Arrival Date: " + arrivalDate);
                System.out.println("Hospital ID: " + hospitalID + "\n");        
        }
}

class Main{
        // **************MAIN METHOD************** 
                
                public static void main(String[] args) 
                { 
                        outpatient p1 = new outpatient("Adam Stal",27,"Sickness","10/04/2018",353546);
                        
                        inpatient p2 = new inpatient("Mary Joe",44,"Stomach Ache","12/08/2015",543466);
                        
                        // Printing details of the patients
                        p1.display();
                        p2.display();
                }
                
}

OUTPUT:


Related Solutions

-------------- WRITE IN C# ------------------- Create two subclasses called outpatient and inpatient which inherit from the...
-------------- WRITE IN C# ------------------- Create two subclasses called outpatient and inpatient which inherit from the patient base class. The outpatient class has an additional data field called doctorOfficeID and the inpatient class has an additional data item called hospitalID. Write a main method that creates inpatient and outpatient objects. Sets data for these objects and display the data.
Problem 2: (20 pts) Create a Patient class which has private fields for patientid, lastname, firstname,...
Problem 2: (20 pts) Create a Patient class which has private fields for patientid, lastname, firstname, age, and email. Create public data items for each of these private fields with get and set methods. The entire lastname must be stored in uppercase. Create a main class which instantiates a patient object and sets values for each data item within the class. Display the data in the object to the console window
Part 3: Anagram Arranger (20 pts) Overview Create a file called Anagram.java, which reads a series...
Part 3: Anagram Arranger (20 pts) Overview Create a file called Anagram.java, which reads a series of words input from a file. For each word read from the file, the user will have the option to swap letters within that word. You are required to use your doubly-linked list class to receive credit for this part of the assignment. Therefore, your word should be stored as a List of Characters or Strings (each String being one letter). After the user...
6 Problem 2 (20 pts) The SPAD XIII was a fighter plane used by various countries,...
6 Problem 2 (20 pts) The SPAD XIII was a fighter plane used by various countries, including the United States, during World War I. It had a 97 kg wooden propeller that was 2.5 m long and 15 cm wide and 9 cm thick. A Vickers 7.7 mm machine gun mounted on the front, which used a timing belt to fire between the propeller blades at a rate of 500 rounds/minute. The gun is mounted halfway between the engine shaft...
Problem 1 [20 pts]: An experiment consists of tossing a coin 6 times. Let X be...
Problem 1 [20 pts]: An experiment consists of tossing a coin 6 times. Let X be the random variable that is the number of heads in the outcome. Find the mean and variance of X. Thank You
Programming Problem 2 - Cycle [A] Create a class called “Cycle” which has two instance integer...
Programming Problem 2 - Cycle [A] Create a class called “Cycle” which has two instance integer variables as properties, “numberOfWheels” and “weight.” Create a constructor with two parameters, using the same variable names in the parameter list. Assign each variable to numberOfWheels” and “weight” respectively. Write a separate application to test the class and display its properties. Note: Do not change the names of the instance variables or the variables listed in the constructor’s parameter list. [B] Edit your class...
PROBLEM 2. 20 pts. An urn contains 4 Red balls and 6 Green balls. If 4...
PROBLEM 2. 20 pts. An urn contains 4 Red balls and 6 Green balls. If 4 balls are taken one at a time with replacement. Find the probability that one is R. Find also the expected number of R and the standard deviation of R If 4 two balls are taken one at a time without replacement. Find the probability that only one is Red
Problem 5: (10 pts) Modify the patient class with two overloaded methods to display a bill...
Problem 5: (10 pts) Modify the patient class with two overloaded methods to display a bill for astandard visit based on age. In the first method do not use any parameters to pass in data. If the patient is over 65, then a standard visit is $75. If the patient is under 65, then the standard doctors office visit is $125. Build a second method where you pass in a discount rate. If the patient is over 65, then apply...
PROBLEM 2.  20 pts.  An urn contains 4 Red balls and 6 Green balls. If 4 balls are...
PROBLEM 2.  20 pts.  An urn contains 4 Red balls and 6 Green balls. If 4 balls are taken one at a time with replacement. Find the probability that one is R. Find also the expected number of R and the standard deviation of R If 4 two balls are taken one at a time without replacement. Find the probability that only one is Red
Problem 1. (20 Pts) Two storage structures, given code names Y and Z, are being considered...
Problem 1. (20 Pts) Two storage structures, given code names Y and Z, are being considered for a military base. The military uses a 6% percent/year expected rate of return and a 24-year life for decisions of this type. The relevant characteristics for each structure are shown below. Structure Y Structure Z First Cost 24225 24225 Estimated Life 12 years 24 years Estimated Salvage Value None $1,800 Annual Maintenance Cost $1,000 $720 a) What is the future worth of each...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT