-
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
first attempt #2207
base: master
Are you sure you want to change the base?
first attempt #2207
Changes from 6 commits
cfde61a
ea5b4fb
ad76482
50c6ed0
ac7192b
61aef2c
23882d6
58545bd
1049212
a8734cd
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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
# jv-oop | ||
|
||
- Create class Machine containing methods `public abstract void doWork()` and `public abstract void stopWork()`. | ||
- Create classes `Truck`, `Bulldozer`, and `Excavator` that will inherit from `Machine`. | ||
- Create class core.basesyntax.Machine containing methods `public abstract void doWork()` and `public abstract void stopWork()`. | ||
- Create classes `core.basesyntax.Truck`, `core.basesyntax.Bulldozer`, and `core.basesyntax.Excavator` that will inherit from `core.basesyntax.Machine`. | ||
- In those classes override `doWork()`, so it will print a message that a certain machine started its work. | ||
- Override `stopWork()` as well. It should print messages that certain machines stopped working. | ||
- In the `MainApp` class create a `Machine` array with `Truck`, `Bulldozer`, and `Excavator` and call methods `doWork()` and `stopWork()` in a loop. | ||
- In the `MainApp` class create a `core.basesyntax.Machine` array with `core.basesyntax.Truck`, `core.basesyntax.Bulldozer`, and `core.basesyntax.Excavator` and call methods `doWork()` and `stopWork()` in a loop. | ||
|
||
#### [Try to avoid these common mistakes, while solving task](./checklist.md) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ public class Main { | |
|
||
#### Write informative messages in methods. | ||
- Use English only and make messages informative | ||
- The message should indicate what type of `Machine` is working right now `Truck`, `Bulldozer` or `Excavator`. | ||
- The message should indicate what type of `core.basesyntax.Machine` is working right now `core.basesyntax.Truck`, `core.basesyntax.Bulldozer` or `core.basesyntax.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. revert changes 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. not fixed |
||
|
||
#### Use abstract references instead of specific ones where possible: | ||
* Bad example: | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,15 @@ | ||||||
package core.basesyntax; | ||||||
|
||||||
import core.basesyntax.Machine; | ||||||
|
||||||
public class Bulldozer extends Machine { | ||||||
@Override | ||||||
public void doWork() { | ||||||
System.out.println("core.basesyntax.Bulldozer has started 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. same for all messages
Suggested change
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. not fixed (fix it everywhere) |
||||||
} | ||||||
|
||||||
@Override | ||||||
public void stopWork() { | ||||||
System.out.println("core.basesyntax.Bulldozer has stopped working."); | ||||||
} | ||||||
} |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -0,0 +1,16 @@ | ||||
package core.basesyntax; | ||||
|
||||
import core.basesyntax.Machine; | ||||
|
||||
public class Excavator extends Machine { | ||||
@Override | ||||
public void doWork() { | ||||
System.out.println("core.basesyntax.Excavator has started working."); | ||||
} | ||||
|
||||
@Override | ||||
public void stopWork() { | ||||
System.out.println("core.basesyntax.Excavator has 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.
Suggested change
Leave only one empty line |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package core.basesyntax; | ||
|
||
public abstract class Machine { | ||
public abstract void doWork(); | ||
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. check tabulation 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. corrected 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. not fixed |
||
public abstract void stopWork(); | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,5 +1,17 @@ | ||||||||||||
package core.basesyntax; | ||||||||||||
|
||||||||||||
public class MainAppTest { | ||||||||||||
public static void main(String[] args) { | ||||||||||||
final int MACHINE_COUNT = 3; | ||||||||||||
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.
Suggested change
Make this variable constant |
||||||||||||
Machine[] machines = new Machine[MACHINE_COUNT]; | ||||||||||||
machines[0] = new Truck(); | ||||||||||||
machines[1] = new Bulldozer(); | ||||||||||||
machines[2] = new 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. it could be done in 1 line using initialization values 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. done ! thanks |
||||||||||||
|
||||||||||||
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 redundant empty line 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. I tried . it does not let me remove them in intelllij idea |
||||||||||||
|
||||||||||||
for (Machine machine : machines) { | ||||||||||||
machine.doWork(); | ||||||||||||
machine.stopWork(); | ||||||||||||
} | ||||||||||||
} | ||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package core.basesyntax; | ||
|
||
public class Truck extends Machine { | ||
@Override | ||
public void doWork() { | ||
System.out.println("core.basesyntax.Truck has started working."); | ||
} | ||
|
||
@Override | ||
public void stopWork() { | ||
System.out.println("core.basesyntax.Truck has stopped working."); | ||
} | ||
} |
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.
revert changes
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.
not fixed