From a37eaed90fc5b036d3887258b224b8b0c669486b Mon Sep 17 00:00:00 2001 From: "Dymchenko, Mykola" Date: Tue, 8 Oct 2024 07:46:42 -0500 Subject: [PATCH 1/3] - Created abstract class Machine and abstract methods for this class doWork(), stopWork() - Created new classes: Bulldozer, Excavator, Truck and extended them from the superclass Machine - Overridden methods: doWork() and stopWork() for each subclass - updated class MainApp: - added new Machine array with Truck, Bulldozer and Excavator and call methods doWork() and stopWork() in a loop --- src/main/java/core/basesyntax/Bulldozer.java | 18 ++++++++++++++++++ src/main/java/core/basesyntax/Excavator.java | 18 ++++++++++++++++++ src/main/java/core/basesyntax/Machine.java | 12 ++++++++++++ src/main/java/core/basesyntax/MainApp.java | 10 ++++++++++ src/main/java/core/basesyntax/Truck.java | 18 ++++++++++++++++++ 5 files changed, 76 insertions(+) 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..87964f07e --- /dev/null +++ b/src/main/java/core/basesyntax/Bulldozer.java @@ -0,0 +1,18 @@ +package core.basesyntax; + +public class Bulldozer extends Machine { + + public Bulldozer() { + + } + + @Override + public void doWork() { + System.out.println("Bulldozer started"); + } + + @Override + public void stopWork() { + System.out.println("Bulldozer stopped"); + } +} diff --git a/src/main/java/core/basesyntax/Excavator.java b/src/main/java/core/basesyntax/Excavator.java new file mode 100644 index 000000000..cd89d4e61 --- /dev/null +++ b/src/main/java/core/basesyntax/Excavator.java @@ -0,0 +1,18 @@ +package core.basesyntax; + +public class Excavator extends Machine { + + public Excavator() { + + } + + @Override + public void doWork() { + System.out.println("Excavator started"); + } + + @Override + public void stopWork() { + System.out.println("Excavator stopped"); + } +} diff --git a/src/main/java/core/basesyntax/Machine.java b/src/main/java/core/basesyntax/Machine.java new file mode 100644 index 000000000..d1aee3664 --- /dev/null +++ b/src/main/java/core/basesyntax/Machine.java @@ -0,0 +1,12 @@ +package core.basesyntax; + +public abstract class Machine { + + public 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..138c73fba 100644 --- a/src/main/java/core/basesyntax/MainApp.java +++ b/src/main/java/core/basesyntax/MainApp.java @@ -2,4 +2,14 @@ public class MainApp { + public static void main(String[] args) { + Machine[] machines = new Machine[3]; + machines[0] = new Bulldozer(); + machines[1] = new Truck(); + machines[2] = new Excavator(); + 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..2d5ea0b33 --- /dev/null +++ b/src/main/java/core/basesyntax/Truck.java @@ -0,0 +1,18 @@ +package core.basesyntax; + +public class Truck extends Machine { + + public Truck() { + + } + + @Override + public void doWork() { + System.out.println("Truck started"); + } + + @Override + public void stopWork() { + System.out.println("Truck stopped"); + } +} From 5b4a5d9311152c61308043c13cd42da49bb686ab Mon Sep 17 00:00:00 2001 From: "Dymchenko, Mykola" Date: Tue, 8 Oct 2024 08:08:20 -0500 Subject: [PATCH 2/3] - removed constructors from the classes: Machine, Bulldozer, Truck, Excavator --- src/main/java/core/basesyntax/Bulldozer.java | 4 ---- src/main/java/core/basesyntax/Excavator.java | 4 ---- src/main/java/core/basesyntax/Machine.java | 4 ---- src/main/java/core/basesyntax/Truck.java | 4 ---- 4 files changed, 16 deletions(-) diff --git a/src/main/java/core/basesyntax/Bulldozer.java b/src/main/java/core/basesyntax/Bulldozer.java index 87964f07e..2ef132f5f 100644 --- a/src/main/java/core/basesyntax/Bulldozer.java +++ b/src/main/java/core/basesyntax/Bulldozer.java @@ -2,10 +2,6 @@ public class Bulldozer extends Machine { - public Bulldozer() { - - } - @Override public void doWork() { System.out.println("Bulldozer started"); diff --git a/src/main/java/core/basesyntax/Excavator.java b/src/main/java/core/basesyntax/Excavator.java index cd89d4e61..1144d288b 100644 --- a/src/main/java/core/basesyntax/Excavator.java +++ b/src/main/java/core/basesyntax/Excavator.java @@ -2,10 +2,6 @@ public class Excavator extends Machine { - public Excavator() { - - } - @Override public void doWork() { System.out.println("Excavator started"); diff --git a/src/main/java/core/basesyntax/Machine.java b/src/main/java/core/basesyntax/Machine.java index d1aee3664..4aea2f871 100644 --- a/src/main/java/core/basesyntax/Machine.java +++ b/src/main/java/core/basesyntax/Machine.java @@ -2,10 +2,6 @@ public abstract class Machine { - public Machine() { - - } - public abstract void doWork(); public abstract void stopWork(); diff --git a/src/main/java/core/basesyntax/Truck.java b/src/main/java/core/basesyntax/Truck.java index 2d5ea0b33..3af5b4693 100644 --- a/src/main/java/core/basesyntax/Truck.java +++ b/src/main/java/core/basesyntax/Truck.java @@ -2,10 +2,6 @@ public class Truck extends Machine { - public Truck() { - - } - @Override public void doWork() { System.out.println("Truck started"); From cdb1f613c5072db8d008c0acf606119504c214a6 Mon Sep 17 00:00:00 2001 From: "Dymchenko, Mykola" Date: Tue, 8 Oct 2024 08:33:23 -0500 Subject: [PATCH 3/3] - removed extra spaces --- src/main/java/core/basesyntax/Bulldozer.java | 1 - src/main/java/core/basesyntax/Excavator.java | 1 - src/main/java/core/basesyntax/Machine.java | 1 - src/main/java/core/basesyntax/MainApp.java | 1 - src/main/java/core/basesyntax/Truck.java | 1 - 5 files changed, 5 deletions(-) diff --git a/src/main/java/core/basesyntax/Bulldozer.java b/src/main/java/core/basesyntax/Bulldozer.java index 2ef132f5f..25f157ba3 100644 --- a/src/main/java/core/basesyntax/Bulldozer.java +++ b/src/main/java/core/basesyntax/Bulldozer.java @@ -1,7 +1,6 @@ package core.basesyntax; public class Bulldozer extends Machine { - @Override public void doWork() { System.out.println("Bulldozer started"); diff --git a/src/main/java/core/basesyntax/Excavator.java b/src/main/java/core/basesyntax/Excavator.java index 1144d288b..f8c1e221f 100644 --- a/src/main/java/core/basesyntax/Excavator.java +++ b/src/main/java/core/basesyntax/Excavator.java @@ -1,7 +1,6 @@ package core.basesyntax; public class Excavator extends Machine { - @Override public void doWork() { System.out.println("Excavator started"); diff --git a/src/main/java/core/basesyntax/Machine.java b/src/main/java/core/basesyntax/Machine.java index 4aea2f871..cad5be453 100644 --- a/src/main/java/core/basesyntax/Machine.java +++ b/src/main/java/core/basesyntax/Machine.java @@ -1,7 +1,6 @@ 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 138c73fba..dd589af9d 100644 --- a/src/main/java/core/basesyntax/MainApp.java +++ b/src/main/java/core/basesyntax/MainApp.java @@ -1,7 +1,6 @@ package core.basesyntax; public class MainApp { - public static void main(String[] args) { Machine[] machines = new Machine[3]; machines[0] = new Bulldozer(); diff --git a/src/main/java/core/basesyntax/Truck.java b/src/main/java/core/basesyntax/Truck.java index 3af5b4693..bceb54f4e 100644 --- a/src/main/java/core/basesyntax/Truck.java +++ b/src/main/java/core/basesyntax/Truck.java @@ -1,7 +1,6 @@ package core.basesyntax; public class Truck extends Machine { - @Override public void doWork() { System.out.println("Truck started");