SlideShare a Scribd company logo
1 of 18
Download to read offline
Todo
package hwk6;
// This class contains the configuration of a type of apartment
public class Apartment {
int numOfUnits; // the number of apartments of this type
Room[] rooms; // rooms in this type of apartment
Apartment(int numOfUnits, Room[] rooms) {
this.numOfUnits = numOfUnits;
this.rooms = rooms;
}
// return an array of window orders for one unit of this type of apartment
WindowOrder[] orderForOneUnit() {
// TODO
}
// return an array of window orders for all units of this type of apartment
WindowOrder[] totalOrder() {
// TODO
}
// return text like:
//
// 15 apartments with (Living room: 5 (6 X 8 window)) (Master bedroom: 3 (4 X 6 window))
(Guest room: 2 (5 X 6 window))
public String toString() {
// TODO
}
}
class OneBedroom extends Apartment {
OneBedroom(int numOfUnits) {
super(numOfUnits, new Room[] { new LivingRoom(), new MasterBedroom() });
}
}
class TwoBedroom extends Apartment {
TwoBedroom(int numOfUnits) {
super(numOfUnits, new Room[] { new LivingRoom(), new MasterBedroom(), new
GuestRoom() });
}
}
class ThreeBedroom extends Apartment {
ThreeBedroom(int numOfUnits) {
super(numOfUnits, new Room[] { new LivingRoom(), new MasterBedroom(), new
GuestRoom(), new GuestRoom() });
}
// return an array of window orders for all units of this type of apartment
//
// Notice we have two guest rooms and they have the same size of windows.
// override the inherited method to merge the order for the two guest rooms since their
windows have the same size
@Override
WindowOrder[] orderForOneUnit() {
// TODO
}
}
package hwk6;
public class Building {
Apartment[] apartments;
public Building(Apartment[] apartments) {
this.apartments= apartments;
}
// Return an array of window orders for all apartments in the building
// Ensure that the orders for windows of the same sizes are merged.
WindowOrder[] order() {
// TODO
}
// return a string to represent all types of apartments in the building such as:
// 20 apartments with (Living room: 5 (6 X 8 window))(Master bedroom: 3 (4 X 6 window))
// 15 apartments with (Living room: 5 (6 X 8 window))(Master bedroom: 3 (4 X 6
window))(Guest room: 2 (5 X 6 window))
// 10 apartments with (Living room: 5 (6 X 8 window))(Master bedroom: 3 (4 X 6
window))(Guest room: 2 (5 X 6 window))(Guest room: 2 (5 X 6 window))
//
public String toString() {
// TODO
}
}
package hwk6;
public class Hwk6 {
public static void main(String[] args) {
Apartment[] apartments = { new OneBedroom(20), new TwoBedroom(15), new
ThreeBedroom(10) };
Building building = new Building(apartments);
WindowOrder[] orders = building.order();
System.out.println(building);
System.out.println("Window orders are: ");
for(WindowOrder order: orders) {
System.out.println(order);
}
}
}
package hwk6;
public class Room {
Window window;
int numOfWindows;
Room(Window window, int numOfWindows) {
this.window = window;
this.numOfWindows = numOfWindows;
}
WindowOrder order() {
return new WindowOrder(window, numOfWindows);
}
// Print text like: 5 (6 X 8 window)
@Override
public String toString() {
// TODO
}
// Two rooms are equal if they contain the same number of windows of the same size
@Override
public boolean equals(Object that) {
// TODO
}
}
class MasterBedroom extends Room {
MasterBedroom() {
super(new Window(4, 6), 3);
}
// Call parent's toString method
//
// return text like: Master bedroom: 3 (4 X 6 window)
@Override
public String toString() {
// TODO
}
}
class GuestRoom extends Room {
GuestRoom() {
super(new Window(5, 6), 2);
}
// Call parent's toString method
//
// return text like: Guest room: 2 (5 X 6 window)
@Override
public String toString() {
// TODO
}
}
class LivingRoom extends Room {
LivingRoom() {
super(new Window(6, 8), 5);
}
// Call parent's toString method
//
// return text like: Living room: 5 (6 X 8 window)
@Override
public String toString() {
// TODO
}
}
package hwk6;
public class Window {
private final int width, height;
public Window(int width, int height) {
this.width = width;
this.height = height;
}
// print text like: 4 X 6 window
public String toString() {
// TODO
}
// compare window objects by their dimensions
public boolean equals(Object that) {
// TODO
}
}
class WindowOrder {
final Window window; // window description (its width and height)
int num; // number of windows for this order
WindowOrder(Window window, int num) {
this.window = window;
this.num = num;
}
// add the num field of the parameter to the num field of this object
//
// BUT
//
// do the merging only of two windows have the same size
// do nothing if the size does not match
//
// return the current object
WindowOrder add (WindowOrder order) {
// TODO
}
// update the num field of this object by multiplying it with the parameter
// and then return the current object
WindowOrder times(int number) {
// TODO
}
// print text like: 20 4 X 6 window
@Override
public String toString() {
// TODO
}
// Two orders are equal if they contain the same number of windows of the same size.
@Override
public boolean equals(Object that) {
// TODO
}
}
Testing
package hwk6;
import org.junit.*;
import static org.junit.Assert.*;
import java.lang.reflect.Field;
import org.junit.FixMethodOrder;
import org.junit.runners.MethodSorters;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class Testing {
Window window;
WindowOrder windoworder;
Room room;
Room masterbedroom;
Room guestroom;
Room livingroom;
Apartment apartment;
Apartment onebedroom;
Apartment twobedrom;
Apartment threebedroom;
Building building;
Room []rooms ;
Apartment [] apartments;
@Before
public void setUp()
{
this.window= new Window(10, 20);
windoworder = new WindowOrder(window, 100);
this.room= new Room(window, 5);
this.masterbedroom= new MasterBedroom();
this.guestroom= new GuestRoom();
this.livingroom= new LivingRoom();
rooms =new Room[5];
rooms[0]=masterbedroom;
rooms[1]=guestroom;
rooms[2]=livingroom;
rooms[3]=masterbedroom;
rooms[4]=livingroom;
this.apartment= new Apartment(30, rooms);
this.onebedroom= new OneBedroom(10);
this.twobedrom=new TwoBedroom(5);
this.threebedroom=new ThreeBedroom(15);
apartments = new Apartment[6];
apartments[0] = onebedroom;
apartments[1] = twobedrom;
apartments[2] = threebedroom;
apartments[3] = onebedroom;
apartments[4] = onebedroom;
apartments[5] = twobedrom;
this.building= new Building(apartments);
}
@After
public void tearDown()
{
this.window= null;
this.windoworder=null;
this.room= null;
this.masterbedroom= null;
this.guestroom= null;
this.livingroom= null;
this.apartment= null;
this.onebedroom= null;
this.twobedrom=null;
this.threebedroom=null;
this.building=null;
}
private Object getField( Object instance, String name ) throws Exception
{
Class c = instance.getClass();
Field f = c.getDeclaredField( name );
f.setAccessible( true );
return f.get( instance );
}
@Test
public void AA_TestWindowConstructor() throws Exception{
assertEquals(this.window.getClass().getSimpleName().toString(), "Window");
assertEquals(10,(int)getField(window,"width"));
assertEquals(20,getField(window,"height"));
}
@Test
public void AB_TestWindowEquals() throws Exception{
assertTrue(this.window.equals(new Window(10,20)));
assertTrue(this.window.equals(this.window));
assertFalse(this.window.equals(new Window(1,20)));
}
@Test
public void BA_TestWindowOrderConstructor(){
assertEquals(this.windoworder.getClass().getSimpleName().toString(), "WindowOrder");
assertEquals(this.window,windoworder.window);
assertEquals(100,windoworder.num);
}
@Test
public void BB_Testwindoworderadd(){
WindowOrder w=windoworder.add(new WindowOrder(new Window(10,20), 1000));
assertEquals(windoworder,w);
assertEquals(1100,windoworder.num);
windoworder=null;
}
@Test
public void BC_Testwindoworderadd(){
WindowOrder w= windoworder.add(new WindowOrder(new Window(20,20), 1000));
assertEquals(windoworder,w);
assertEquals(100,windoworder.num);
}
@Test
public void BD_Testwindoworderadd(){
WindowOrder w= windoworder.add(windoworder);
assertEquals(windoworder,w);
assertEquals(200,windoworder.num);
}
@Test
public void BE_Testwindowordertimes(){
WindowOrder w= windoworder.times(0);
assertEquals(windoworder,w);
assertEquals(0,windoworder.num);
}
@Test
public void BF_Testwindowordertimes(){
WindowOrder w= windoworder.times(3);
assertEquals(windoworder,w);
assertEquals(300,windoworder.num);
}
@Test
public void CA_TestRoomConstructor(){
assertEquals(this.room.getClass().getSimpleName().toString(), "Room");
assertEquals(5,room.numOfWindows);
assertEquals(window,room.window);
}
@Test
public void CB_TestRoomOrder(){
assertEquals( new WindowOrder(window, 5),room.order());
assertEquals( new WindowOrder(new Window(4, 6), 3),masterbedroom.order());
}
@Test
public void D_TestMasterBedRoomConstructor(){
assertEquals(this.masterbedroom.getClass().getSimpleName().toString(),
"MasterBedroom");
assertEquals(3,masterbedroom.numOfWindows);
assertEquals(new Window(4, 6),masterbedroom.window);
}
@Test
public void E_TestGuestRoomConstructor(){
assertEquals(this.guestroom.getClass().getSimpleName().toString(), "GuestRoom");
assertEquals(2,guestroom.numOfWindows);
assertEquals(new Window(5, 6),guestroom.window);
}
@Test
public void F_TestLivingRoomConstructor(){
assertEquals(this.livingroom.getClass().getSimpleName().toString(), "LivingRoom");
assertEquals(5,livingroom.numOfWindows);
assertEquals(new Window(6, 8),livingroom.window);
}
@Test
public void GA_TestApartmentConstructor(){
assertEquals(this.apartment.getClass().getSimpleName().toString(), "Apartment");
assertEquals(30,apartment.numOfUnits);
assertArrayEquals(rooms,apartment.rooms);
}
@Test
public void GB_TestApartmentTotalOrder(){
WindowOrder[] wo = new WindowOrder [5];
wo[0] = new WindowOrder(new Window(4, 6), 90);
wo[1] = new WindowOrder(new Window(5, 6), 60);
wo[2] = new WindowOrder(new Window(6, 8), 150);
wo[3] = new WindowOrder(new Window(4, 6), 90);
wo[4] = new WindowOrder(new Window(6, 8), 150);
assertArrayEquals(wo ,apartment.totalOrder());
}
@Test
public void HA_TestOneBedroomConstructor(){
assertEquals(this.onebedroom.getClass().getSimpleName().toString(), "OneBedroom");
assertEquals(10,onebedroom.numOfUnits);
assertArrayEquals(new Room[] { new LivingRoom(), new MasterBedroom()
},onebedroom.rooms);
}
@Test
public void HB_TestOneBedroomorDerForOneUnit(){
WindowOrder[] wo = new WindowOrder [2];
wo[0] = new WindowOrder(new Window(6, 8), 5);
wo[1] = new WindowOrder(new Window(4, 6), 3);
assertArrayEquals(wo ,onebedroom.orderForOneUnit());
}
@Test
public void HC_TestOneBedroomTotalOrder(){
WindowOrder[] wo = new WindowOrder [2];
wo[0] = new WindowOrder(new Window(6, 8), 50);
wo[1] = new WindowOrder(new Window(4, 6), 30);
assertArrayEquals(wo ,onebedroom.totalOrder());
}
@Test
public void IA_TestTwoBedroomConstructor(){
assertEquals(this.twobedrom.getClass().getSimpleName().toString(), "TwoBedroom");
assertEquals(5,twobedrom.numOfUnits);
assertArrayEquals(new Room[] { new LivingRoom(), new MasterBedroom(), new
GuestRoom() },twobedrom.rooms);
}
@Test
public void IB_TestTwoBedroomOrderForOneUnit(){
WindowOrder[] wo = new WindowOrder [3];
wo[0] = new WindowOrder(new Window(6, 8), 5);
wo[1] = new WindowOrder(new Window(4, 6), 3);
wo[2] = new WindowOrder(new Window(5, 6), 2);
assertArrayEquals(wo ,twobedrom.orderForOneUnit());
}
@Test
public void IC_TestTwoBedroomTotalOrder(){
WindowOrder[] wo = new WindowOrder [3];
wo[0] = new WindowOrder(new Window(6, 8), 25);
wo[1] = new WindowOrder(new Window(4, 6), 15);
wo[2] = new WindowOrder(new Window(5, 6), 10);
assertArrayEquals(wo ,twobedrom.totalOrder());
}
@Test
public void JA_TestThreeBedroomConstructor(){
assertEquals(this.threebedroom.getClass().getSimpleName().toString(), "ThreeBedroom");
assertEquals(15,threebedroom.numOfUnits);
assertArrayEquals(new Room[] { new LivingRoom(), new MasterBedroom(), new
GuestRoom(), new GuestRoom() },threebedroom.rooms);
}
@Test
public void JB_TestThreeBedroomOrderForOneUnit(){
WindowOrder[] wo = new WindowOrder [3];
wo[0] = new WindowOrder(new Window(6, 8), 5);
wo[1] = new WindowOrder(new Window(4, 6), 3);
wo[2] = new WindowOrder(new Window(5, 6), 4);
assertArrayEquals(wo ,threebedroom.orderForOneUnit());
}
@Test
public void JC_TestThreeBedroomTotalOrder(){
WindowOrder[] wo = new WindowOrder [3];
wo[0] = new WindowOrder(new Window(6, 8), 75);
wo[1] = new WindowOrder(new Window(4, 6), 45);
wo[2] = new WindowOrder(new Window(5, 6), 60);
assertArrayEquals(wo ,threebedroom.totalOrder());
}
@Test
public void KA_TestBuildingConstructor(){
assertEquals(this.building.getClass().getSimpleName().toString(), "Building");
assertArrayEquals(apartments,building.apartments);
}
@Test
public void KB_TestBuildingOrderr(){
WindowOrder[] wo = new WindowOrder [3];
wo[0] = new WindowOrder(new Window(6, 8), 275);
wo[1] = new WindowOrder(new Window(4, 6), 165);
wo[2] = new WindowOrder(new Window(5, 6), 80);
assertArrayEquals(wo,building.order());
}
@Test
public void L_TestWindowToString(){
String expected= "10 X 20 window";
assertEquals(expected,window.toString());
}
@Test
public void M_TestWindowOrderToString(){
String expected= "100 10 X 20 window";
assertEquals(expected,windoworder.toString());
}
@Test
public void N_TestApartmentToString(){
String expected= "30 apartments with (Master bedroom: 3 (4 X 6 window))(Guest room: 2 (5
X 6 window))(Living room: 5 (6 X 8 window))(Master bedroom: 3 (4 X 6 window))(Living
room: 5 (6 X 8 window))";
assertEquals(expected,apartment.toString());
}
@Test
public void O_TestoneBedRoomToString(){
String expected= "10 apartments with (Living room: 5 (6 X 8 window))(Master bedroom: 3
(4 X 6 window))";
assertEquals(expected,onebedroom.toString());
}
@Test
public void P_TestTwoBedRoomToString(){
String expected= "5 apartments with (Living room: 5 (6 X 8 window))(Master bedroom: 3 (4
X 6 window))(Guest room: 2 (5 X 6 window))";
assertEquals(expected,twobedrom.toString());
}
@Test
public void Q_TestThreeBedRoomToString(){
String expected= "15 apartments with (Living room: 5 (6 X 8 window))(Master bedroom: 3
(4 X 6 window))(Guest room: 2 (5 X 6 window))(Guest room: 2 (5 X 6 window))";
assertEquals(expected,threebedroom.toString());
}
@Test
public void R_TestMasterRoomToString(){
String expected= "Master bedroom: 3 (4 X 6 window)";
assertEquals(expected,masterbedroom.toString());
}
@Test
public void S_TestGuestRoomToString(){
String expected= "Guest room: 2 (5 X 6 window)";
assertEquals(expected,guestroom.toString());
}
@Test
public void T_TestLivingRoomToString(){
String expected= "Living room: 5 (6 X 8 window)";
assertEquals(expected,livingroom.toString());
}
@Test
public void UTestBuildingToString(){
String expected= "10 apartments with (Living room: 5 (6 X 8 window))(Master bedroom: 3
(4 X 6 window)) "+
"5 apartments with (Living room: 5 (6 X 8 window))(Master bedroom: 3 (4 X 6
window))(Guest room: 2 (5 X 6 window)) "+
"15 apartments with (Living room: 5 (6 X 8 window))(Master bedroom: 3 (4 X 6
window))(Guest room: 2 (5 X 6 window))(Guest room: 2 (5 X 6 window)) "+
"10 apartments with (Living room: 5 (6 X 8 window))(Master bedroom: 3 (4 X 6 window)) "+
"10 apartments with (Living room: 5 (6 X 8 window))(Master bedroom: 3 (4 X 6 window)) "+
"5 apartments with (Living room: 5 (6 X 8 window))(Master bedroom: 3 (4 X 6
window))(Guest room: 2 (5 X 6 window)) ";
assertEquals(expected,building.toString());
}
}
please finish todo. 1 What's the problem? Suppose you want to model an apartment building so
that you can calculate the number of windows (and their sizes) that are in the building. We are
modelling the building with the following classes: 1. Building, which contains several types of
apartments. 2. Apartment and its subclasses OneBedroom, TwoBedroom, and ThreeBedroom An
instance of this class is to represent a type of apartments, which in cludes a field to store the
number of units of this tvpe. 3. Room and its subclass LivingRoom, MasterBedroom, and
GuestRoom Each room has some windows of certain size. Different type of rooms have
windows of different sizes. 4. Window and WindowOrder Window object has just the width and
height of the window. Window order object has a window object and the number of window for
that order. 2 What to implement? You wl fill in the methods for classes described above. The
provided code template has instruction in the comments above the methods that vou will
implement 3 What is provided? We provide a driver class Hwk6.java, a test class Test.java, and a
bunch of template classes. Note that each file may contain multiple classes. I usually group
related classes in the same file. For example, the file Apartment.java contains not only
Apartment class but also its subclasses.
Solution
package hwk6;
public class Hwk6 {
public static void main(String[] args) {
Apartment[] apartments = { new OneBedroom(20), new TwoBedroom(15), new
ThreeBedroom(10) };
Building building = new Building(apartments);
WindowOrder[] orders = building.order();
System.out.println(building.toString());
System.out.println("Window orders are: ");
for(WindowOrder order: orders) {
System.out.println(order.toString());
}
}
}
package hwk6;
public class Building {
Apartment[] apartments;
public Building(Apartment[] apartments) {
this.apartments= apartments;
}
// Return an array of window orders for all apartments in the building
// Ensure that the orders for windows of the same sizes are merged.
WindowOrder[] order() {
WindowOrder temp[] = new WindowOrder[3];
temp[0] = new WindowOrder(new Window(6,8),0);
temp[1] = new WindowOrder(new Window(4,6),0);
temp[2] = new WindowOrder(new Window(5,6),0);
for(int i=0;i

More Related Content

Similar to Todopackage hwk6; This class contains the configuration of a t.pdf

using the code below create a method called getCollisionCount that w.pdf
using the code below create a method called getCollisionCount that w.pdfusing the code below create a method called getCollisionCount that w.pdf
using the code below create a method called getCollisionCount that w.pdf
amirthagiftsmadurai
ย 
.NET 2015: ะ‘ัƒะดัƒั‰ะตะต ั€ัะดะพะผ
.NET 2015: ะ‘ัƒะดัƒั‰ะตะต ั€ัะดะพะผ.NET 2015: ะ‘ัƒะดัƒั‰ะตะต ั€ัะดะพะผ
.NET 2015: ะ‘ัƒะดัƒั‰ะตะต ั€ัะดะพะผ
Andrey Akinshin
ย 
class object.pptx
class object.pptxclass object.pptx
class object.pptx
Killmekhilati
ย 
java question Fill the add statement areaProject is to wo.pdf
java question Fill the add statement areaProject is to wo.pdfjava question Fill the add statement areaProject is to wo.pdf
java question Fill the add statement areaProject is to wo.pdf
dbrienmhompsonkath75
ย 
Mocks introduction
Mocks introductionMocks introduction
Mocks introduction
Sperasoft
ย 
EmptyCollectionException-java -- - Represents the situation in which.docx
EmptyCollectionException-java --  - Represents the situation in which.docxEmptyCollectionException-java --  - Represents the situation in which.docx
EmptyCollectionException-java -- - Represents the situation in which.docx
BlakeSGMHemmingss
ย 
This project should be done in C# using Visual Studio - Windows Form.pdf
This project should be done in C# using Visual Studio - Windows Form.pdfThis project should be done in C# using Visual Studio - Windows Form.pdf
This project should be done in C# using Visual Studio - Windows Form.pdf
rajeshjangid1865
ย 
using the code below write the public V add(K key, V value); that ad.pdf
using the code below write the public V add(K key, V value); that ad.pdfusing the code below write the public V add(K key, V value); that ad.pdf
using the code below write the public V add(K key, V value); that ad.pdf
amirthagiftsmadurai
ย 
operating system linux,ubuntu,Mac Geometri.pdf
operating system linux,ubuntu,Mac Geometri.pdfoperating system linux,ubuntu,Mac Geometri.pdf
operating system linux,ubuntu,Mac Geometri.pdf
aquadreammail
ย 

Similar to Todopackage hwk6; This class contains the configuration of a t.pdf (20)

TDD - test doubles
TDD - test doublesTDD - test doubles
TDD - test doubles
ย 
using the code below create a method called getCollisionCount that w.pdf
using the code below create a method called getCollisionCount that w.pdfusing the code below create a method called getCollisionCount that w.pdf
using the code below create a method called getCollisionCount that w.pdf
ย 
PHP7 Presentation
PHP7 PresentationPHP7 Presentation
PHP7 Presentation
ย 
.NET 2015: ะ‘ัƒะดัƒั‰ะตะต ั€ัะดะพะผ
.NET 2015: ะ‘ัƒะดัƒั‰ะตะต ั€ัะดะพะผ.NET 2015: ะ‘ัƒะดัƒั‰ะตะต ั€ัะดะพะผ
.NET 2015: ะ‘ัƒะดัƒั‰ะตะต ั€ัะดะพะผ
ย 
Introduction to TypeScript
Introduction to TypeScriptIntroduction to TypeScript
Introduction to TypeScript
ย 
class object.pptx
class object.pptxclass object.pptx
class object.pptx
ย 
Modern Java Workshop
Modern Java WorkshopModern Java Workshop
Modern Java Workshop
ย 
java question Fill the add statement areaProject is to wo.pdf
java question Fill the add statement areaProject is to wo.pdfjava question Fill the add statement areaProject is to wo.pdf
java question Fill the add statement areaProject is to wo.pdf
ย 
Android code convention
Android code conventionAndroid code convention
Android code convention
ย 
Flink Batch Processing and Iterations
Flink Batch Processing and IterationsFlink Batch Processing and Iterations
Flink Batch Processing and Iterations
ย 
Creating Interface- Practice Program 6.docx
Creating Interface- Practice Program 6.docxCreating Interface- Practice Program 6.docx
Creating Interface- Practice Program 6.docx
ย 
Exploring ES6
Exploring ES6Exploring ES6
Exploring ES6
ย 
Mocks introduction
Mocks introductionMocks introduction
Mocks introduction
ย 
Go Programming Language (Golang)
Go Programming Language (Golang)Go Programming Language (Golang)
Go Programming Language (Golang)
ย 
EmptyCollectionException-java -- - Represents the situation in which.docx
EmptyCollectionException-java --  - Represents the situation in which.docxEmptyCollectionException-java --  - Represents the situation in which.docx
EmptyCollectionException-java -- - Represents the situation in which.docx
ย 
This project should be done in C# using Visual Studio - Windows Form.pdf
This project should be done in C# using Visual Studio - Windows Form.pdfThis project should be done in C# using Visual Studio - Windows Form.pdf
This project should be done in C# using Visual Studio - Windows Form.pdf
ย 
using the code below write the public V add(K key, V value); that ad.pdf
using the code below write the public V add(K key, V value); that ad.pdfusing the code below write the public V add(K key, V value); that ad.pdf
using the code below write the public V add(K key, V value); that ad.pdf
ย 
operating system linux,ubuntu,Mac Geometri.pdf
operating system linux,ubuntu,Mac Geometri.pdfoperating system linux,ubuntu,Mac Geometri.pdf
operating system linux,ubuntu,Mac Geometri.pdf
ย 
Test string and array
Test string and arrayTest string and array
Test string and array
ย 
Functional Programming with C#
Functional Programming with C#Functional Programming with C#
Functional Programming with C#
ย 

More from aroraopticals15

Evaluate the decision to have a computer usage policy and the potent.pdf
Evaluate the decision to have a computer usage policy and the potent.pdfEvaluate the decision to have a computer usage policy and the potent.pdf
Evaluate the decision to have a computer usage policy and the potent.pdf
aroraopticals15
ย 
(java) eclipse PleaseDevelop an application that implements a pro.pdf
(java) eclipse PleaseDevelop an application that implements a pro.pdf(java) eclipse PleaseDevelop an application that implements a pro.pdf
(java) eclipse PleaseDevelop an application that implements a pro.pdf
aroraopticals15
ย 
Write short descriptive answer to the following questions Discuss wh.pdf
Write short descriptive answer to the following questions  Discuss wh.pdfWrite short descriptive answer to the following questions  Discuss wh.pdf
Write short descriptive answer to the following questions Discuss wh.pdf
aroraopticals15
ย 
Why do viral particles, zymosan on fungi, endotoxin (LPS) from gram .pdf
Why do viral particles, zymosan on fungi, endotoxin (LPS) from gram .pdfWhy do viral particles, zymosan on fungi, endotoxin (LPS) from gram .pdf
Why do viral particles, zymosan on fungi, endotoxin (LPS) from gram .pdf
aroraopticals15
ย 
Which of following is not a class of the phylum platyhelminthes Tre.pdf
Which of following is not a class of the phylum platyhelminthes  Tre.pdfWhich of following is not a class of the phylum platyhelminthes  Tre.pdf
Which of following is not a class of the phylum platyhelminthes Tre.pdf
aroraopticals15
ย 
what is the process in society that made this change to advertising .pdf
what is the process in society that made this change to advertising .pdfwhat is the process in society that made this change to advertising .pdf
what is the process in society that made this change to advertising .pdf
aroraopticals15
ย 
Use the following word bank to complete the numbers 51-100. Acoeloma.pdf
Use the following word bank to complete the numbers 51-100.  Acoeloma.pdfUse the following word bank to complete the numbers 51-100.  Acoeloma.pdf
Use the following word bank to complete the numbers 51-100. Acoeloma.pdf
aroraopticals15
ย 

More from aroraopticals15 (20)

For a given H0 and level of significance, if you reject the H0 for a.pdf
For a given H0 and level of significance, if you reject the H0 for a.pdfFor a given H0 and level of significance, if you reject the H0 for a.pdf
For a given H0 and level of significance, if you reject the H0 for a.pdf
ย 
Find all elements of our ring R that have norm 1. Show that no elemen.pdf
Find all elements of our ring R that have norm 1. Show that no elemen.pdfFind all elements of our ring R that have norm 1. Show that no elemen.pdf
Find all elements of our ring R that have norm 1. Show that no elemen.pdf
ย 
Evaluate the decision to have a computer usage policy and the potent.pdf
Evaluate the decision to have a computer usage policy and the potent.pdfEvaluate the decision to have a computer usage policy and the potent.pdf
Evaluate the decision to have a computer usage policy and the potent.pdf
ย 
(java) eclipse PleaseDevelop an application that implements a pro.pdf
(java) eclipse PleaseDevelop an application that implements a pro.pdf(java) eclipse PleaseDevelop an application that implements a pro.pdf
(java) eclipse PleaseDevelop an application that implements a pro.pdf
ย 
At a sudden contraction in a pipe the diameter changes from D_1 to D_.pdf
At a sudden contraction in a pipe the diameter changes from D_1 to D_.pdfAt a sudden contraction in a pipe the diameter changes from D_1 to D_.pdf
At a sudden contraction in a pipe the diameter changes from D_1 to D_.pdf
ย 
Above is a trace depicting mechanical activity of frog heart. A stud.pdf
Above is a trace depicting mechanical activity of frog heart. A stud.pdfAbove is a trace depicting mechanical activity of frog heart. A stud.pdf
Above is a trace depicting mechanical activity of frog heart. A stud.pdf
ย 
A gymnosperm, such as Juniperus virginiana, that produces female con.pdf
A gymnosperm, such as Juniperus virginiana, that produces female con.pdfA gymnosperm, such as Juniperus virginiana, that produces female con.pdf
A gymnosperm, such as Juniperus virginiana, that produces female con.pdf
ย 
Write short descriptive answer to the following questions Discuss wh.pdf
Write short descriptive answer to the following questions  Discuss wh.pdfWrite short descriptive answer to the following questions  Discuss wh.pdf
Write short descriptive answer to the following questions Discuss wh.pdf
ย 
Why should anyone else care about what I do with my sewage on my own .pdf
Why should anyone else care about what I do with my sewage on my own .pdfWhy should anyone else care about what I do with my sewage on my own .pdf
Why should anyone else care about what I do with my sewage on my own .pdf
ย 
Why do viral particles, zymosan on fungi, endotoxin (LPS) from gram .pdf
Why do viral particles, zymosan on fungi, endotoxin (LPS) from gram .pdfWhy do viral particles, zymosan on fungi, endotoxin (LPS) from gram .pdf
Why do viral particles, zymosan on fungi, endotoxin (LPS) from gram .pdf
ย 
Which of the following used historicalcomparative methods in their .pdf
Which of the following used historicalcomparative methods in their .pdfWhich of the following used historicalcomparative methods in their .pdf
Which of the following used historicalcomparative methods in their .pdf
ย 
Which of following is not a class of the phylum platyhelminthes Tre.pdf
Which of following is not a class of the phylum platyhelminthes  Tre.pdfWhich of following is not a class of the phylum platyhelminthes  Tre.pdf
Which of following is not a class of the phylum platyhelminthes Tre.pdf
ย 
What is wrong with this code Please fix.code#include stdio.h.pdf
What is wrong with this code Please fix.code#include stdio.h.pdfWhat is wrong with this code Please fix.code#include stdio.h.pdf
What is wrong with this code Please fix.code#include stdio.h.pdf
ย 
What are two ways that meiosis could produce gametes that contai.pdf
What are two ways that meiosis could produce gametes that contai.pdfWhat are two ways that meiosis could produce gametes that contai.pdf
What are two ways that meiosis could produce gametes that contai.pdf
ย 
what is the process in society that made this change to advertising .pdf
what is the process in society that made this change to advertising .pdfwhat is the process in society that made this change to advertising .pdf
what is the process in society that made this change to advertising .pdf
ย 
What is the best way to go about designing an Android AppSoluti.pdf
What is the best way to go about designing an Android AppSoluti.pdfWhat is the best way to go about designing an Android AppSoluti.pdf
What is the best way to go about designing an Android AppSoluti.pdf
ย 
Use the following word bank to complete the numbers 51-100. Acoeloma.pdf
Use the following word bank to complete the numbers 51-100.  Acoeloma.pdfUse the following word bank to complete the numbers 51-100.  Acoeloma.pdf
Use the following word bank to complete the numbers 51-100. Acoeloma.pdf
ย 
Two cards are randomly selected from a 52-card deck. What is the pro.pdf
Two cards are randomly selected from a 52-card deck. What is the pro.pdfTwo cards are randomly selected from a 52-card deck. What is the pro.pdf
Two cards are randomly selected from a 52-card deck. What is the pro.pdf
ย 
Two labs are being compared to determine if they are providing the sa.pdf
Two labs are being compared to determine if they are providing the sa.pdfTwo labs are being compared to determine if they are providing the sa.pdf
Two labs are being compared to determine if they are providing the sa.pdf
ย 
This question refers to the ABO blood type locus. Remember that the A.pdf
This question refers to the ABO blood type locus. Remember that the A.pdfThis question refers to the ABO blood type locus. Remember that the A.pdf
This question refers to the ABO blood type locus. Remember that the A.pdf
ย 

Recently uploaded

Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
AnaAcapella
ย 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
EADTU
ย 
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
httgc7rh9c
ย 

Recently uploaded (20)

Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
ย 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
ย 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
ย 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
ย 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
ย 
What is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptxWhat is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptx
ย 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
ย 
Introduction to TechSoupโ€™s Digital Marketing Services and Use Cases
Introduction to TechSoupโ€™s Digital Marketing  Services and Use CasesIntroduction to TechSoupโ€™s Digital Marketing  Services and Use Cases
Introduction to TechSoupโ€™s Digital Marketing Services and Use Cases
ย 
Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17
ย 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
ย 
Simple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfSimple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdf
ย 
How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17
ย 
Economic Importance Of Fungi In Food Additives
Economic Importance Of Fungi In Food AdditivesEconomic Importance Of Fungi In Food Additives
Economic Importance Of Fungi In Food Additives
ย 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
ย 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
ย 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
ย 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
ย 
Play hard learn harder: The Serious Business of Play
Play hard learn harder:  The Serious Business of PlayPlay hard learn harder:  The Serious Business of Play
Play hard learn harder: The Serious Business of Play
ย 
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
ย 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
ย 

Todopackage hwk6; This class contains the configuration of a t.pdf

  • 1. Todo package hwk6; // This class contains the configuration of a type of apartment public class Apartment { int numOfUnits; // the number of apartments of this type Room[] rooms; // rooms in this type of apartment Apartment(int numOfUnits, Room[] rooms) { this.numOfUnits = numOfUnits; this.rooms = rooms; } // return an array of window orders for one unit of this type of apartment WindowOrder[] orderForOneUnit() { // TODO } // return an array of window orders for all units of this type of apartment WindowOrder[] totalOrder() { // TODO } // return text like: // // 15 apartments with (Living room: 5 (6 X 8 window)) (Master bedroom: 3 (4 X 6 window)) (Guest room: 2 (5 X 6 window)) public String toString() { // TODO } } class OneBedroom extends Apartment { OneBedroom(int numOfUnits) { super(numOfUnits, new Room[] { new LivingRoom(), new MasterBedroom() }); } }
  • 2. class TwoBedroom extends Apartment { TwoBedroom(int numOfUnits) { super(numOfUnits, new Room[] { new LivingRoom(), new MasterBedroom(), new GuestRoom() }); } } class ThreeBedroom extends Apartment { ThreeBedroom(int numOfUnits) { super(numOfUnits, new Room[] { new LivingRoom(), new MasterBedroom(), new GuestRoom(), new GuestRoom() }); } // return an array of window orders for all units of this type of apartment // // Notice we have two guest rooms and they have the same size of windows. // override the inherited method to merge the order for the two guest rooms since their windows have the same size @Override WindowOrder[] orderForOneUnit() { // TODO } } package hwk6; public class Building { Apartment[] apartments; public Building(Apartment[] apartments) { this.apartments= apartments; } // Return an array of window orders for all apartments in the building // Ensure that the orders for windows of the same sizes are merged. WindowOrder[] order() { // TODO }
  • 3. // return a string to represent all types of apartments in the building such as: // 20 apartments with (Living room: 5 (6 X 8 window))(Master bedroom: 3 (4 X 6 window)) // 15 apartments with (Living room: 5 (6 X 8 window))(Master bedroom: 3 (4 X 6 window))(Guest room: 2 (5 X 6 window)) // 10 apartments with (Living room: 5 (6 X 8 window))(Master bedroom: 3 (4 X 6 window))(Guest room: 2 (5 X 6 window))(Guest room: 2 (5 X 6 window)) // public String toString() { // TODO } } package hwk6; public class Hwk6 { public static void main(String[] args) { Apartment[] apartments = { new OneBedroom(20), new TwoBedroom(15), new ThreeBedroom(10) }; Building building = new Building(apartments); WindowOrder[] orders = building.order(); System.out.println(building); System.out.println("Window orders are: "); for(WindowOrder order: orders) { System.out.println(order); } } } package hwk6; public class Room { Window window; int numOfWindows; Room(Window window, int numOfWindows) { this.window = window;
  • 4. this.numOfWindows = numOfWindows; } WindowOrder order() { return new WindowOrder(window, numOfWindows); } // Print text like: 5 (6 X 8 window) @Override public String toString() { // TODO } // Two rooms are equal if they contain the same number of windows of the same size @Override public boolean equals(Object that) { // TODO } } class MasterBedroom extends Room { MasterBedroom() { super(new Window(4, 6), 3); } // Call parent's toString method // // return text like: Master bedroom: 3 (4 X 6 window) @Override public String toString() { // TODO } } class GuestRoom extends Room { GuestRoom() { super(new Window(5, 6), 2); } // Call parent's toString method // // return text like: Guest room: 2 (5 X 6 window)
  • 5. @Override public String toString() { // TODO } } class LivingRoom extends Room { LivingRoom() { super(new Window(6, 8), 5); } // Call parent's toString method // // return text like: Living room: 5 (6 X 8 window) @Override public String toString() { // TODO } } package hwk6; public class Window { private final int width, height; public Window(int width, int height) { this.width = width; this.height = height; } // print text like: 4 X 6 window public String toString() { // TODO } // compare window objects by their dimensions public boolean equals(Object that) { // TODO } }
  • 6. class WindowOrder { final Window window; // window description (its width and height) int num; // number of windows for this order WindowOrder(Window window, int num) { this.window = window; this.num = num; } // add the num field of the parameter to the num field of this object // // BUT // // do the merging only of two windows have the same size // do nothing if the size does not match // // return the current object WindowOrder add (WindowOrder order) { // TODO } // update the num field of this object by multiplying it with the parameter // and then return the current object WindowOrder times(int number) { // TODO } // print text like: 20 4 X 6 window @Override public String toString() { // TODO } // Two orders are equal if they contain the same number of windows of the same size. @Override public boolean equals(Object that) { // TODO } }
  • 7. Testing package hwk6; import org.junit.*; import static org.junit.Assert.*; import java.lang.reflect.Field; import org.junit.FixMethodOrder; import org.junit.runners.MethodSorters; @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class Testing { Window window; WindowOrder windoworder; Room room; Room masterbedroom; Room guestroom; Room livingroom; Apartment apartment; Apartment onebedroom; Apartment twobedrom; Apartment threebedroom; Building building; Room []rooms ; Apartment [] apartments; @Before public void setUp() { this.window= new Window(10, 20); windoworder = new WindowOrder(window, 100); this.room= new Room(window, 5); this.masterbedroom= new MasterBedroom(); this.guestroom= new GuestRoom();
  • 8. this.livingroom= new LivingRoom(); rooms =new Room[5]; rooms[0]=masterbedroom; rooms[1]=guestroom; rooms[2]=livingroom; rooms[3]=masterbedroom; rooms[4]=livingroom; this.apartment= new Apartment(30, rooms); this.onebedroom= new OneBedroom(10); this.twobedrom=new TwoBedroom(5); this.threebedroom=new ThreeBedroom(15); apartments = new Apartment[6]; apartments[0] = onebedroom; apartments[1] = twobedrom; apartments[2] = threebedroom; apartments[3] = onebedroom; apartments[4] = onebedroom; apartments[5] = twobedrom; this.building= new Building(apartments); } @After public void tearDown() { this.window= null; this.windoworder=null; this.room= null; this.masterbedroom= null; this.guestroom= null; this.livingroom= null; this.apartment= null; this.onebedroom= null; this.twobedrom=null; this.threebedroom=null;
  • 9. this.building=null; } private Object getField( Object instance, String name ) throws Exception { Class c = instance.getClass(); Field f = c.getDeclaredField( name ); f.setAccessible( true ); return f.get( instance ); } @Test public void AA_TestWindowConstructor() throws Exception{ assertEquals(this.window.getClass().getSimpleName().toString(), "Window"); assertEquals(10,(int)getField(window,"width")); assertEquals(20,getField(window,"height")); } @Test public void AB_TestWindowEquals() throws Exception{ assertTrue(this.window.equals(new Window(10,20))); assertTrue(this.window.equals(this.window)); assertFalse(this.window.equals(new Window(1,20))); } @Test public void BA_TestWindowOrderConstructor(){ assertEquals(this.windoworder.getClass().getSimpleName().toString(), "WindowOrder"); assertEquals(this.window,windoworder.window); assertEquals(100,windoworder.num); } @Test public void BB_Testwindoworderadd(){ WindowOrder w=windoworder.add(new WindowOrder(new Window(10,20), 1000)); assertEquals(windoworder,w); assertEquals(1100,windoworder.num); windoworder=null; }
  • 10. @Test public void BC_Testwindoworderadd(){ WindowOrder w= windoworder.add(new WindowOrder(new Window(20,20), 1000)); assertEquals(windoworder,w); assertEquals(100,windoworder.num); } @Test public void BD_Testwindoworderadd(){ WindowOrder w= windoworder.add(windoworder); assertEquals(windoworder,w); assertEquals(200,windoworder.num); } @Test public void BE_Testwindowordertimes(){ WindowOrder w= windoworder.times(0); assertEquals(windoworder,w); assertEquals(0,windoworder.num); } @Test public void BF_Testwindowordertimes(){ WindowOrder w= windoworder.times(3); assertEquals(windoworder,w); assertEquals(300,windoworder.num); } @Test public void CA_TestRoomConstructor(){ assertEquals(this.room.getClass().getSimpleName().toString(), "Room"); assertEquals(5,room.numOfWindows); assertEquals(window,room.window); } @Test public void CB_TestRoomOrder(){ assertEquals( new WindowOrder(window, 5),room.order()); assertEquals( new WindowOrder(new Window(4, 6), 3),masterbedroom.order()); }
  • 11. @Test public void D_TestMasterBedRoomConstructor(){ assertEquals(this.masterbedroom.getClass().getSimpleName().toString(), "MasterBedroom"); assertEquals(3,masterbedroom.numOfWindows); assertEquals(new Window(4, 6),masterbedroom.window); } @Test public void E_TestGuestRoomConstructor(){ assertEquals(this.guestroom.getClass().getSimpleName().toString(), "GuestRoom"); assertEquals(2,guestroom.numOfWindows); assertEquals(new Window(5, 6),guestroom.window); } @Test public void F_TestLivingRoomConstructor(){ assertEquals(this.livingroom.getClass().getSimpleName().toString(), "LivingRoom"); assertEquals(5,livingroom.numOfWindows); assertEquals(new Window(6, 8),livingroom.window); } @Test public void GA_TestApartmentConstructor(){ assertEquals(this.apartment.getClass().getSimpleName().toString(), "Apartment"); assertEquals(30,apartment.numOfUnits); assertArrayEquals(rooms,apartment.rooms); } @Test public void GB_TestApartmentTotalOrder(){ WindowOrder[] wo = new WindowOrder [5]; wo[0] = new WindowOrder(new Window(4, 6), 90); wo[1] = new WindowOrder(new Window(5, 6), 60); wo[2] = new WindowOrder(new Window(6, 8), 150); wo[3] = new WindowOrder(new Window(4, 6), 90); wo[4] = new WindowOrder(new Window(6, 8), 150); assertArrayEquals(wo ,apartment.totalOrder());
  • 12. } @Test public void HA_TestOneBedroomConstructor(){ assertEquals(this.onebedroom.getClass().getSimpleName().toString(), "OneBedroom"); assertEquals(10,onebedroom.numOfUnits); assertArrayEquals(new Room[] { new LivingRoom(), new MasterBedroom() },onebedroom.rooms); } @Test public void HB_TestOneBedroomorDerForOneUnit(){ WindowOrder[] wo = new WindowOrder [2]; wo[0] = new WindowOrder(new Window(6, 8), 5); wo[1] = new WindowOrder(new Window(4, 6), 3); assertArrayEquals(wo ,onebedroom.orderForOneUnit()); } @Test public void HC_TestOneBedroomTotalOrder(){ WindowOrder[] wo = new WindowOrder [2]; wo[0] = new WindowOrder(new Window(6, 8), 50); wo[1] = new WindowOrder(new Window(4, 6), 30); assertArrayEquals(wo ,onebedroom.totalOrder()); } @Test public void IA_TestTwoBedroomConstructor(){ assertEquals(this.twobedrom.getClass().getSimpleName().toString(), "TwoBedroom"); assertEquals(5,twobedrom.numOfUnits); assertArrayEquals(new Room[] { new LivingRoom(), new MasterBedroom(), new GuestRoom() },twobedrom.rooms); } @Test public void IB_TestTwoBedroomOrderForOneUnit(){ WindowOrder[] wo = new WindowOrder [3]; wo[0] = new WindowOrder(new Window(6, 8), 5);
  • 13. wo[1] = new WindowOrder(new Window(4, 6), 3); wo[2] = new WindowOrder(new Window(5, 6), 2); assertArrayEquals(wo ,twobedrom.orderForOneUnit()); } @Test public void IC_TestTwoBedroomTotalOrder(){ WindowOrder[] wo = new WindowOrder [3]; wo[0] = new WindowOrder(new Window(6, 8), 25); wo[1] = new WindowOrder(new Window(4, 6), 15); wo[2] = new WindowOrder(new Window(5, 6), 10); assertArrayEquals(wo ,twobedrom.totalOrder()); } @Test public void JA_TestThreeBedroomConstructor(){ assertEquals(this.threebedroom.getClass().getSimpleName().toString(), "ThreeBedroom"); assertEquals(15,threebedroom.numOfUnits); assertArrayEquals(new Room[] { new LivingRoom(), new MasterBedroom(), new GuestRoom(), new GuestRoom() },threebedroom.rooms); } @Test public void JB_TestThreeBedroomOrderForOneUnit(){ WindowOrder[] wo = new WindowOrder [3]; wo[0] = new WindowOrder(new Window(6, 8), 5); wo[1] = new WindowOrder(new Window(4, 6), 3); wo[2] = new WindowOrder(new Window(5, 6), 4); assertArrayEquals(wo ,threebedroom.orderForOneUnit()); } @Test public void JC_TestThreeBedroomTotalOrder(){ WindowOrder[] wo = new WindowOrder [3]; wo[0] = new WindowOrder(new Window(6, 8), 75); wo[1] = new WindowOrder(new Window(4, 6), 45);
  • 14. wo[2] = new WindowOrder(new Window(5, 6), 60); assertArrayEquals(wo ,threebedroom.totalOrder()); } @Test public void KA_TestBuildingConstructor(){ assertEquals(this.building.getClass().getSimpleName().toString(), "Building"); assertArrayEquals(apartments,building.apartments); } @Test public void KB_TestBuildingOrderr(){ WindowOrder[] wo = new WindowOrder [3]; wo[0] = new WindowOrder(new Window(6, 8), 275); wo[1] = new WindowOrder(new Window(4, 6), 165); wo[2] = new WindowOrder(new Window(5, 6), 80); assertArrayEquals(wo,building.order()); } @Test public void L_TestWindowToString(){ String expected= "10 X 20 window"; assertEquals(expected,window.toString()); } @Test public void M_TestWindowOrderToString(){ String expected= "100 10 X 20 window"; assertEquals(expected,windoworder.toString()); } @Test public void N_TestApartmentToString(){ String expected= "30 apartments with (Master bedroom: 3 (4 X 6 window))(Guest room: 2 (5 X 6 window))(Living room: 5 (6 X 8 window))(Master bedroom: 3 (4 X 6 window))(Living
  • 15. room: 5 (6 X 8 window))"; assertEquals(expected,apartment.toString()); } @Test public void O_TestoneBedRoomToString(){ String expected= "10 apartments with (Living room: 5 (6 X 8 window))(Master bedroom: 3 (4 X 6 window))"; assertEquals(expected,onebedroom.toString()); } @Test public void P_TestTwoBedRoomToString(){ String expected= "5 apartments with (Living room: 5 (6 X 8 window))(Master bedroom: 3 (4 X 6 window))(Guest room: 2 (5 X 6 window))"; assertEquals(expected,twobedrom.toString()); } @Test public void Q_TestThreeBedRoomToString(){ String expected= "15 apartments with (Living room: 5 (6 X 8 window))(Master bedroom: 3 (4 X 6 window))(Guest room: 2 (5 X 6 window))(Guest room: 2 (5 X 6 window))"; assertEquals(expected,threebedroom.toString()); } @Test public void R_TestMasterRoomToString(){ String expected= "Master bedroom: 3 (4 X 6 window)"; assertEquals(expected,masterbedroom.toString()); } @Test
  • 16. public void S_TestGuestRoomToString(){ String expected= "Guest room: 2 (5 X 6 window)"; assertEquals(expected,guestroom.toString()); } @Test public void T_TestLivingRoomToString(){ String expected= "Living room: 5 (6 X 8 window)"; assertEquals(expected,livingroom.toString()); } @Test public void UTestBuildingToString(){ String expected= "10 apartments with (Living room: 5 (6 X 8 window))(Master bedroom: 3 (4 X 6 window)) "+ "5 apartments with (Living room: 5 (6 X 8 window))(Master bedroom: 3 (4 X 6 window))(Guest room: 2 (5 X 6 window)) "+ "15 apartments with (Living room: 5 (6 X 8 window))(Master bedroom: 3 (4 X 6 window))(Guest room: 2 (5 X 6 window))(Guest room: 2 (5 X 6 window)) "+ "10 apartments with (Living room: 5 (6 X 8 window))(Master bedroom: 3 (4 X 6 window)) "+ "10 apartments with (Living room: 5 (6 X 8 window))(Master bedroom: 3 (4 X 6 window)) "+ "5 apartments with (Living room: 5 (6 X 8 window))(Master bedroom: 3 (4 X 6 window))(Guest room: 2 (5 X 6 window)) "; assertEquals(expected,building.toString()); } } please finish todo. 1 What's the problem? Suppose you want to model an apartment building so that you can calculate the number of windows (and their sizes) that are in the building. We are modelling the building with the following classes: 1. Building, which contains several types of apartments. 2. Apartment and its subclasses OneBedroom, TwoBedroom, and ThreeBedroom An instance of this class is to represent a type of apartments, which in cludes a field to store the number of units of this tvpe. 3. Room and its subclass LivingRoom, MasterBedroom, and GuestRoom Each room has some windows of certain size. Different type of rooms have
  • 17. windows of different sizes. 4. Window and WindowOrder Window object has just the width and height of the window. Window order object has a window object and the number of window for that order. 2 What to implement? You wl fill in the methods for classes described above. The provided code template has instruction in the comments above the methods that vou will implement 3 What is provided? We provide a driver class Hwk6.java, a test class Test.java, and a bunch of template classes. Note that each file may contain multiple classes. I usually group related classes in the same file. For example, the file Apartment.java contains not only Apartment class but also its subclasses. Solution package hwk6; public class Hwk6 { public static void main(String[] args) { Apartment[] apartments = { new OneBedroom(20), new TwoBedroom(15), new ThreeBedroom(10) }; Building building = new Building(apartments); WindowOrder[] orders = building.order(); System.out.println(building.toString()); System.out.println("Window orders are: "); for(WindowOrder order: orders) { System.out.println(order.toString()); } } } package hwk6; public class Building { Apartment[] apartments; public Building(Apartment[] apartments) { this.apartments= apartments; } // Return an array of window orders for all apartments in the building // Ensure that the orders for windows of the same sizes are merged. WindowOrder[] order() {
  • 18. WindowOrder temp[] = new WindowOrder[3]; temp[0] = new WindowOrder(new Window(6,8),0); temp[1] = new WindowOrder(new Window(4,6),0); temp[2] = new WindowOrder(new Window(5,6),0); for(int i=0;i