-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Develop #2155
base: master
Are you sure you want to change the base?
Develop #2155
Changes from 13 commits
41ff595
f07c826
7d37697
6de7435
3228d53
7763d6b
80670e8
04cb25a
22b9998
9c0365f
fcc3152
e6b6360
f9e1a4f
6c223ab
e19fc19
5a3b993
93626c1
a7f2105
c945605
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package core.basesyntax; | ||
|
||
public class Bulldozer extends Machine { | ||
|
||
public Bulldozer(String machine) { | ||
super(machine); | ||
} | ||
|
||
@Override | ||
public void doWork() { | ||
System.out.println("Bulldozer" + " " + machine + " " + "is moving earth."); | ||
} | ||
|
||
@Override | ||
public void stopWork() { | ||
System.out.println("Bulldozer" + " " + machine + " " + "has finished moving earth."); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Bulldozer"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package core.basesyntax; | ||
|
||
public class Excavator extends Machine { | ||
|
||
public Excavator(String machine) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All constructors & |
||
super(machine); | ||
} | ||
MrGizmen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
@Override | ||
public void doWork() { | ||
System.out.println("Excavator" + " " + machine + " " + "started its work."); | ||
} | ||
|
||
@Override | ||
public void stopWork() { | ||
System.out.println("Excavator" + " " + machine + " " + "stopped working."); | ||
|
||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please read previous comments about these methods. |
||
|
||
@Override | ||
public String toString() { | ||
return "Excavator"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package core.basesyntax; | ||
|
||
public abstract class Machine { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is how this class should look like: public abstract class Machine {
public abstract void doWork();
public abstract void stopWork();
} |
||
protected String machine; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The field 'machine' is somewhat ambiguous. Consider renaming it to something more descriptive that reflects its purpose in the context of a 'Machine', such as 'machineType' or 'machineName'. |
||
|
||
public Machine(String machine) { | ||
this.machine = machine; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The constructor parameter 'machine' should be renamed for clarity. If this is intended to represent the type or name of the machine, consider renaming the parameter to 'machineType' or 'machineName' to match the suggested field name change. |
||
|
||
public abstract void doWork(); | ||
|
||
public abstract void stopWork(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,23 @@ | ||
package core.basesyntax; | ||
|
||
import java.util.Arrays; | ||
|
||
public class MainApp { | ||
public static void main(String[] args) { | ||
|
||
Machine truck = new Truck("Mikki"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The constructors for Truck, Bulldozer, and Excavator classes are not defined in the task. If these classes have constructors that take parameters, mention it in the task definition. If not, use default constructors instead. |
||
Machine bulldozer = new Bulldozer("Eduardo"); | ||
Machine excavator = new Excavator("Maks"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As Mateusz mentioned in the previous comment, you should remove all constructors from Machine child classes. If Java class doesn't have any explicitly defined constructor it will use the default one, so in this case you will be able to create Truck/Bulldozer/Excavator instances like this: Machine truck = new Truck(); Notice that in this case you don't have to provide "name" of the machine, because you are able to use default constructor, i.e. new Truck(); That's why you should remove "name" fields in all child classes and delete a constructors you created. |
||
|
||
Machine[] machines = {truck, bulldozer, excavator}; | ||
printTotal(machines); | ||
} | ||
|
||
private static void printTotal(Machine[] machines) { | ||
for (Machine machine : machines) { | ||
machine.doWork(); | ||
machine.stopWork(); | ||
} | ||
System.out.println(Arrays.toString(machines)); | ||
MrGizmen marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line is unnecessary. The printTotal method is supposed to invoke doWork() and stopWork() on each machine, there is no need to print an array of Machines. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package core.basesyntax; | ||
|
||
public class Truck extends Machine { | ||
|
||
public Truck(String machine) { | ||
super(machine); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove constructor and "name" field to be able to create instances without providing a name |
||
|
||
@Override | ||
public void doWork() { | ||
System.out.println("Truck" + " " + machine + " " + "started its work."); | ||
} | ||
|
||
@Override | ||
public void stopWork() { | ||
System.out.println("Truck" + " " + machine + " " + "stopped working. "); | ||
|
||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Truck"; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 'machineType' field is not defined in this class. If 'machineType' is a field in the parent class, it should be accessed using 'super.machineType'. Or better yet, since this class already represents a specific machine type (Bulldozer), 'machineType' is not needed in the toString() method. You can return "Bulldozer" instead.