Templates Hwk6java package hwk6 public class Hwk6 public st

Templates

Hwk6.java

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);
       }
   }
}

Apartment.java

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
   }
}

Building.java

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
   }
}

Room.java

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
   }
}

Window.java

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.java

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());
}
  
}

Solution

// i provided the output almost window order i didn\'t provided do somechanges what you required

solution

package com.bp.common;

import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;

public class Apartment {
   int numOfUnits; // the number of apartments of this type
   Window window;
   WindowOrder order;
   List<WindowOrder> list;
   /**
   * @return the numOfUnits
   */
   public int getNumOfUnits() {
       return numOfUnits;
   }

   /**
   * @param numOfUnits the numOfUnits to set
   */
   public void setNumOfUnits(int numOfUnits) {
       this.numOfUnits = numOfUnits;
   }

   Room[] rooms; // rooms in this type of apartment
   private int num;
  
   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
   List<WindowOrder> orderForOneUnit() {
      
      
       WindowOrder order=new WindowOrder(window, num);
       Apartment apartment=new Apartment(numOfUnits, rooms);
       if((apartment.numOfUnits)==(order.num))
          
       {
          
           List list=new ArrayList();
           list.add(order);
       }
      
       return list;
     
   }
  
  
       @Override
   public String toString() {
       return \"Apartment [numOfUnits=\" + numOfUnits + \", rooms=\" + Arrays.toString(rooms) + \"]\";
   }
  
   // 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))
     
}

package com.bp.common;

import java.util.Arrays;

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() {
       return null;
   // TODO
   }

   @Override
   public String toString() {
       return \"Building [apartments=\" + Arrays.toString(apartments) + \"]\";
   }
  
   // 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))
   //
     

}

package com.bp.common;

public class GuestBedRoom extends Room{
   GuestBedRoom() {
   super(new Window(5, 6), 2);
   }
   // Call parent\'s toString method
   //
   // return text like: Guest room: 2 (5 X 6 window)

   /* (non-Javadoc)
   * @see java.lang.Object#toString()
   */
   @Override
   public String toString() {
       return super.toString();
   }
     

}

package com.bp.common;

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);
  
  
}
}

package com.bp.common;

public 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)

   /* (non-Javadoc)
   * @see java.lang.Object#toString()
   */
   @Override
   public String toString() {
       System.out.println(super.toString());
       return \"LivingRoom [window=\" + window + \", numOfWindows=\" + numOfWindows + \", order()=\" + order()
               + \", toString()=\" + super.toString() + \", getClass()=\" + getClass() + \", hashCode()=\" + hashCode()
               + \"]\";
   }
  

}

package com.bp.common;

public 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() {
       return super.toString();
   // TODO
   }

}

package com.bp.common;

public class OneBedRoom extends Apartment{
   OneBedRoom(int numOfUnits) {
   super(numOfUnits, new Room[] { new LivingRoom(), new MasterBedRoom() });
   }

}

package com.bp.common;

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)
     
   // Two rooms are equal if they contain the same number of windows of the same size
     
   /* (non-Javadoc)
   * @see java.lang.Object#toString()
   */
   @Override
   public String toString() {
       return \"Room [window=\" + window + \", numOfWindows=\" + numOfWindows + \"]\";
   }

   /* (non-Javadoc)
   * @see java.lang.Object#hashCode()
   */
   @Override
   public int hashCode() {
       final int prime = 31;
       int result = 1;
       result = prime * result + numOfWindows;
       result = prime * result + ((window == null) ? 0 : window.hashCode());
       return result;
   }

   /* (non-Javadoc)
   * @see java.lang.Object#equals(java.lang.Object)
   */
   @Override
   public boolean equals(Object obj) {
       if (this == obj)
           return true;
       if (obj == null)
           return false;
       if (getClass() != obj.getClass())
           return false;
       Room other = (Room) obj;
       if (numOfWindows != other.numOfWindows)
           return false;
       if (window == null) {
           if (other.window != null)
               return false;
       } else if (!window.equals(other.window))
           return false;
       return true;
   }
}

package com.bp.common;

public class ThreeBedRoom extends Apartment{
   ThreeBedRoom(int numOfUnits) {
   super(numOfUnits, new Room[] { new LivingRoom(), new MasterBedRoom(), new GuestBedRoom(), new GuestBedRoom() });
   }
  
   // 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
     
}

package com.bp.common;

public class TwoBedRoom extends Apartment{

  
  
   TwoBedRoom(int numOfUnits) {
   super(numOfUnits, new Room[] { new LivingRoom(), new MasterBedRoom(), new GuestBedRoom() });

}
}

package com.bp.common;

public class Window {
   private final int width, height;
     
   public Window(int height, int width) {
   this.width = width;
   this.height = height;
   }
  
  
     
   // compare window objects by their dimensions
     
   // print text like: 4 X 6 window
   @Override
   public String toString() {
       return \"Window [width=\" + width + \"*\" + height + \"]\";
   }

   /* (non-Javadoc)
   * @see java.lang.Object#hashCode()
   */
   @Override
   public int hashCode() {
       final int prime = 31;
       int result = 1;
       result = prime * result + height;
       result = prime * result + width;
       return result;
   }

   @Override
   public boolean equals(Object obj) {
       if (this == obj)
           return true;
       if (obj == null)
           return false;
       if (getClass() != obj.getClass())
           return false;
       Window other = (Window) obj;
       if (height != other.height)
           return false;
       if (width != other.width)
           return false;
       return true;
   }

}

package com.bp.common;

public class WindowOrder {
   final Window window; // window description (its width and height)
   int num; // number of windows for this order
   private WindowOrder 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) {
         
         
   return this.order=order;
   }
   /**
   * @return the num
   */
   public int getNum() {
       return num;
   }
   /**
   * @param num the num to set
   */
   public void setNum(int num) {
       this.num = num;
   }
   // update the num field of this object by multiplying it with the parameter
   // and then return the current object
   WindowOrder times(int number) {
      
   int no=order.getNum();
   int modifiedno=no*number;
   order.setNum(modifiedno);
   return order;
   }
  
     
  
   // Two orders are equal if they contain the same number of windows of the same size.
  
   @Override
   public String toString() {
       return \"WindowOrder [window=\" + window + \", num=\" + num + \", order=\" + order + \"]\";
   }
   @Override
   public int hashCode() {
       final int prime = 31;
       int result = 1;
       result = prime * result + num;
       result = prime * result + ((window == null) ? 0 : window.hashCode());
       return result;
   }
   @Override
   public boolean equals(Object obj) {
       if (this == obj)
           return true;
       if (obj == null)
           return false;
       if (getClass() != obj.getClass())
           return false;
       WindowOrder other = (WindowOrder) obj;
       if (num != other.num)
           return false;
       if (window == null) {
           if (other.window != null)
               return false;
       } else if (!window.equals(other.window))
           return false;
       return true;
   }
   }

Templates Hwk6.java package hwk6; public class Hwk6 { public static void main(String[] args) { Apartment[] apartments = { new OneBedroom(20), new TwoBedroom(15)
Templates Hwk6.java package hwk6; public class Hwk6 { public static void main(String[] args) { Apartment[] apartments = { new OneBedroom(20), new TwoBedroom(15)
Templates Hwk6.java package hwk6; public class Hwk6 { public static void main(String[] args) { Apartment[] apartments = { new OneBedroom(20), new TwoBedroom(15)
Templates Hwk6.java package hwk6; public class Hwk6 { public static void main(String[] args) { Apartment[] apartments = { new OneBedroom(20), new TwoBedroom(15)
Templates Hwk6.java package hwk6; public class Hwk6 { public static void main(String[] args) { Apartment[] apartments = { new OneBedroom(20), new TwoBedroom(15)
Templates Hwk6.java package hwk6; public class Hwk6 { public static void main(String[] args) { Apartment[] apartments = { new OneBedroom(20), new TwoBedroom(15)
Templates Hwk6.java package hwk6; public class Hwk6 { public static void main(String[] args) { Apartment[] apartments = { new OneBedroom(20), new TwoBedroom(15)
Templates Hwk6.java package hwk6; public class Hwk6 { public static void main(String[] args) { Apartment[] apartments = { new OneBedroom(20), new TwoBedroom(15)
Templates Hwk6.java package hwk6; public class Hwk6 { public static void main(String[] args) { Apartment[] apartments = { new OneBedroom(20), new TwoBedroom(15)
Templates Hwk6.java package hwk6; public class Hwk6 { public static void main(String[] args) { Apartment[] apartments = { new OneBedroom(20), new TwoBedroom(15)
Templates Hwk6.java package hwk6; public class Hwk6 { public static void main(String[] args) { Apartment[] apartments = { new OneBedroom(20), new TwoBedroom(15)
Templates Hwk6.java package hwk6; public class Hwk6 { public static void main(String[] args) { Apartment[] apartments = { new OneBedroom(20), new TwoBedroom(15)
Templates Hwk6.java package hwk6; public class Hwk6 { public static void main(String[] args) { Apartment[] apartments = { new OneBedroom(20), new TwoBedroom(15)
Templates Hwk6.java package hwk6; public class Hwk6 { public static void main(String[] args) { Apartment[] apartments = { new OneBedroom(20), new TwoBedroom(15)
Templates Hwk6.java package hwk6; public class Hwk6 { public static void main(String[] args) { Apartment[] apartments = { new OneBedroom(20), new TwoBedroom(15)
Templates Hwk6.java package hwk6; public class Hwk6 { public static void main(String[] args) { Apartment[] apartments = { new OneBedroom(20), new TwoBedroom(15)
Templates Hwk6.java package hwk6; public class Hwk6 { public static void main(String[] args) { Apartment[] apartments = { new OneBedroom(20), new TwoBedroom(15)

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site