Answered step by step
Verified Expert Solution
Question
1 Approved Answer
java 2. In the FSTCooling System class: a. Create an array that can hold 10 Room objects. b. Add four Room objects, with the state
java
2. In the FSTCooling System class: a. Create an array that can hold 10 Room objects. b. Add four Room objects, with the state in Table 1, to the array. Name Floor Square Footage Lecture Room 1 120 Computer Science Lab 1 100 Computer Science Lab 2 150 Lecture Room 2 300 Table 1 C. Print the details of the Room objects by invoking to toString() methods. What do you observe? 3. In the Room class, uncomment the supplied toString() method. Print the details of the Room objects by invoking to toString() methods. What do you observe now? 4. Suppose the number of seats in a Room can vary from the default calculation, perhaps due to safety regulations. Add an overloaded constructor to the Room class that accepts a name, floor, square footage and number of seats for the Room. This constructor should initialize the appropriate attributes with the supplied values and should also initialise the roomID to "FST". 5. Using the new constructor from Step 5, create a new Room called "Lecture Room 3", located on Floor 2, with a size of 175 square feet and seating for 70 people. Add this new Room to the array and print an updated list of Rooms 6. In the Room class, write a method with the signature: public void generateRoomID (int floor). This method should automatically generate a roomID for a Room object based on the floor that a Room is located on. Table 2 shows how this is to be achieved. Note: Two class variables are required: floorID Generator and floor 21D Generator. TIP: Class variable format Floor ID Start 100 Increment Examples of roomID values FST100, FST110, FST120... FST200, FST210, FST220... Table 2 caccess modifier state variable type> variable name> 200 7. Iterate through the Rooms array in the FSTCooling System class, generate and set the roomID for each Room object, and then print the details of each Room object. 8. In the FSTCooling System class. print the values of the two class variables (floor 1IDGenerator, floor2IDGenerator) in the Room class. What do you notice? Change these variables to instance variables then print the contents of the Rooms array and the values of the generator variables once more. What do you observe? 9. Locate and print the details of the Room object with roomID FST100 and the Room object with the roomID FST210. Part 2: Association Relationships Now, we will model the relationship between a Room object and an Air Conditioner object. Let's start with the premise that one room is cooled by one air conditioner. 1. Retrieve the AirConditioner.java from the network folder for myElearning). In your Air Conditioner class: a. Observe that the following constructor is provided: public Air Conditioner (String brand, int btu) which generates unique values for the acld starting from 1000. b. Create an object reference to a Room object as follows: private Room room; c. Write a method in the AirConditioner class which associates an Air Conditioner object with a Room object: public void cools (Room ) room = r. d. Write a method public String listRoom() which returns the details of the Room that the AirConditioner cools, or a message indicating that the AirConditioner is currently not installed in any room. Note: By creating an object variable of type Room in the AirConditioner class in 1b). we have essentially created an association between the Air Conditioner class and the Room class. This is an example of a one-to-one relationship. The method cools(Room 7) in 1(c), allows the Room object variable to be set to a real object. The listRoom() method in 1(d) simply allows a client to get details of the Room object if it has been set or a message if the Room object has not been set (i.e. it is null). Page 2 of 4 AirConditioner cools Room 2. Within your Room class: a. Create an object reference to an Air Conditioner object as follows: private AirConditioner airConditioner, b. Write a method in the Room class which associates a AirConditioner object with a Room object: public void addAirConditioner(Air Conditioner ac) airConditioner = ac: c. Write a method public String listAir Conditioner) which returns the details of the AirConditioner installed in the Room or a message indicating that there is no Air Conditioner installed in the Room. Note: Step 1 set up the directed relationship from the AirConditioner class to Room class. This allows an Air Conditioner object to know about the Room it cools. Step 2 sets up another relationship, this time directed from the Room class to the AirConditioner class in the same way. This now allows the Room object to know about the Air Conditioner object. Another example of a one-to-one relationship. The method name does not necessarily have to be the same as the relationship name. The method is merely an implementation of the design concept. AirConditioner is cooled by Room 3. In your FSTCooling System class: a. Create an AirConditioner object act with the following details: Brand: Carrier BTU: 5000 b. Associate the AirConditioner object act with the Room object with roomid FST210. This is done as follows: Locate the Room object with roomID FST130 (Let's call this object room210 for reference) Invoke the cools(..) method on the AirConditioner object, passing the Room object as an input parameter. c. Invoke the listRoom() method on ac1. Observe what happens. d. Invoke the listAirConditioner() method on room210. Observe what happens. e. Associate the Air Conditioner object act with the Room object room210. This is done as follows: Invoke the addAirConditioner...) method on the Room object room210, passing the Air Conditioner object act as an input parameter. f. Invoke the listRoom() method again on ac1. Observe what happens. g. Invoke the listAir Conditioner() method on room210. Observe what happens now. h. Create a second AirConditioner object ac2 with the following details: Brand: Carrier BTU: 6000 Add this Air Conditioner ac2 to the Room room210 and repeat steps (t) and (g). What happens here? (We have been handling One-to-One relationships but now need to be able to handle One-to-Many relationships!) Page 3 of 4 4. Modify your Room class so that it keeps track of many Air Conditioner objects. You need to add an array. a. Fix the addAirConditioner(AirConditioner ac) method appropriately b. Try to add Air Conditioner ac2 to Room room210 and observe what happens now. c. Create a third AirConditioner ac3 on your own and add it to a room of your choice. d. Print out the details of all the rooms now with air conditioner details. 2. In the FSTCooling System class: a. Create an array that can hold 10 Room objects. b. Add four Room objects, with the state in Table 1, to the array. Name Floor Square Footage Lecture Room 1 120 Computer Science Lab 1 100 Computer Science Lab 2 150 Lecture Room 2 300 Table 1 C. Print the details of the Room objects by invoking to toString() methods. What do you observe? 3. In the Room class, uncomment the supplied toString() method. Print the details of the Room objects by invoking to toString() methods. What do you observe now? 4. Suppose the number of seats in a Room can vary from the default calculation, perhaps due to safety regulations. Add an overloaded constructor to the Room class that accepts a name, floor, square footage and number of seats for the Room. This constructor should initialize the appropriate attributes with the supplied values and should also initialise the roomID to "FST". 5. Using the new constructor from Step 5, create a new Room called "Lecture Room 3", located on Floor 2, with a size of 175 square feet and seating for 70 people. Add this new Room to the array and print an updated list of Rooms 6. In the Room class, write a method with the signature: public void generateRoomID (int floor). This method should automatically generate a roomID for a Room object based on the floor that a Room is located on. Table 2 shows how this is to be achieved. Note: Two class variables are required: floorID Generator and floor 21D Generator. TIP: Class variable format Floor ID Start 100 Increment Examples of roomID values FST100, FST110, FST120... FST200, FST210, FST220... Table 2 caccess modifier state variable type> variable name> 200 7. Iterate through the Rooms array in the FSTCooling System class, generate and set the roomID for each Room object, and then print the details of each Room object. 8. In the FSTCooling System class. print the values of the two class variables (floor 1IDGenerator, floor2IDGenerator) in the Room class. What do you notice? Change these variables to instance variables then print the contents of the Rooms array and the values of the generator variables once more. What do you observe? 9. Locate and print the details of the Room object with roomID FST100 and the Room object with the roomID FST210. Part 2: Association Relationships Now, we will model the relationship between a Room object and an Air Conditioner object. Let's start with the premise that one room is cooled by one air conditioner. 1. Retrieve the AirConditioner.java from the network folder for myElearning). In your Air Conditioner class: a. Observe that the following constructor is provided: public Air Conditioner (String brand, int btu) which generates unique values for the acld starting from 1000. b. Create an object reference to a Room object as follows: private Room room; c. Write a method in the AirConditioner class which associates an Air Conditioner object with a Room object: public void cools (Room ) room = r. d. Write a method public String listRoom() which returns the details of the Room that the AirConditioner cools, or a message indicating that the AirConditioner is currently not installed in any room. Note: By creating an object variable of type Room in the AirConditioner class in 1b). we have essentially created an association between the Air Conditioner class and the Room class. This is an example of a one-to-one relationship. The method cools(Room 7) in 1(c), allows the Room object variable to be set to a real object. The listRoom() method in 1(d) simply allows a client to get details of the Room object if it has been set or a message if the Room object has not been set (i.e. it is null). Page 2 of 4 AirConditioner cools Room 2. Within your Room class: a. Create an object reference to an Air Conditioner object as follows: private AirConditioner airConditioner, b. Write a method in the Room class which associates a AirConditioner object with a Room object: public void addAirConditioner(Air Conditioner ac) airConditioner = ac: c. Write a method public String listAir Conditioner) which returns the details of the AirConditioner installed in the Room or a message indicating that there is no Air Conditioner installed in the Room. Note: Step 1 set up the directed relationship from the AirConditioner class to Room class. This allows an Air Conditioner object to know about the Room it cools. Step 2 sets up another relationship, this time directed from the Room class to the AirConditioner class in the same way. This now allows the Room object to know about the Air Conditioner object. Another example of a one-to-one relationship. The method name does not necessarily have to be the same as the relationship name. The method is merely an implementation of the design concept. AirConditioner is cooled by Room 3. In your FSTCooling System class: a. Create an AirConditioner object act with the following details: Brand: Carrier BTU: 5000 b. Associate the AirConditioner object act with the Room object with roomid FST210. This is done as follows: Locate the Room object with roomID FST130 (Let's call this object room210 for reference) Invoke the cools(..) method on the AirConditioner object, passing the Room object as an input parameter. c. Invoke the listRoom() method on ac1. Observe what happens. d. Invoke the listAirConditioner() method on room210. Observe what happens. e. Associate the Air Conditioner object act with the Room object room210. This is done as follows: Invoke the addAirConditioner...) method on the Room object room210, passing the Air Conditioner object act as an input parameter. f. Invoke the listRoom() method again on ac1. Observe what happens. g. Invoke the listAir Conditioner() method on room210. Observe what happens now. h. Create a second AirConditioner object ac2 with the following details: Brand: Carrier BTU: 6000 Add this Air Conditioner ac2 to the Room room210 and repeat steps (t) and (g). What happens here? (We have been handling One-to-One relationships but now need to be able to handle One-to-Many relationships!) Page 3 of 4 4. Modify your Room class so that it keeps track of many Air Conditioner objects. You need to add an array. a. Fix the addAirConditioner(AirConditioner ac) method appropriately b. Try to add Air Conditioner ac2 to Room room210 and observe what happens now. c. Create a third AirConditioner ac3 on your own and add it to a room of your choice. d. Print out the details of all the rooms now with air conditioner details 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