From 02062668e7beed544ab0787ae5846f4315c5d80b Mon Sep 17 00:00:00 2001 From: Taras Date: Sun, 30 Jul 2023 23:15:18 +0300 Subject: [PATCH] oop-basic --- src/main/java/core/basesyntax/Bulldozer.java | 14 ++++++++++++++ src/main/java/core/basesyntax/Excavator.java | 13 +++++++++++++ src/main/java/core/basesyntax/Machine.java | 8 ++++++++ src/main/java/core/basesyntax/MainApp.java | 12 +++++++++++- src/main/java/core/basesyntax/Truck.java | 13 +++++++++++++ 5 files changed, 59 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..88757409f --- /dev/null +++ b/src/main/java/core/basesyntax/Bulldozer.java @@ -0,0 +1,14 @@ +package core.basesyntax; + +public class Bulldozer extends Machine { + + @Override + public void doWork() { + System.out.println("Bulldozer starts working"); + } + + @Override + public void stopWork() { + System.out.println("Bulldozer stops working"); + } +} diff --git a/src/main/java/core/basesyntax/Excavator.java b/src/main/java/core/basesyntax/Excavator.java new file mode 100644 index 000000000..41c325d05 --- /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 starts working"); + } + + @Override + public void stopWork() { + System.out.println("Excavator stops working"); + } +} diff --git a/src/main/java/core/basesyntax/Machine.java b/src/main/java/core/basesyntax/Machine.java new file mode 100644 index 000000000..5b8bb3eb3 --- /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..4060b1f67 100644 --- a/src/main/java/core/basesyntax/MainApp.java +++ b/src/main/java/core/basesyntax/MainApp.java @@ -1,5 +1,15 @@ package core.basesyntax; public class MainApp { - + public static void main(String[] args) { + Machine[] array = new Machine[]{ + new Truck(), + new Bulldozer(), + new Excavator() + }; + for (Machine machine : array) { + 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..d86c31fc1 --- /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 starts working"); + } + + @Override + public void stopWork() { + System.out.println("Truck stops working"); + } +}