Background
After many years of dealing with incomplete and inaccurate information about the classrooms on campus, the faculty of Stony Brook have decided to band together to create a system that will allow them to quickly reference the facilities present in each room, and search for rooms that fulfil certain criteria. In order to have fast access to their large database of rooms and buildings, they have decided to hire you to build a room information system that is based on hash maps. You will be modelling the hash maps on the physical structure of campus, with one hash map relating each building’s name to its content hashmap. The content hashmap will relate the room number to a classroom object containing all the relevant features of the room. You must be able to add and remove buildings from the campus, as well as add and remove classrooms from each building, and edit classrooms to reflect changes.
Additionally, you must implement a search function that will either search a building or the whole campus for classes fulfilling certain criteria. For this request, you may use sequential search (however, if the search involves only one building you definitely shouldn’t search the whole campus).
Finally, as the monkeys in the basement sometimes take a break from using the treadmill power turbine generators, the power occasionally goes out and system must be shut down and then restarted without losing data. You must use Java Serialization to achieve this.
NOTE: All exceptions explicitly thrown in Required Classes except for IllegalArgumentException are custom exceptions that need to be made by you.
Required Classes
Classroom
Write a fully documented class named Classroom that contains four private data fields: boolean hasWhiteboard, boolean hasChalkboard, int numSeats, and String[] AVEquipmentList. This class will be used to represent a classroom within Stony Brook.
This class must implement the Serializable interface.
private boolean hasWhiteboard
This field is true if the classroom has a whiteboard, false otherwise.
private boolean hasChalkboard
This field is true if the classroom has a chalkboard, false otherwise.
private int numSeats
This field holds the number of seats the classroom has.
private String[] AVEquipmentList
This field holds the names of the AV Equipment that are supported in the room.
OPTIONAL: You can use List as the data type, whichever is easier.
Getter and Setter methods for the above four member variables.
Building or Building HashMap
The database of Classrooms will be stored in a HashMap. Use the room number of the classrooms as the key for the HashMap. In this request, you must use the HashMap/HashTable implementation provided by the Java API. You may use inheritance if you wish.
This class should also implement the Serializable. interface.
public void addClassroom(int roomNumber, Classroom classroom)
This method adds a Classroom into the Building using the specified room number as the key.
Throws an IllegalArgumentException if the given roomNumber = null or if the room number is already in the Building.
public Classroom getClassroom(int roomNumber)
Retrieves the Classroom from the table having the indicated room number. If the requested room number does not exist in the Building, return null.
public void removeClassroom(int roomNumber)
This method removes a classroom from the Building.
Throws an IllegalArgumentException if the given roomNumber = null or if it doesn’t exist in the building.
Campus or Campus HashMap
Write a fully-documented class named Campus. The database of Buildings will be stored in a HashMap. Use the name of the Building objects as the key for hashing. In this request, like the Building class, you may provide your own implementation for the School class, or you may use the HashTable (or HashMap) implementation provided by the Java API.
Just as the above classes, this class should implement the Serializable interface.
public void addBuilding(String buildingName, Building building)
This method adds a Building into the Campus using the specified building name as the key.
Throws an IllegalArgumentException if the given buildingName = null or if the building name is already in the Campus.
public Building getBuilding(String buildingName)
Retrieves the Building from the table having the indicated building name. If the requested building name does not exist in the Campus, return null.
public void removeBuilding(String buildingName)
This method removes a Building from the Campus.
Throws an IllegalArgumentException if the given buildingName = null or if the building name is not in the Campus.
RoomLookup
This is the driver class that shows the user the menu detailed in UI Required Functions. It must have a public static main(String[] args), but you can add extra methods to help you organize each part of the menu.
General Recommendations
You might want to implement a toString() method for classes to make debugging and printing easier. You do not have to do this, but it will help you.
You can feel free to add any extra methods and variables as you see fit (public and private).
Serializable Interface
You will also work with the idea of persistence. This means that our program should save all data from session to session. When we terminate a program, normally the data will be lost. We will preserve this data by using Serializable Java API and binary object files. All your classes should simply implement the java.io.Serializable interface.
Example: (note - class names here intentionally are different than the request description above)
Example: A StorageTable class contains information for all Storage objects saved in the electronic database. You would want to preserve this data, so you can load this data the next time you run your program. You would do the following:
Modify the StorageTable so that it implements the Serializable interface. Also, the Storage class should also make this implementation. No other changes are necessary.
In your application that contains the StorageTable, you can include code that will save that class’s data into a file so it can be read in again later. To do this, you need to create an ObjectOutputStream to send the data to, and then use the writeObject method to send the data to the stream, which is stored in the specified file.
1 | StorageTable storage = new StorageTable(/*Constructor Parameters*/); |
When the same application (or another application) runs again, you can initialize the member using the serialized data saved from step 2 so you don’t have to recreate the object from scratch. To do this, you need to create an ObjectInputStream to read the data from, and then use the readObject method to read the hash from the stream.1
2
3
4
5
6FileInputStream file = new FileInputStream("storage.obj");
ObjectInputStream inStream = new ObjectInputStream(file);
StorageTable storage;
storage = (StorageTable) inStream.readObject();
inStream.close();
// missing code here can use StorageTable constructed previously
Note: If you change any data fields or structure of the serialized class, old saved objects will become incompatible.