Answered step by step
Verified Expert Solution
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()); }
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");
}
}
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