Skip to content

Homework#2566

Open
StanislavKotsurskyi wants to merge 3 commits intomate-academy:masterfrom
StanislavKotsurskyi:homework
Open

Homework#2566
StanislavKotsurskyi wants to merge 3 commits intomate-academy:masterfrom
StanislavKotsurskyi:homework

Conversation

@StanislavKotsurskyi
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. MainApp.java Logic: All the logic for creating the Machine array, populating it with Truck, Bulldozer, and Excavator instances, and looping through them to call doWork() and stopWork() must be placed directly inside the main method. Currently, this logic is in a separate loop() method that is never called, so the program doesn't perform its main function.

  2. Informative Messages: In your Truck, Bulldozer, and Excavator classes, you are creating a new instance inside the System.out.println() call (e.g., new Truck()). This results in unhelpful output like core.basesyntax.Truck@1b6d3586 has started working!. Instead, please use a simple string like "Truck has started working!" or get the class name dynamically with this.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

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment on lines +4 to +8
public static void main(String[] args) {
Machine volvo = new Truck();
Machine cat = new Excavator();
Machine shantui = new Bulldozer();
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main method should contain all the logic for this task. According to the requirements, you need to:

  1. Create a Machine array.
  2. Populate it with new instances of Truck, Bulldozer, and Excavator.
  3. Loop through this array and call doWork() and stopWork() on each machine.

Comment on lines +10 to +16
public static Machine loop(Machine[] vehicles) {
for (Machine machine : vehicles) {
machine.doWork();
machine.stopWork();
}
return null;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!");
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!");
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!");
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!");
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!");
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!");
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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! ✨

Footnotes

  1. Rate AI review example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants