Question
The purpose of this lab is to write Java code over the following topics: To implement a seperate class according to specifications To implement a
The purpose of this lab is to write Java code over the following topics:
To implement a seperate class according to specifications
To implement a class using an interface.
To understand iterative development.
Java Programming
Create a new Java Project named R15
Copy R15Admit.java into the project.
Copy R15Interface.java into the project.
Create a class called R15Room and have it implement R15Interface.
The TA will help you do this.
Declare two private instance variables
An int called roomBeds to hold the number of beds
A boolean called roomMonitor that describes whether the room has a heart monitor
Write the methods in the interface according to the pre and post conditions in the interface.
Create a set of test cases in the main method that test your methods.
Once your code passes your test cases, run your code using R15Admit.
R15Admit.java
import java.util.Scanner; // R15 Assignment // Author: Russ Wakefield // Date: April 1, 2017 // Class: CS163 // Email: waker@cs.colostate.edu public class R15Admit { public static void main(String[] args) { /* * This program: * 1) Initializes the rooms * 2) gathers the information that about a patient's need * 3) checks to see what rooms fulfills the patient's needs */ String answer = ""; boolean needsMonitor = false; boolean needsSingle = false; R15Interface room0 = new R15Room(); R15Interface room1 = new R15Room(); R15Interface room2 = new R15Room(); room0.R15Init(0); room1.R15Init(1); room2.R15Init(2); //What are the patient's needs? Scanner kb = new Scanner(System.in); System.out.print ("Does the patient need a heart monitor ?"); answer = kb.next().toLowerCase(); if (answer.charAt(0) == 'y') needsMonitor = true; System.out.print ("Does the patient need a single room?" ); answer = kb.next().toLowerCase(); if (answer.charAt(0) == 'y') needsSingle = true; //Let's find a room if (room0.checkRoom(needsMonitor, needsSingle)) System.out.println ("Room 0 fits the needs"); else if (room1.checkRoom(needsMonitor, needsSingle)) System.out.println ("Room 1 fits the needs"); else if (room2.checkRoom(needsMonitor, needsSingle)) System.out.println ("Room 2 fits the needs"); else System.out.println ("No rooms fit the needs"); kb.close(); } }
R15Interface.java
// R15 Assignment // Author: Russ Wakefield // Date: April 1, 2017 // Class: CS163 // Email: waker@cs.colostate.edu public interface R15Interface { /* * Method - R15Init * precondition - 0 <= roomType <= 2 * postcondition - room initialized with the correct attributes. * Type 0 - has 1 bed and a heart monitor * Type 1 - has 2 beds and a heart monitor * Type 2 - has 1 bed and no heart monitor */ public void R15Init(int roomType); /* * Method - checkRoom * Precondition - this room has been initialized to its appropriate attributes * Precondition - needsMonitor is set to t/f based on the need for a heart monitor * Precondition - needsSingle is set to t/f based on the need for a Single Room * Postcondition - returns true if the necessary equipment is available. * Note, if the patient does not need a heart monitor, we want to save * it for someone that does need it - same with the single bed. This * means the requirements should directly match the room. */ public boolean checkRoom(boolean needsMonitor, boolean needsSingle); /* * Method - getRoomBeds() * Precondition - this room has been initialized to its appropriate attributes * Postcondition - returns the number of beds in the room. */ public int getRoomBeds(); /* * Method - setRoomBeds(int numBeds) * Precondition - this room has been initialized to its appropriate attributes * Postcondition - sets the number of beds in the room to numBeds. */ public void setRoomBeds(int numBeds); /* * Method - getRoomMonitor() * Precondition - this room has been initialized to its appropriate attributes * Postcondition - returns true if the room has a heart monitor, false if not. */ public boolean getRoomMonitor(); /* * Method - setRoomMonitor(boolean hasMonitor) * Precondition - this room has been initialized to its appropriate attributes * Postcondition - sets value of whether the room has a heart monitor appropriately. */ public void setRoomMonitor(boolean hasMonitor); }
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