,Classroom。
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 assignment, 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 assignment, 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 assignment, 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).
UI Required Functions
Menu:
- A - Add Building: with name
- D - Delete Building: by name
- E - Edit Building: by name
- A - Add Room
- D - Delete Room
- E - Edit room
- F - Find Room: Find by name, and print the details
- S - Search
- Options:
- W - Whiteboard: list all rooms containing a whiteboard in the scope
- B - Blackboard: list all rooms containing a blackboard in the scope
- A - AV Keyword: list all rooms containing a piece of av equipment in the scope
- C-List buildings on campus and their rooms.
- L-List summary of building: by name
- Total Seats
- Percent of rooms have whiteboard
- Percent of rooms have blackboar≬㹩ㄾ㰍⼊㸠㰠‼⽬㹩㰾†㵬∠≱㹵㉩㱰⽭㸯㱬⼊㸠㰠†㵑∠≩㹴㌼㰯⽬㸠㰠†⼠㸠㰠⁓㵶≥∾㸍㐊㰠⼠㸠㰠⼾㹄㰠㵯∻≶㹥㔼㰯⽬㸠㰠‼⼯㹵㱬†㵩∾≵㹬㘾㰍⼊㹩㱤⁓⽥㹲㱩⽡㹡ൢ੬⁉⁴•㰾⽓㹩ൡ੬⁺†⁉⁴㱦㴍∊≯㹵ഠ††⁷㱫㹴㱨†㵯≦≳㹩䙳䥣㵡⁴㰠⁰㵭∠≳㹡㱡⽬㹴䘠䥭⡯㰠㵨≥≥㹲♭㭥☠㭡㱬⽬㹥⤠㭤㱡⽴㹬㱬⼠㹬㱯⁗㵬∠≥㹲䥳㵬㱺†㵁≐≩㹮㰠⽯㹴†䤠⡬⥳㬠㱳⽨㸠㱳⁰⽬㹹㰠㵴≨≶㹡㭥㱲⽦㸼㰯⼊㸼㱰㴨≮∭㸠㵭⡳⥩⠠⥴㭨㱡⽮㸠㱨⽷㹯㱲㵩≯≯㹶⸼⡭⥰㭬㱥⼺㹴㱯⽥㹔㱡㵣≯≮㹳㰠㵮∠∠㹓⽴⽯†⁴⁴⁷㱴⽯㹳㱥⽲㹨㱩⽡㹴㱡⼬㸠൹੯⁵†††⁴㱨⽩㹤ൡੴ†⁴†㱸⽴㹩൭†⁹⁵㰠⽲㹵൲ਠ㱰⽲㸮ഠਖ਼㱯⽵㸠㱤⽯㹴൨㰠㹯♬㭮㱧⼺㸯൰ਾ㰍㸼㩤䥦†††⁴⁴†Ᵽ⁵⸠㱴⽨㹳 implementation. No other changes are necessary.
1 2 3 4
|
public class StorageTable implements Serializable #123; #125;
|
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 2 3 4 5 6 7 8
|
StorageTable storage = new StorageTable();
FileOutputStream file = new FileOutputStream("storage.obj"); ObjectOutputStream outStream = new ObjectOutputStream(file);
outStream.writeObject(storage); outStream.close();
|
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.