From b184c2df10ec87259c4181db42fbe630f92c6a26 Mon Sep 17 00:00:00 2001 From: Tetiana Denchyk Date: Thu, 10 Aug 2023 07:25:00 +0300 Subject: [PATCH] created classes Machine, Excavator, Truck, Bulldozer, added array of Machines, created abstract methods doWork and stopWork --- src/main/java/core/basesyntax/Bulldozer.java | 13 +++++++++++++ src/main/java/core/basesyntax/Excavator.java | 13 +++++++++++++ src/main/java/core/basesyntax/Machine.java | 7 +++++++ src/main/java/core/basesyntax/MainApp.java | 11 +++++++++++ src/main/java/core/basesyntax/Truck.java | 13 +++++++++++++ 5 files changed, 57 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..a4263391a --- /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 started to work."); + } + + @Override + public void stopWork() { + System.out.println("Bulldozer stopped 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..2ebeca13a --- /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 started to work."); + } + + @Override + public void stopWork() { + System.out.println("Excavator stopped 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..4219699a5 --- /dev/null +++ b/src/main/java/core/basesyntax/Machine.java @@ -0,0 +1,7 @@ +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..8c8b2cbff 100644 --- a/src/main/java/core/basesyntax/MainApp.java +++ b/src/main/java/core/basesyntax/MainApp.java @@ -1,5 +1,16 @@ 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 (int i = 0; i < machines.length; i++) { + machines[i].doWork(); + machines[i].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..1408a375a --- /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 started to work."); + } + + @Override + public void stopWork() { + System.out.println("Truck stopped working."); + } +}