Conversation
…ided methods doWork and stopWork, and created loop
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
This requires changes because the core logic of the application is not being executed, and the output messages from the machines are not formatted correctly.
Here are the main issues to address:
-
MainApp.javaLogic: All the logic for creating theMachinearray, populating it withTruck,Bulldozer, andExcavatorinstances, and looping through them to calldoWork()andstopWork()must be placed directly inside themainmethod. Currently, this logic is in a separateloop()method that is never called, so the program doesn't perform its main function. -
Informative Messages: In your
Truck,Bulldozer, andExcavatorclasses, you are creating a new instance inside theSystem.out.println()call (e.g.,new Truck()). This results in unhelpful output likecore.basesyntax.Truck@1b6d3586 has started working!. Instead, please use a simple string like"Truck has started working!"or get the class name dynamically withthis.getClass().getSimpleName()to produce a clear message as required by [CHECKLIST ITEM #2].
You've done a great job setting up the abstract Machine class and the inheritance structure. With these fixes, your solution will be perfect!
✨ 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
| public static void main(String[] args) { | ||
| Machine volvo = new Truck(); | ||
| Machine cat = new Excavator(); | ||
| Machine shantui = new Bulldozer(); | ||
| } |
There was a problem hiding this comment.
The main method should contain all the logic for this task. According to the requirements, you need to:
- Create a
Machinearray. - Populate it with new instances of
Truck,Bulldozer, andExcavator. - Loop through this array and call
doWork()andstopWork()on each machine.
| public static Machine loop(Machine[] vehicles) { | ||
| for (Machine machine : vehicles) { | ||
| machine.doWork(); | ||
| machine.stopWork(); | ||
| } | ||
| return null; | ||
| } |
There was a problem hiding this comment.
This loop method is never called, so the code inside it will not run. All the logic for creating the array and iterating through it should be placed directly inside the main method.
| public class Bulldozer extends Machine { | ||
| @Override | ||
| public void doWork() { | ||
| System.out.println(new Bulldozer() + " has started working!"); |
There was a problem hiding this comment.
Creating a new Bulldozer instance here is inefficient. More importantly, it will call the default toString() method, printing something like core.basesyntax.Bulldozer@15db9742, which is not very informative. According to checklist item #2, the message should just indicate the type of machine. Using a string literal like "Bulldozer" or this.getClass().getSimpleName() would be a better approach.
|
|
||
| @Override | ||
| public void stopWork() { | ||
| System.out.println(new Bulldozer() + " has stopped working!"); |
There was a problem hiding this comment.
Similar to the doWork() method, creating a new instance here is unnecessary and leads to a non-informative message. Please use a simple string or this.getClass().getSimpleName() to indicate the machine type.
| public class Excavator extends Machine { | ||
| @Override | ||
| public void doWork() { | ||
| System.out.println(new Excavator() + " has started working!"); |
There was a problem hiding this comment.
Creating a new Excavator instance here is unnecessary. The output will include the object's hashcode (e.g., core.basesyntax.Excavator@15db9742), which is not the informative message requested. A better approach is to use the class name directly as a string, like "Excavator has started working!".
|
|
||
| @Override | ||
| public void stopWork() { | ||
| System.out.println(new Excavator() + " has stopped working!"); |
There was a problem hiding this comment.
Similar to the doWork() method, creating a new Excavator instance here is not ideal. Please use a string literal to identify the machine type in the message to ensure the output is clear and informative.
| public class Truck extends Machine { | ||
| @Override | ||
| public void doWork() { | ||
| System.out.println(new Truck() + " has started working!"); |
There was a problem hiding this comment.
Creating a new Truck instance here is unnecessary. The output will include the object's hashcode (e.g., core.basesyntax.Truck@15db9742), which is not an informative message. This violates checklist item #2. A better approach is to use the class name directly in a string, like "Truck has started working!".
|
|
||
| @Override | ||
| public void stopWork() { | ||
| System.out.println(new Truck() + " has stopped working!"); |
There was a problem hiding this comment.
Similar to doWork(), creating a new Truck instance here is not the correct way to generate an informative message. Please use a string literal to clearly state that the truck has stopped working.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Excellent work on this revision! I am approving your solution as you have successfully addressed all the feedback from the previous review. The application logic is now correctly placed within the main method, and the output messages are clear and informative. Your code is clean, correct, and fully meets all task requirements. Well done!
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
No description provided.