From 9187955284e4e888e43eecd8e3785520520c96c7 Mon Sep 17 00:00:00 2001 From: Piotr Kaliszuk Date: Fri, 15 Sep 2023 22:01:19 +0200 Subject: [PATCH 1/4] First Solution --- checklist.md | 49 -------------------- src/main/java/core/basesyntax/Bulldozer.java | 12 +++++ src/main/java/core/basesyntax/Excavator.java | 12 +++++ src/main/java/core/basesyntax/Machine.java | 6 +++ src/main/java/core/basesyntax/MainApp.java | 11 ++++- src/main/java/core/basesyntax/Truck.java | 12 +++++ 6 files changed, 52 insertions(+), 50 deletions(-) delete mode 100644 checklist.md 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/checklist.md b/checklist.md deleted file mode 100644 index 46121f865..000000000 --- a/checklist.md +++ /dev/null @@ -1,49 +0,0 @@ -## Common mistakes (jv-oop) - -#### Please don't add redundant empty lines to your code. -We don't need them after class declaration or method signature. -* Bad example: -``` -public class Main { - - public static void main(String[] args) { - - System.out.println("Hello world!"); - } -} -``` -* Improved example: -``` -public class Main { - public static void main(String[] args) { - System.out.println("Hello world!"); - } -} -``` - -#### Write informative messages in methods. -Use english only and make them informative: -message should indicate what type of `Machine` is working right now `Truck`, `Bulldozer` or `Excavator`. - -#### Use abstract reference instead of specific one where possible: -* Bad example: -``` -Cat fluffy = new Cat(); -Dog oscar = new Dog(); -``` -This example is bad cause it won't allow us to use polymorphism in our code. -Our reference is now bonded to specific implementation, but it is always better to depend on the abstraction. -Let's see how we can improve it: -* Improved example: -``` -Animal fluffy = new Cat(); -Animal oscar = new Dog(); -``` - -#### Depending on the case, class elements should have different access modifiers -Remember that if you don't use any access modifiers that will apply the default one. Do we always want -to have all elements with default access modifiers? Remind yourself about encapsulation principle and -when private or public should be used. - -#### Write informative messages when you commit code or open a PR. -Bad example of commit/PR message: `done`/`fixed`/`commit`/`solution`/`added homework`/`my solution` and other one-word, abstract or random messages. diff --git a/src/main/java/core/basesyntax/Bulldozer.java b/src/main/java/core/basesyntax/Bulldozer.java new file mode 100644 index 000000000..018163f8c --- /dev/null +++ b/src/main/java/core/basesyntax/Bulldozer.java @@ -0,0 +1,12 @@ +package core.basesyntax; + +public class Bulldozer extends Machine{ + @Override + public void doWork() { + System.out.println("Trzasku-Trzask"); + } + @Override + public void stopWork() { + System.out.println("The 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..bbe65f87e --- /dev/null +++ b/src/main/java/core/basesyntax/Excavator.java @@ -0,0 +1,12 @@ +package core.basesyntax; + +public class Excavator extends Machine{ + @Override + public void doWork() { + System.out.println("Kopu-Kop"); + } + @Override + public void stopWork() { + System.out.println("The 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..b3c81d24e --- /dev/null +++ b/src/main/java/core/basesyntax/Machine.java @@ -0,0 +1,6 @@ +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..411e0a22e 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[] machines = {new Bulldozer(), new Excavator(), new Truck()}; + printMethodsInLoop(machines); + } + public static void printMethodsInLoop(Machine[] machines){ + 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..2a36040e5 --- /dev/null +++ b/src/main/java/core/basesyntax/Truck.java @@ -0,0 +1,12 @@ +package core.basesyntax; + +public class Truck extends Machine{ + @Override + public void doWork() { + System.out.println("Brum-Brum"); + } + @Override + public void stopWork() { + System.out.println("The Truck stopped working"); + } +} From 594aa64262691c64eb9193545ae2b1224d17a5d4 Mon Sep 17 00:00:00 2001 From: Piotr Kaliszuk Date: Fri, 15 Sep 2023 22:07:51 +0200 Subject: [PATCH 2/4] First solution --- src/main/java/core/basesyntax/Bulldozer.java | 3 ++- src/main/java/core/basesyntax/Excavator.java | 3 ++- src/main/java/core/basesyntax/MainApp.java | 1 + src/main/java/core/basesyntax/Truck.java | 3 ++- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/core/basesyntax/Bulldozer.java b/src/main/java/core/basesyntax/Bulldozer.java index 018163f8c..ee9b58f09 100644 --- a/src/main/java/core/basesyntax/Bulldozer.java +++ b/src/main/java/core/basesyntax/Bulldozer.java @@ -1,10 +1,11 @@ package core.basesyntax; -public class Bulldozer extends Machine{ +public class Bulldozer extends Machine { @Override public void doWork() { System.out.println("Trzasku-Trzask"); } + @Override public void stopWork() { System.out.println("The Bulldozer stopped working"); diff --git a/src/main/java/core/basesyntax/Excavator.java b/src/main/java/core/basesyntax/Excavator.java index bbe65f87e..67060173f 100644 --- a/src/main/java/core/basesyntax/Excavator.java +++ b/src/main/java/core/basesyntax/Excavator.java @@ -1,10 +1,11 @@ package core.basesyntax; -public class Excavator extends Machine{ +public class Excavator extends Machine { @Override public void doWork() { System.out.println("Kopu-Kop"); } + @Override public void stopWork() { System.out.println("The Excavator stopped working"); diff --git a/src/main/java/core/basesyntax/MainApp.java b/src/main/java/core/basesyntax/MainApp.java index 411e0a22e..30ebf115f 100644 --- a/src/main/java/core/basesyntax/MainApp.java +++ b/src/main/java/core/basesyntax/MainApp.java @@ -5,6 +5,7 @@ public static void main(String[] args) { Machine[] machines = {new Bulldozer(), new Excavator(), new Truck()}; printMethodsInLoop(machines); } + public static void printMethodsInLoop(Machine[] machines){ for (Machine machine : machines){ machine.doWork(); diff --git a/src/main/java/core/basesyntax/Truck.java b/src/main/java/core/basesyntax/Truck.java index 2a36040e5..5d0ee1284 100644 --- a/src/main/java/core/basesyntax/Truck.java +++ b/src/main/java/core/basesyntax/Truck.java @@ -1,10 +1,11 @@ package core.basesyntax; -public class Truck extends Machine{ +public class Truck extends Machine { @Override public void doWork() { System.out.println("Brum-Brum"); } + @Override public void stopWork() { System.out.println("The Truck stopped working"); From 82b04d989cc36717a75e90ef69699c79235455bb Mon Sep 17 00:00:00 2001 From: Piotr Kaliszuk Date: Fri, 15 Sep 2023 22:12:30 +0200 Subject: [PATCH 3/4] Deleting Spaces --- src/main/java/core/basesyntax/Machine.java | 1 + src/main/java/core/basesyntax/MainApp.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/core/basesyntax/Machine.java b/src/main/java/core/basesyntax/Machine.java index b3c81d24e..4219699a5 100644 --- a/src/main/java/core/basesyntax/Machine.java +++ b/src/main/java/core/basesyntax/Machine.java @@ -2,5 +2,6 @@ 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 30ebf115f..cee724d31 100644 --- a/src/main/java/core/basesyntax/MainApp.java +++ b/src/main/java/core/basesyntax/MainApp.java @@ -6,7 +6,7 @@ public static void main(String[] args) { printMethodsInLoop(machines); } - public static void printMethodsInLoop(Machine[] machines){ + public static void printMethodsInLoop (Machine[] machines) { for (Machine machine : machines){ machine.doWork(); machine.stopWork(); From 85203c1873e15ba35e953201ddf709087b30a150 Mon Sep 17 00:00:00 2001 From: Piotr Kaliszuk Date: Fri, 15 Sep 2023 22:20:12 +0200 Subject: [PATCH 4/4] "Deleting spaced cd." --- src/main/java/core/basesyntax/MainApp.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/core/basesyntax/MainApp.java b/src/main/java/core/basesyntax/MainApp.java index cee724d31..88e6ee7b8 100644 --- a/src/main/java/core/basesyntax/MainApp.java +++ b/src/main/java/core/basesyntax/MainApp.java @@ -6,8 +6,8 @@ public static void main(String[] args) { printMethodsInLoop(machines); } - public static void printMethodsInLoop (Machine[] machines) { - for (Machine machine : machines){ + public static void printMethodsInLoop(Machine[] machines) { + for (Machine machine : machines) { machine.doWork(); machine.stopWork(); }