Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Step: 3

blur-text-image

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

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

13th Edition Global Edition

1292263350, 978-1292263359

More Books

Students also viewed these Databases questions

Question

1. Identify what positions are included in the plan.

Answered: 1 week ago

Question

2. Identify the employees who are included in the plan.

Answered: 1 week ago