Skip to content

Created abstract class Machine with doWork() and stopWork() methods. …#2585

Open
daryna-mitina wants to merge 2 commits into
mate-academy:masterfrom
daryna-mitina:hw-1-solution
Open

Created abstract class Machine with doWork() and stopWork() methods. …#2585
daryna-mitina wants to merge 2 commits into
mate-academy:masterfrom
daryna-mitina:hw-1-solution

Conversation

@daryna-mitina

Copy link
Copy Markdown

…Implemented Excavator, Bulldozer, Truck classes with method overrides.

…Implemented Excavator, Bulldozer, Truck classes with method overrides.

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review Summary

Your implementation has two critical violations of the task requirements that must be fixed:

  1. Missing public modifier on abstract methods: In Machine.java, the abstract methods must be declared as public abstract void doWork() and public abstract void stopWork(). Currently they use package-private access (no modifier). This must be fixed in Machine.java as well as in Excavator.java and Bulldozer.java.

  2. Array and loop required in MainApp: The task explicitly requires creating a Machine array and calling methods "in a loop". Your current implementation in MainApp.java uses individual variables and individual method calls instead of:

Machine[] machines = {new Truck(), new Bulldozer(), new Excavator()};
for (Machine machine : machines) {
    machine.doWork();
    machine.stopWork();
}
  1. Excavator class visibility: The Excavator class should be declared as public.

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

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

package core.basesyntax;

public class Bulldozer extends Machine {
@Override

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 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");

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 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 {

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

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 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");

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 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() {

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 doWork() method must be public to override the parent's abstract method. Currently package-private, which is less visible than required.

}

@Override
void stopWork() {

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 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() {

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 doWork() method must be public to override the parent's abstract method. Currently package-private, which is less visible than required.

}

@Override
void stopWork() {

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 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() {

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 doWork() method must be public to override the parent's abstract method. Currently package-private, which is less visible than required.

}

@Override
void stopWork() {

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 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() {

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

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 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) {

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 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();

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 task requires creating a Machine array with Truck, Bulldozer, and Excavator. Consider using: Machine[] machines = {new Truck(), new Bulldozer(), new Excavator()};

Comment on lines +8 to +15

excavator.doWork();
truck.doWork();
bulldozer.doWork();

excavator.stopWork();
truck.stopWork();
bulldozer.stopWork();

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 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();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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");
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 mateacademy-ai-mentor left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

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