added lab3 ex1
This commit is contained in:
parent
1ab845574a
commit
5fbcd72ea6
5
src/lab3_abstract_factory/ex1/AbstractDoor.java
Normal file
5
src/lab3_abstract_factory/ex1/AbstractDoor.java
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package lab3_abstract_factory.ex1;
|
||||||
|
|
||||||
|
public abstract class AbstractDoor {
|
||||||
|
public abstract int getPrice();
|
||||||
|
}
|
5
src/lab3_abstract_factory/ex1/AbstractWall.java
Normal file
5
src/lab3_abstract_factory/ex1/AbstractWall.java
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package lab3_abstract_factory.ex1;
|
||||||
|
|
||||||
|
public abstract class AbstractWall {
|
||||||
|
public abstract int getPrice();
|
||||||
|
}
|
5
src/lab3_abstract_factory/ex1/AbstractWindows.java
Normal file
5
src/lab3_abstract_factory/ex1/AbstractWindows.java
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package lab3_abstract_factory.ex1;
|
||||||
|
|
||||||
|
public abstract class AbstractWindows {
|
||||||
|
public abstract int getPrice();
|
||||||
|
}
|
26
src/lab3_abstract_factory/ex1/ArchitectOffice.java
Normal file
26
src/lab3_abstract_factory/ex1/ArchitectOffice.java
Normal file
@ -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);
|
||||||
|
}
|
||||||
|
}
|
46
src/lab3_abstract_factory/ex1/House.java
Normal file
46
src/lab3_abstract_factory/ex1/House.java
Normal file
@ -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"
|
||||||
|
+ ")";
|
||||||
|
}
|
||||||
|
}
|
7
src/lab3_abstract_factory/ex1/HouseFactory.java
Normal file
7
src/lab3_abstract_factory/ex1/HouseFactory.java
Normal file
@ -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();
|
||||||
|
}
|
15
src/lab3_abstract_factory/ex1/doors/LargeDoor.java
Normal file
15
src/lab3_abstract_factory/ex1/doors/LargeDoor.java
Normal file
@ -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";
|
||||||
|
}
|
||||||
|
}
|
15
src/lab3_abstract_factory/ex1/doors/ThinDoor.java
Normal file
15
src/lab3_abstract_factory/ex1/doors/ThinDoor.java
Normal file
@ -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";
|
||||||
|
}
|
||||||
|
}
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
15
src/lab3_abstract_factory/ex1/walls/BricksWall.java
Normal file
15
src/lab3_abstract_factory/ex1/walls/BricksWall.java
Normal file
@ -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";
|
||||||
|
}
|
||||||
|
}
|
15
src/lab3_abstract_factory/ex1/walls/GlassWall.java
Normal file
15
src/lab3_abstract_factory/ex1/walls/GlassWall.java
Normal file
@ -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";
|
||||||
|
}
|
||||||
|
}
|
15
src/lab3_abstract_factory/ex1/walls/WoodWall.java
Normal file
15
src/lab3_abstract_factory/ex1/walls/WoodWall.java
Normal file
@ -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";
|
||||||
|
}
|
||||||
|
}
|
15
src/lab3_abstract_factory/ex1/windows/FramedWindows.java
Normal file
15
src/lab3_abstract_factory/ex1/windows/FramedWindows.java
Normal file
@ -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";
|
||||||
|
}
|
||||||
|
}
|
15
src/lab3_abstract_factory/ex1/windows/FullHeightWindows.java
Normal file
15
src/lab3_abstract_factory/ex1/windows/FullHeightWindows.java
Normal file
@ -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";
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user