Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

package qa.edu.qu.cmps251.finaltest; import qa.edu.qu.cmps251.finaltest.do_not_touch.AirPurificationInterface; import qa.edu.qu.cmps251.finaltest.do_not_touch.CommonRoom; public class Check { //Check TODO1 - See handout for expected output public static void testTodo1() { System.out.println(Questions.createHospital()); }

image text in transcribed
image text in transcribed
package qa.edu.qu.cmps251.finaltest;
import qa.edu.qu.cmps251.finaltest.do_not_touch.AirPurificationInterface;
import qa.edu.qu.cmps251.finaltest.do_not_touch.CommonRoom;
public class Check {
//Check TODO1 - See handout for expected output
public static void testTodo1() {
System.out.println(Questions.createHospital());
}
//Check TODO2 - See handout for expected output
public static void testTodo2() {
System.out.println("Number of common rooms: " +
Questions.getNumOfCommonRooms(Questions.createHospital(), 2));
}
//Check TODO3 - See handout for expected output
public static void testTodo3() {
System.out.println("Hepa object returned:");
AirPurificationInterface ap = Questions.getHepaAirPurificationSystem();
if (ap!=null)
System.out.println("Has filter?: " + ap.hasAirPurification() + " type is: " + ap.getTypeOfFilter());
}
//Check TODO4 - See handout for expected output
public static void testTodo4() {
System.out.println("Top free private room is: ");
System.out.println(Questions.topFloorPrivateRoom(Questions.createHospital()));
}
//Check TODO5 - See handout for expected output
public static void testTodo5() {
System.out.println("Parsing lines:");
System.out.println(Questions.returnPrivateRoom("3#2#false"));
System.out.println(Questions.returnPrivateRoom("1#34#true#HEPA"));
}
//Check TODO6 - See handout for expected output
public static void testTodo6() {
System.out.println("Reading from Common_Rooms.dat");
for (CommonRoom cm:Questions.returnCommonRoomsFromObjFile("Common_Rooms.dat")) {
System.out.println(cm.toString());
}
}
}
package qa.edu.qu.cmps251.finaltest;
import java.util.ArrayList;
import qa.edu.qu.cmps251.finaltest.do_not_touch.AirPurificationInterface;
import qa.edu.qu.cmps251.finaltest.do_not_touch.CommonRoom;
import qa.edu.qu.cmps251.finaltest.do_not_touch.Hospital;
import qa.edu.qu.cmps251.finaltest.do_not_touch.PrivateRoom;
public class Questions {
/**
* TODO 1 (8 pts)
*/
public static Hospital createHospital() {
return null;
}
/**
* TODO 2 (3 pts)
*/
public static int getNumOfCommonRooms(Hospital hospital, int x) {
return 0;
}
/**
* TODO 3 (4 pts)
*/
public static AirPurificationInterface getHepaAirPurificationSystem() {
return null;
}
/**
* TODO 4 (5 pts)
*/
public static PrivateRoom topFloorPrivateRoom(Hospital s) {
return null;
}
/**
* TODO 5 (5 points)
*/
public static PrivateRoom returnPrivateRoom(String extractMe) {
return null;
}
/**
* TODO 6 (5 points)
*/
public static ArrayList returnCommonRoomsFromObjFile(String fileName) {
ArrayList cms = new ArrayList();
return cms;
}
/**
* Main will only help you test whether what you did in the TODOs is correct or not
*
* See handout for expected output
*/
public static void main(String args[]) {
System.out.println("TODO1------------------");
Check.testTodo1();
System.out.println(" TODO2------------------");
Check.testTodo2();
System.out.println(" TODO3------------------");
Check.testTodo3();
System.out.println(" TODO4------------------");
Check.testTodo4();
System.out.println(" TODO5------------------");
Check.testTodo5();
System.out.println(" TODO6------------------");
Check.testTodo6();
}
}
package qa.edu.qu.cmps251.finaltest.do_not_touch;
public interface AirPurificationInterface {
public final static int HEPA_FILTER = 1;
public final static int CHEAP_FILTER = 2;
public boolean hasAirPurification();
public void setHasAirPurification(boolean hasAP);
public void setTypeOfAPFilter(int type);
public String getTypeOfFilter();
}
package qa.edu.qu.cmps251.finaltest.do_not_touch;
public class CommonRoom extends Room {
private static final long serialVersionUID = 590174148818403811L;
private int numOfWindows;
public CommonRoom(int numOfWindows, int numOfBeds, int floor) {
super(numOfBeds, floor);
this.numOfWindows = numOfWindows;
}
public int getNumOfWindows() {
return numOfWindows;
}
@Override
public String toString() {
return "Common Room. " + "Number of windows: " +
getNumOfWindows() + " " + super.toString();
}
}
package qa.edu.qu.cmps251.finaltest.do_not_touch;
import java.util.ArrayList;
public class Hospital {
private String name;
private ArrayList rooms;
public Hospital(String name) {
this.name = name;
rooms = new ArrayList();
}
public int getNumOfRooms() {
return rooms.size();
}
public Room getRoomAt(int i) {
return rooms.get(i);
}
public void addRoom(Room r) {
rooms.add(r);
}
@Override
public String toString() {
String s = "Hotel name: " + name + " ";
s += "Number of rooms: " + getNumOfRooms() + " ";
s += "Rooms=================== ";
for (Room r: rooms) {
s += r.toString() + " ";
}
return s;
}
}
package qa.edu.qu.cmps251.finaltest.do_not_touch;
public class PrivateRoom extends Room implements AirPurificationInterface {
private static final long serialVersionUID = -8355460212275853185L;
private boolean hasAirPurificationSystem;
private int typeOfFilter;
public PrivateRoom(int numOfBeds, int floor) {
super(numOfBeds, floor);
}
@Override
public boolean hasAirPurification() {
return hasAirPurificationSystem;
}
@Override
public void setHasAirPurification(boolean hasAP) {
hasAirPurificationSystem = hasAP;
}
@Override
public void setTypeOfAPFilter(int type) {
typeOfFilter = type;
}
@Override
public String getTypeOfFilter() {
switch (typeOfFilter) {
case AirPurificationInterface.CHEAP_FILTER:
return "Cheap";
case AirPurificationInterface.HEPA_FILTER:
return "HEPA";
}
return "";
}
@Override
public String toString() {
String s = "Private Room. ";
if (hasAirPurificationSystem)
s+= "Filter system: " + getTypeOfFilter() + " ";
s += super.toString();
return s;
}
}
package qa.edu.qu.cmps251.finaltest.do_not_touch;
import java.io.Serializable;
public abstract class Room implements Serializable {
private static final long serialVersionUID = 9204414934914747698L;
private int numOfBeds;
private int floor;
private boolean isOccupied;
public Room(int numOfBeds, int floor) {
this.numOfBeds = numOfBeds;
this.floor = floor;
}
public int getFloor() {
return floor;
}
public int getNumOfBeds() {
return numOfBeds;
}
public void setOccupied(boolean isOccupied) {
this.isOccupied = isOccupied;
}
public boolean isOccupied() {
return isOccupied;
}
@Override
public String toString() {
return "Floor: " + floor + " number of beds: " + numOfBeds + (isOccupied?" Occupied":" Not occupied");
}
}
TODO Description Points Create and return a hospital named Alsalmiya that has three rooms: 1. Private room with 3 beds on the 33rd floor 2. Common room with 2 windows, 3 beds on the 10th floor 3. Private room with 4 beds on the 34rd floor that haS CHEAP air purification filter system (ROOM 3 is occupied. All the others are not) Return the number of common rooms that exist in the Hospital given in the argument 3 BONUS (2 pts) Count only those common rooms that have x number of windows or greater @param hospital to search in eparam x - only rooms with this number of windows or greater return the total number of common rooms with x number of windows or greater 3 Return an object that implements the AirPurificationInterface Make sure that the object has air purification, and the type is set to HEPA All other parameters can be chosen at random return AirPurificationInterface object Search the hospital for a room that is: (1) free (available) (2) private (3) in the highest possible floor and return it param s the hospital we are searching return The top available private room in the hospital This method takes a string that looks like one of following examples and returns a CommonRoom object constructed from this given string 5 Strings can look like ONE of the following: 114,false 2 20 true HEPA 1122 true CHEAP First example: the room has one bed, on the 4th floor and has no air filter Second example: the room has 2 beds, on 20th floor and has HEPA filter Third example: the room has one bed, on 22nd floor and has CHEAP filter You will need to parse all these cases and return a PrivateRoom that represents these values. eparam extractMe return A Common Room with these attributes Read Common Room objects from file fileName, add them to an arraylist and return them eparam fileName - file to read CommonRooms from. File ends with "nul1- return ArrayList of common rooms that exist in file fileName

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

Beginning VB 2008 Databases

Authors: Vidya Vrat Agarwal, James Huddleston

1st Edition

1590599470, 978-1590599471

More Books

Students also viewed these Databases questions

Question

What is DDL?

Answered: 1 week ago