Question
please solve it in 15 min Create a class called Hospital . A Hospital is described by four pieces of private information as instance variables
please solve it in 15 min
Create a class called Hospital. A Hospital is described by four pieces of private information as instance variables: the hospital name (String), specialty (String), totalBeds that represents the total number of beds (int), and occupiedBeds (int).
Provide a set and a get method for each instance variable. For the setters: if the totalBeds is not positive, it should be set to 500. The occupiedBeds must be positive, and it should not be greater than the totalBeds. Otherwise, it should be set to 0.
Your class should have one constructor that properly initializes the three instance variables. In addition, provide the following methods:
- A method named isFull() that returns true if all the beds are occupied, and false if there are available beds.
- A method named getAvailableBeds() that returns 0 if the hospital is full. Otherwise, it returns the number of available beds.
Write an application named HospitalTest to test Hospital class. In the HospitalTest do the following:
- Create a hospital instance with these details: Al-Seha, Physiotherapy, totalBeds = 500 and occupiedBeds = 350.
- Print details of the above hospital and the number of available beds, properly labeled.
- Create another hospital instance for the Hospital: Sidra, Pediatrics, totalBeds = 1000 and occupiedBeds = 500 (yes, the value is negative).
- Print the name, the totalBeds, and the availableBeds. for this instance.
- Using a getter and a setter, set the occupiedBeds for Sidra to be half the total number of beds.
- Re-print the name and the totalBeds, and the availableBeds of Sidra after setting the occupiedBeds.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started