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:

  1. A method named isFull() that returns true if all the beds are occupied, and false if there are available beds.
  2. 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:

  1. Create a hospital instance with these details: Al-Seha, Physiotherapy, totalBeds = 500 and occupiedBeds = 350.
  2. Print details of the above hospital and the number of available beds, properly labeled.
  3. Create another hospital instance for the Hospital: Sidra, Pediatrics, totalBeds = 1000 and occupiedBeds = 500 (yes, the value is negative).
  4. Print the name, the totalBeds, and the availableBeds. for this instance.
  5. Using a getter and a setter, set the occupiedBeds for Sidra to be half the total number of beds.
  6. 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!