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..ee9b58f09 --- /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("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..67060173f --- /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("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..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..88e6ee7b8 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[] 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..5d0ee1284 --- /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("Brum-Brum"); + } + + @Override + public void stopWork() { + System.out.println("The Truck stopped working"); + } +}