Created abstract class Machine with doWork() and stopWork() methods. …#2585
Created abstract class Machine with doWork() and stopWork() methods. …#2585daryna-mitina wants to merge 2 commits into
Conversation
…Implemented Excavator, Bulldozer, Truck classes with method overrides.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Your implementation has two critical violations of the task requirements that must be fixed:
-
Missing
publicmodifier on abstract methods: InMachine.java, the abstract methods must be declared aspublic abstract void doWork()andpublic abstract void stopWork(). Currently they use package-private access (no modifier). This must be fixed inMachine.javaas well as inExcavator.javaandBulldozer.java. -
Array and loop required in MainApp: The task explicitly requires creating a
Machinearray and calling methods "in a loop". Your current implementation inMainApp.javauses individual variables and individual method calls instead of:
Machine[] machines = {new Truck(), new Bulldozer(), new Excavator()};
for (Machine machine : machines) {
machine.doWork();
machine.stopWork();
}- Excavator class visibility: The
Excavatorclass should be declared aspublic.
The minor style issue with empty lines in Truck.java is not a blocker but can be cleaned up. Once the critical issues are addressed, your OOP structure with inheritance and method overriding is correct.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Important
Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.
Tip
If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.
Caution
Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.
Footnotes
| package core.basesyntax; | ||
|
|
||
| public class Bulldozer extends Machine { | ||
| @Override |
There was a problem hiding this comment.
The abstract methods must be declared as 'public abstract void doWork()' and 'public abstract void stopWork()' according to the task requirements. Currently they use package-private access.
| public class Bulldozer extends Machine { | ||
| @Override | ||
| void doWork() { | ||
| System.out.println("Bulldozer started working"); |
There was a problem hiding this comment.
The abstract method must be declared as 'public abstract void stopWork()' according to the task requirements. Currently it uses package-private access.
| @@ -0,0 +1,13 @@ | |||
| package core.basesyntax; | |||
|
|
|||
| public class Excavator extends Machine { | |||
There was a problem hiding this comment.
The abstract class should be public and its methods must be public as specified in the task: public abstract void doWork() and public abstract void stopWork(). Currently, the class has default (package-private) access.
| package core.basesyntax; | ||
|
|
||
| public class Excavator extends Machine { | ||
| @Override |
There was a problem hiding this comment.
The doWork() method should be public abstract void doWork() as required by the task description. Without public, this won't compile because subclasses cannot reduce visibility when overriding.
| public class Excavator extends Machine { | ||
| @Override | ||
| void doWork() { | ||
| System.out.println("Excavator started working"); |
There was a problem hiding this comment.
The stopWork() method should be public abstract void stopWork() as required by the task description. Without public, this won't compile because subclasses cannot reduce visibility when overriding.
|
|
||
| public class Excavator extends Machine { | ||
| @Override | ||
| void doWork() { |
There was a problem hiding this comment.
The doWork() method must be public to override the parent's abstract method. Currently package-private, which is less visible than required.
| } | ||
|
|
||
| @Override | ||
| void stopWork() { |
There was a problem hiding this comment.
The stopWork() method must be public to override the parent's abstract method. Currently package-private, which is less visible than required.
|
|
||
| public class Excavator extends Machine { | ||
| @Override | ||
| void doWork() { |
There was a problem hiding this comment.
The doWork() method must be public to override the parent's abstract method. Currently package-private, which is less visible than required.
| } | ||
|
|
||
| @Override | ||
| void stopWork() { |
There was a problem hiding this comment.
The stopWork() method must be public to override the parent's abstract method. Currently package-private, which is less visible than required.
|
|
||
| public class Excavator extends Machine { | ||
| @Override | ||
| void doWork() { |
There was a problem hiding this comment.
The doWork() method must be public to override the parent's abstract method. Currently package-private, which is less visible than required.
| } | ||
|
|
||
| @Override | ||
| void stopWork() { |
There was a problem hiding this comment.
The stopWork() method must be public to override the parent's abstract method. Currently package-private, which is less visible than required.
|
|
||
| public class Excavator extends Machine { | ||
| @Override | ||
| void doWork() { |
There was a problem hiding this comment.
The task requires creating a Machine array and calling methods in a loop. Currently using individual variables without an array or loop.
| System.out.println("Excavator started working"); | ||
| } | ||
|
|
||
| @Override |
There was a problem hiding this comment.
The task requires calling methods in a loop for all machines, not explicit individual method calls.
| package core.basesyntax; | ||
|
|
||
| public class MainApp { | ||
| public static void main(String[] args) { |
There was a problem hiding this comment.
The abstract methods must be declared as public abstract void doWork() and public abstract void stopWork() according to the task requirements. Currently, they have default (package-private) access.
|
|
||
| public class MainApp { | ||
| public static void main(String[] args) { | ||
| Machine truck = new Truck(); |
There was a problem hiding this comment.
The task requires creating a Machine array with Truck, Bulldozer, and Excavator. Consider using: Machine[] machines = {new Truck(), new Bulldozer(), new Excavator()};
|
|
||
| excavator.doWork(); | ||
| truck.doWork(); | ||
| bulldozer.doWork(); | ||
|
|
||
| excavator.stopWork(); | ||
| truck.stopWork(); | ||
| bulldozer.stopWork(); |
There was a problem hiding this comment.
The task requires calling doWork() and stopWork() methods in a loop for all machines. Consider iterating through the array instead of calling methods individually on each variable.
| package core.basesyntax; | ||
|
|
||
| abstract class Machine { | ||
| abstract void doWork(); |
There was a problem hiding this comment.
Task requirement specifies public abstract void doWork() and public abstract void stopWork(), but the abstract methods are declared without the public modifier. They will have default (package-private) access instead.
| abstract class Machine { | ||
| abstract void doWork(); | ||
|
|
||
| abstract void stopWork(); |
There was a problem hiding this comment.
Task requirement specifies public abstract void doWork() and public abstract void stopWork(), but the abstract methods are declared without the public modifier. They will have default (package-private) access instead.
| package core.basesyntax; | ||
|
|
||
| abstract class Machine { | ||
| abstract void doWork(); |
There was a problem hiding this comment.
Task requirement specifies public abstract void doWork() and public abstract void stopWork(), but the abstract methods are declared without the public modifier. They will have default (package-private) access instead.
| abstract class Machine { | ||
| abstract void doWork(); | ||
|
|
||
| abstract void stopWork(); |
There was a problem hiding this comment.
Task requirement specifies public abstract void doWork() and public abstract void stopWork(), but the abstract methods are declared without the public modifier. They will have default (package-private) access instead.
| package core.basesyntax; | ||
|
|
||
| abstract class Machine { | ||
| abstract void doWork(); |
There was a problem hiding this comment.
Task requirement specifies public abstract void doWork() and public abstract void stopWork(), but the abstract methods are declared without the public modifier. They will have default (package-private) access instead.
| abstract class Machine { | ||
| abstract void doWork(); | ||
|
|
||
| abstract void stopWork(); |
There was a problem hiding this comment.
Task requirement specifies public abstract void doWork() and public abstract void stopWork(), but the abstract methods are declared without the public modifier. They will have default (package-private) access instead.
| @Override | ||
| void doWork() { | ||
| System.out.println("Truck started working"); | ||
| } |
There was a problem hiding this comment.
According to the checklist, redundant empty lines should not be added after method declarations. Consider removing the empty line between doWork() and stopWork() methods for cleaner code.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
All requirements have been successfully implemented: the abstract class Machine with public abstract doWork() and stopWork() methods, three subclasses (Truck, Bulldozer, Excavator) properly extending Machine and overriding both methods with informative messages, and MainApp correctly using a Machine array with polymorphism to call methods in a loop. The OOP structure with inheritance and proper access modifiers is correctly applied throughout.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
…Implemented Excavator, Bulldozer, Truck classes with method overrides.