From cab791c74c34450df5f7b48f85831feca669bcb3 Mon Sep 17 00:00:00 2001 From: Bohdan Maksymenko Date: Fri, 28 Jul 2023 23:10:52 +0300 Subject: [PATCH 1/3] create abstract class Machine and some machines and override 2 methods of abstract classes --- src/main/java/core/basesyntax/Bulldozer.java | 13 +++++++++++++ src/main/java/core/basesyntax/Excavator.java | 13 +++++++++++++ src/main/java/core/basesyntax/Machine.java | 8 ++++++++ src/main/java/core/basesyntax/MainApp.java | 11 ++++++++++- src/main/java/core/basesyntax/Truck.java | 13 +++++++++++++ 5 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 src/main/java/core/basesyntax/Bulldozer.java create mode 100644 src/main/java/core/basesyntax/Excavator.java create mode 100644 src/main/java/core/basesyntax/Machine.java create mode 100644 src/main/java/core/basesyntax/Truck.java diff --git a/src/main/java/core/basesyntax/Bulldozer.java b/src/main/java/core/basesyntax/Bulldozer.java new file mode 100644 index 000000000..2db6035e5 --- /dev/null +++ b/src/main/java/core/basesyntax/Bulldozer.java @@ -0,0 +1,13 @@ +package core.basesyntax; + +public class Bulldozer extends Machine { + @Override + public void doWork() { + System.out.println("Bulldozer is start work"); + } + + @Override + public void stopWork() { + System.out.println("Bulldozer is stop work"); + } +} diff --git a/src/main/java/core/basesyntax/Excavator.java b/src/main/java/core/basesyntax/Excavator.java new file mode 100644 index 000000000..6c494fe82 --- /dev/null +++ b/src/main/java/core/basesyntax/Excavator.java @@ -0,0 +1,13 @@ +package core.basesyntax; + +public class Excavator extends Machine { + @Override + public void doWork() { + System.out.println("Excavator is start work"); + } + + @Override + public void stopWork() { + System.out.println("Excavator is stop work"); + } +} diff --git a/src/main/java/core/basesyntax/Machine.java b/src/main/java/core/basesyntax/Machine.java new file mode 100644 index 000000000..4aea2f871 --- /dev/null +++ b/src/main/java/core/basesyntax/Machine.java @@ -0,0 +1,8 @@ +package core.basesyntax; + +public abstract class Machine { + + public abstract void doWork(); + + public abstract void stopWork(); +} diff --git a/src/main/java/core/basesyntax/MainApp.java b/src/main/java/core/basesyntax/MainApp.java index f99e9a019..a55248504 100644 --- a/src/main/java/core/basesyntax/MainApp.java +++ b/src/main/java/core/basesyntax/MainApp.java @@ -1,5 +1,14 @@ package core.basesyntax; public class MainApp { - + public static void main(String[] args) { + Excavator excavator = new Excavator(); + Bulldozer bulldozer = new Bulldozer(); + Truck truck = new Truck(); + Machine[] machines = {excavator, truck, bulldozer}; + for (Machine machine:machines){ + machine.doWork(); + machine.stopWork(); + } + } } diff --git a/src/main/java/core/basesyntax/Truck.java b/src/main/java/core/basesyntax/Truck.java new file mode 100644 index 000000000..c68d3d0aa --- /dev/null +++ b/src/main/java/core/basesyntax/Truck.java @@ -0,0 +1,13 @@ +package core.basesyntax; + +public class Truck extends Machine { + @Override + public void doWork() { + System.out.println("Truck is start work"); + } + + @Override + public void stopWork() { + System.out.println("Truck is stop work"); + } +} From fb52ff5480c58a217cd3968281f73430e681c3c4 Mon Sep 17 00:00:00 2001 From: Bohdan Maksymenko Date: Fri, 28 Jul 2023 23:27:49 +0300 Subject: [PATCH 2/3] chekstyle fix --- src/main/java/core/basesyntax/MainApp.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/core/basesyntax/MainApp.java b/src/main/java/core/basesyntax/MainApp.java index a55248504..8c11d5d44 100644 --- a/src/main/java/core/basesyntax/MainApp.java +++ b/src/main/java/core/basesyntax/MainApp.java @@ -6,7 +6,7 @@ public static void main(String[] args) { Bulldozer bulldozer = new Bulldozer(); Truck truck = new Truck(); Machine[] machines = {excavator, truck, bulldozer}; - for (Machine machine:machines){ + for (Machine machine:machines) { machine.doWork(); machine.stopWork(); } From fedb59cf380faa35aabcfd3f3ac486b427b2be6c Mon Sep 17 00:00:00 2001 From: Bohdan Maksymenko Date: Mon, 7 Aug 2023 14:37:12 +0300 Subject: [PATCH 3/3] Use polymorphism at the main method and depends on abstract class Machine --- src/main/java/core/basesyntax/MainApp.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/core/basesyntax/MainApp.java b/src/main/java/core/basesyntax/MainApp.java index 8c11d5d44..7e76e7eed 100644 --- a/src/main/java/core/basesyntax/MainApp.java +++ b/src/main/java/core/basesyntax/MainApp.java @@ -2,9 +2,9 @@ public class MainApp { public static void main(String[] args) { - Excavator excavator = new Excavator(); - Bulldozer bulldozer = new Bulldozer(); - Truck truck = new Truck(); + Machine excavator = new Excavator(); + Machine bulldozer = new Bulldozer(); + Machine truck = new Truck(); Machine[] machines = {excavator, truck, bulldozer}; for (Machine machine:machines) { machine.doWork();