From 1024ddb74ec1564c6f4fa1fdfd30da893a0ae564 Mon Sep 17 00:00:00 2001 From: Volikkk Date: Sun, 20 Oct 2024 22:09:06 +0300 Subject: [PATCH] add new files code --- src/main/java/core/basesyntax/Bulldozer.java | 11 ++++++++++- src/main/java/core/basesyntax/Excavator.java | 11 ++++++++++- src/main/java/core/basesyntax/Machine.java | 5 ++++- src/main/java/core/basesyntax/MainApp.java | 8 +++++++- src/main/java/core/basesyntax/Truck.java | 11 ++++++++++- 5 files changed, 41 insertions(+), 5 deletions(-) diff --git a/src/main/java/core/basesyntax/Bulldozer.java b/src/main/java/core/basesyntax/Bulldozer.java index 0e0a7a0f1..d54b90400 100644 --- a/src/main/java/core/basesyntax/Bulldozer.java +++ b/src/main/java/core/basesyntax/Bulldozer.java @@ -1,4 +1,13 @@ package core.basesyntax; -public class Bulldozer { +public class Bulldozer extends Machine { + @Override + public void doWork() { + System.out.println("Bulldozer started its 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 index 161c1e30f..923d91483 100644 --- a/src/main/java/core/basesyntax/Excavator.java +++ b/src/main/java/core/basesyntax/Excavator.java @@ -1,4 +1,13 @@ package core.basesyntax; -public class Excavator { +public class Excavator extends Machine { + @Override + public void doWork() { + System.out.println("Excavator started its 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 index 041c39f6e..087b5b668 100644 --- a/src/main/java/core/basesyntax/Machine.java +++ b/src/main/java/core/basesyntax/Machine.java @@ -1,4 +1,7 @@ package core.basesyntax; -public class Machine { +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..685aaa37f 100644 --- a/src/main/java/core/basesyntax/MainApp.java +++ b/src/main/java/core/basesyntax/MainApp.java @@ -1,5 +1,11 @@ package core.basesyntax; public class MainApp { - + public static void main(String[] args) { + Machine[] machines = { new Truck(), new Bulldozer(), 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 index fa64a6d65..65cca0280 100644 --- a/src/main/java/core/basesyntax/Truck.java +++ b/src/main/java/core/basesyntax/Truck.java @@ -1,4 +1,13 @@ package core.basesyntax; -public class Truck { +public class Truck extends Machine { + @Override + public void doWork() { + System.out.println("Truck started its work."); + } + + @Override + public void stopWork() { + System.out.println("Truck stopped working."); + } }