diff --git a/src/lab3_abstract_factory/ex1/AbstractDoor.java b/src/lab3_abstract_factory/ex1/AbstractDoor.java new file mode 100644 index 0000000..2caf795 --- /dev/null +++ b/src/lab3_abstract_factory/ex1/AbstractDoor.java @@ -0,0 +1,5 @@ +package lab3_abstract_factory.ex1; + +public abstract class AbstractDoor { + public abstract int getPrice(); +} diff --git a/src/lab3_abstract_factory/ex1/AbstractWall.java b/src/lab3_abstract_factory/ex1/AbstractWall.java new file mode 100644 index 0000000..335c4c2 --- /dev/null +++ b/src/lab3_abstract_factory/ex1/AbstractWall.java @@ -0,0 +1,5 @@ +package lab3_abstract_factory.ex1; + +public abstract class AbstractWall { + public abstract int getPrice(); +} diff --git a/src/lab3_abstract_factory/ex1/AbstractWindows.java b/src/lab3_abstract_factory/ex1/AbstractWindows.java new file mode 100644 index 0000000..b7feeef --- /dev/null +++ b/src/lab3_abstract_factory/ex1/AbstractWindows.java @@ -0,0 +1,5 @@ +package lab3_abstract_factory.ex1; + +public abstract class AbstractWindows { + public abstract int getPrice(); +} diff --git a/src/lab3_abstract_factory/ex1/ArchitectOffice.java b/src/lab3_abstract_factory/ex1/ArchitectOffice.java new file mode 100644 index 0000000..2b9ca0e --- /dev/null +++ b/src/lab3_abstract_factory/ex1/ArchitectOffice.java @@ -0,0 +1,26 @@ +package lab3_abstract_factory.ex1; + +import lab3_abstract_factory.ex1.house_factories.DutchHouseFactory; +import lab3_abstract_factory.ex1.house_factories.GermanHouseFactory; +import lab3_abstract_factory.ex1.house_factories.SwissWoodChaletFactory; + +public class ArchitectOffice { + public static void main(String[] args) { + House house1 = new House("Modern German house", + new GermanHouseFactory()); + house1.buildHouse(); + house1.calculatePrice(); + House house2 = new House("Typical dutch house", + new DutchHouseFactory()); + house2.buildHouse(); + house2.calculatePrice(); + House house3 = new House("Swiss wood chalet", + new SwissWoodChaletFactory()); + house3.buildHouse(); + house3.calculatePrice(); + + System.out.println(house1); + System.out.println(house2); + System.out.println(house3); + } +} \ No newline at end of file diff --git a/src/lab3_abstract_factory/ex1/House.java b/src/lab3_abstract_factory/ex1/House.java new file mode 100644 index 0000000..db768b3 --- /dev/null +++ b/src/lab3_abstract_factory/ex1/House.java @@ -0,0 +1,46 @@ +package lab3_abstract_factory.ex1; + +public class House { + private String name; + private HouseFactory houseFactory; + private AbstractWall wall; + private AbstractWindows windows; + private AbstractDoor door; + + public House(String name, HouseFactory houseFactory) { + this.name = name; + this.houseFactory = houseFactory; + } + + public void buildHouse() { + wall = houseFactory.buildWall(); + windows = houseFactory.buildWindows(); + door = houseFactory.buildDoor(); + System.out.println( + "Building a house with " + + wall + + ", " + + windows + + " and a " + + door + ); + } + + public void calculatePrice() { + int total = 0; + total += wall.getPrice(); + total += windows.getPrice(); + total += door.getPrice(); + + System.out.println("Total price: " + total); + } + + @Override + public String toString() { + return "House '" + name + "' (\n" + + " Walls: " + wall + "\n" + + " Windows: " + windows + "\n" + + " Door: " + door + "\n" + + ")"; + } +} diff --git a/src/lab3_abstract_factory/ex1/HouseFactory.java b/src/lab3_abstract_factory/ex1/HouseFactory.java new file mode 100644 index 0000000..2c95d4e --- /dev/null +++ b/src/lab3_abstract_factory/ex1/HouseFactory.java @@ -0,0 +1,7 @@ +package lab3_abstract_factory.ex1; + +public abstract class HouseFactory { + public abstract AbstractWall buildWall(); + public abstract AbstractWindows buildWindows(); + public abstract AbstractDoor buildDoor(); +} diff --git a/src/lab3_abstract_factory/ex1/doors/LargeDoor.java b/src/lab3_abstract_factory/ex1/doors/LargeDoor.java new file mode 100644 index 0000000..375738d --- /dev/null +++ b/src/lab3_abstract_factory/ex1/doors/LargeDoor.java @@ -0,0 +1,15 @@ +package lab3_abstract_factory.ex1.doors; + +import lab3_abstract_factory.ex1.AbstractDoor; + +public class LargeDoor extends AbstractDoor { + @Override + public int getPrice() { + return 50; + } + + @Override + public String toString() { + return "large door"; + } +} diff --git a/src/lab3_abstract_factory/ex1/doors/ThinDoor.java b/src/lab3_abstract_factory/ex1/doors/ThinDoor.java new file mode 100644 index 0000000..fc9dafd --- /dev/null +++ b/src/lab3_abstract_factory/ex1/doors/ThinDoor.java @@ -0,0 +1,15 @@ +package lab3_abstract_factory.ex1.doors; + +import lab3_abstract_factory.ex1.AbstractDoor; + +public class ThinDoor extends AbstractDoor { + @Override + public int getPrice() { + return 25; + } + + @Override + public String toString() { + return "thin door"; + } +} diff --git a/src/lab3_abstract_factory/ex1/house_factories/DutchHouseFactory.java b/src/lab3_abstract_factory/ex1/house_factories/DutchHouseFactory.java new file mode 100644 index 0000000..c1eb6e8 --- /dev/null +++ b/src/lab3_abstract_factory/ex1/house_factories/DutchHouseFactory.java @@ -0,0 +1,26 @@ +package lab3_abstract_factory.ex1.house_factories; + +import lab3_abstract_factory.ex1.AbstractDoor; +import lab3_abstract_factory.ex1.AbstractWall; +import lab3_abstract_factory.ex1.AbstractWindows; +import lab3_abstract_factory.ex1.HouseFactory; +import lab3_abstract_factory.ex1.doors.LargeDoor; +import lab3_abstract_factory.ex1.walls.BricksWall; +import lab3_abstract_factory.ex1.windows.FramedWindows; + +public class DutchHouseFactory extends HouseFactory { + @Override + public AbstractWall buildWall() { + return new BricksWall(); + } + + @Override + public AbstractWindows buildWindows() { + return new FramedWindows(); + } + + @Override + public AbstractDoor buildDoor() { + return new LargeDoor(); + } +} diff --git a/src/lab3_abstract_factory/ex1/house_factories/GermanHouseFactory.java b/src/lab3_abstract_factory/ex1/house_factories/GermanHouseFactory.java new file mode 100644 index 0000000..2803548 --- /dev/null +++ b/src/lab3_abstract_factory/ex1/house_factories/GermanHouseFactory.java @@ -0,0 +1,26 @@ +package lab3_abstract_factory.ex1.house_factories; + +import lab3_abstract_factory.ex1.AbstractDoor; +import lab3_abstract_factory.ex1.AbstractWall; +import lab3_abstract_factory.ex1.AbstractWindows; +import lab3_abstract_factory.ex1.HouseFactory; +import lab3_abstract_factory.ex1.doors.LargeDoor; +import lab3_abstract_factory.ex1.walls.GlassWall; +import lab3_abstract_factory.ex1.windows.FullHeightWindows; + +public class GermanHouseFactory extends HouseFactory { + @Override + public AbstractWall buildWall() { + return new GlassWall(); + } + + @Override + public AbstractWindows buildWindows() { + return new FullHeightWindows(); + } + + @Override + public AbstractDoor buildDoor() { + return new LargeDoor(); + } +} diff --git a/src/lab3_abstract_factory/ex1/house_factories/SwissWoodChaletFactory.java b/src/lab3_abstract_factory/ex1/house_factories/SwissWoodChaletFactory.java new file mode 100644 index 0000000..a93748e --- /dev/null +++ b/src/lab3_abstract_factory/ex1/house_factories/SwissWoodChaletFactory.java @@ -0,0 +1,26 @@ +package lab3_abstract_factory.ex1.house_factories; + +import lab3_abstract_factory.ex1.AbstractDoor; +import lab3_abstract_factory.ex1.AbstractWall; +import lab3_abstract_factory.ex1.AbstractWindows; +import lab3_abstract_factory.ex1.HouseFactory; +import lab3_abstract_factory.ex1.doors.ThinDoor; +import lab3_abstract_factory.ex1.walls.WoodWall; +import lab3_abstract_factory.ex1.windows.FramedWindows; + +public class SwissWoodChaletFactory extends HouseFactory { + @Override + public AbstractWall buildWall() { + return new WoodWall(); + } + + @Override + public AbstractWindows buildWindows() { + return new FramedWindows(); + } + + @Override + public AbstractDoor buildDoor() { + return new ThinDoor(); + } +} diff --git a/src/lab3_abstract_factory/ex1/walls/BricksWall.java b/src/lab3_abstract_factory/ex1/walls/BricksWall.java new file mode 100644 index 0000000..d655246 --- /dev/null +++ b/src/lab3_abstract_factory/ex1/walls/BricksWall.java @@ -0,0 +1,15 @@ +package lab3_abstract_factory.ex1.walls; + +import lab3_abstract_factory.ex1.AbstractWall; + +public class BricksWall extends AbstractWall { + @Override + public int getPrice() { + return 10; + } + + @Override + public String toString() { + return "brick walls"; + } +} diff --git a/src/lab3_abstract_factory/ex1/walls/GlassWall.java b/src/lab3_abstract_factory/ex1/walls/GlassWall.java new file mode 100644 index 0000000..cbd6d76 --- /dev/null +++ b/src/lab3_abstract_factory/ex1/walls/GlassWall.java @@ -0,0 +1,15 @@ +package lab3_abstract_factory.ex1.walls; + +import lab3_abstract_factory.ex1.AbstractWall; + +public class GlassWall extends AbstractWall { + @Override + public int getPrice() { + return 100; + } + + @Override + public String toString() { + return "glass walls"; + } +} diff --git a/src/lab3_abstract_factory/ex1/walls/WoodWall.java b/src/lab3_abstract_factory/ex1/walls/WoodWall.java new file mode 100644 index 0000000..0cb9785 --- /dev/null +++ b/src/lab3_abstract_factory/ex1/walls/WoodWall.java @@ -0,0 +1,15 @@ +package lab3_abstract_factory.ex1.walls; + +import lab3_abstract_factory.ex1.AbstractWall; + +public class WoodWall extends AbstractWall { + @Override + public int getPrice() { + return 1; + } + + @Override + public String toString() { + return "wood walls"; + } +} diff --git a/src/lab3_abstract_factory/ex1/windows/FramedWindows.java b/src/lab3_abstract_factory/ex1/windows/FramedWindows.java new file mode 100644 index 0000000..f857467 --- /dev/null +++ b/src/lab3_abstract_factory/ex1/windows/FramedWindows.java @@ -0,0 +1,15 @@ +package lab3_abstract_factory.ex1.windows; + +import lab3_abstract_factory.ex1.AbstractWindows; + +public class FramedWindows extends AbstractWindows { + @Override + public int getPrice() { + return 100; + } + + @Override + public String toString() { + return "framed windows"; + } +} diff --git a/src/lab3_abstract_factory/ex1/windows/FullHeightWindows.java b/src/lab3_abstract_factory/ex1/windows/FullHeightWindows.java new file mode 100644 index 0000000..1272b7d --- /dev/null +++ b/src/lab3_abstract_factory/ex1/windows/FullHeightWindows.java @@ -0,0 +1,15 @@ +package lab3_abstract_factory.ex1.windows; + +import lab3_abstract_factory.ex1.AbstractWindows; + +public class FullHeightWindows extends AbstractWindows { + @Override + public int getPrice() { + return 200; + } + + @Override + public String toString() { + return "full-height windows"; + } +}