From 04ee5d34f595b5e2d49c5c9578180c412dc34954 Mon Sep 17 00:00:00 2001 From: Bohdan_SSX Date: Tue, 3 Dec 2024 19:08:36 +0200 Subject: [PATCH] Added jv-oop classes --- src/main/java/core/basesyntax/Bulldozer.java | 14 ++++++++++++++ src/main/java/core/basesyntax/Excavator.java | 14 ++++++++++++++ src/main/java/core/basesyntax/Machine.java | 8 ++++++++ src/main/java/core/basesyntax/MainApp.java | 13 ++++++++++++- src/main/java/core/basesyntax/Truck.java | 14 ++++++++++++++ 5 files changed, 62 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..db398b78f --- /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(getClass().getSimpleName() + " started its work"); + } + + @Override + public void stopWork() { + System.out.println(getClass().getSimpleName() + " 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..5b336027c --- /dev/null +++ b/src/main/java/core/basesyntax/Excavator.java @@ -0,0 +1,14 @@ +package core.basesyntax; + +public class Excavator extends Machine { + + @Override + public void doWork() { + System.out.println(getClass().getSimpleName() + " started its work"); + } + + @Override + public void stopWork() { + System.out.println(getClass().getSimpleName() + " 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..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..51898e8fa 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[] arr = {truck, bulldozer, excavator}; + for (Machine machine : arr) { + 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..c56348f21 --- /dev/null +++ b/src/main/java/core/basesyntax/Truck.java @@ -0,0 +1,14 @@ +package core.basesyntax; + +public class Truck extends Machine { + + @Override + public void doWork() { + System.out.println(getClass().getSimpleName() + " started its work"); + } + + @Override + public void stopWork() { + System.out.println(getClass().getSimpleName() + " stopped working"); + } +}