From 3c3eb5425de04dd690582ac88b64d21e6f4a2209 Mon Sep 17 00:00:00 2001 From: Olena Stankevych Date: Mon, 17 Jul 2023 01:34:07 +0300 Subject: [PATCH] implemented method doWork and stopWork in Truck, Excavator, Bulldozer classes. Added psvm method in MainApp class --- src/main/java/core/basesyntax/Bulldozer.java | 13 +++++++++++++ src/main/java/core/basesyntax/Excavator.java | 13 +++++++++++++ src/main/java/core/basesyntax/Machine.java | 16 ++++++++++++++++ src/main/java/core/basesyntax/MainApp.java | 11 ++++++++++- src/main/java/core/basesyntax/Truck.java | 13 +++++++++++++ 5 files changed, 65 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..03dff6faf --- /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() { + printStartMessage(getClass().getSimpleName()); + } + + @Override + public void stopWork() { + printStopMessage(getClass().getSimpleName()); + } +} diff --git a/src/main/java/core/basesyntax/Excavator.java b/src/main/java/core/basesyntax/Excavator.java new file mode 100644 index 000000000..5a609f3b6 --- /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() { + printStartMessage(getClass().getSimpleName()); + } + + @Override + public void stopWork() { + printStopMessage(getClass().getSimpleName()); + } +} diff --git a/src/main/java/core/basesyntax/Machine.java b/src/main/java/core/basesyntax/Machine.java new file mode 100644 index 000000000..fb9f613bb --- /dev/null +++ b/src/main/java/core/basesyntax/Machine.java @@ -0,0 +1,16 @@ +package core.basesyntax; + +public abstract class Machine { + + public abstract void doWork(); + + public abstract void stopWork(); + + public void printStartMessage(String message) { + System.out.println(message + " started working"); + } + + public void printStopMessage(String message) { + System.out.println(message + " stopped working"); + } +} diff --git a/src/main/java/core/basesyntax/MainApp.java b/src/main/java/core/basesyntax/MainApp.java index f99e9a019..520a5a2d3 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) { + Machine truck = new Truck(); + Machine bulldozer = new Bulldozer(); + Machine excavator = new Excavator(); + Machine[] machines = {truck, bulldozer, 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..3404bfbe3 --- /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() { + printStartMessage(getClass().getSimpleName()); + } + + @Override + public void stopWork() { + printStopMessage(getClass().getSimpleName()); + } +}