-
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 11 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 machineType) { | ||
super(machineType); | ||
} | ||
|
||
@Override | ||
public void doWork() { | ||
System.out.println("Bulldozer" + " " + machineType + " " + "started its work."); | ||
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 message in 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. 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. Simply print "Bulldozer started its work." |
||
} | ||
|
||
@Override | ||
public void stopWork() { | ||
System.out.println("Bulldozer" + " " + machineType + " " + "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. Similarly, the message in 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. 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. Simply print "Bulldozer stopped working." |
||
} | ||
|
||
@Override | ||
public String toString() { | ||
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 '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. |
||
return machineType; | ||
} | ||
} |
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 machineType) { | ||
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 for the Excavator class is unnecessary as it just calls the superclass constructor. Consider removing it if there's no additional logic inside. |
||
super(machineType); | ||
} | ||
|
||
@Override | ||
public void doWork() { | ||
System.out.println("Exavator" + " " + machineType + " " + "started its work."); | ||
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. There's a typo in the message printed to the console. It should be 'Excavator' instead of 'Exavator'. Make sure the messages are informative and correctly spelled. 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. You have a typo in 'Excavator'. Please correct it. |
||
} | ||
|
||
@Override | ||
public void stopWork() { | ||
System.out.println("Exavator" + " " + machineType + " " + "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. The same typo is present in the 'stopWork' method. It should be corrected to 'Excavator'. 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. You have a typo in 'Excavator'. Please correct it. |
||
|
||
} | ||
|
||
@Override | ||
public String toString() { | ||
return machineType; | ||
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. It's not clear what the purpose of the overridden toString() method is, as it only returns 'machineType'. If it's not necessary, consider removing it to use the inherited method from Object class. |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
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 machineType; | ||
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 'machineType' variable seems unnecessary in this context as the type of machine can be determined by the instance of the class. Consider removing this and the associated constructor and toString method if not needed for other parts of your program. |
||
|
||
public Machine(String machineType) { | ||
this.machineType = machineType; | ||
} | ||
|
||
public abstract void doWork(); | ||
|
||
public abstract void stopWork(); | ||
|
||
@Override | ||
public String toString() { | ||
return machineType; | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,24 @@ | ||
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); | ||
System.out.println(); | ||
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. There's a redundant empty line after the call to |
||
} | ||
|
||
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 machineType) { | ||
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 Machine class was not described as having a constructor that takes a machineType parameter. It's better to remove the constructor from the Truck class. |
||
super(machineType); | ||
} | ||
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" + " " + machineType + " " + "started its work."); | ||
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 message should be more informative and in proper English. Instead of concatenating strings with spaces, you can use a formatted string. For example: |
||
} | ||
|
||
@Override | ||
public void stopWork() { | ||
System.out.println("Truck" + " " + machineType + " " + "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. The stop message should also be informative and properly formatted. Consider changing it to: |
||
|
||
} | ||
|
||
@Override | ||
public String toString() { | ||
return machineType; | ||
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. The toString() method is generally used to provide a string representation of the object. In this case, it would be more appropriate to include additional information, such as the class name. |
||
} | ||
} |
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 constructor is taking a parameter 'machineType' that seems unnecessary. The type of machine is already known (Bulldozer) and does not need to be passed as a parameter.