Skip to content

Commit

Permalink
implemented method doWork and stopWork in Truck, Excavator, Bulldozer…
Browse files Browse the repository at this point in the history
… classes. Added psvm method in MainApp class
  • Loading branch information
ystankevych committed Jul 16, 2023
1 parent ea616af commit 3c3eb54
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/main/java/core/basesyntax/Bulldozer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package core.basesyntax;

public class Bulldozer extends Machine {
@Override
public void doWork() {
printStartMessage(getClass().getSimpleName());
}

@Override
public void stopWork() {
printStopMessage(getClass().getSimpleName());
}
}
13 changes: 13 additions & 0 deletions src/main/java/core/basesyntax/Excavator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package core.basesyntax;

public class Excavator extends Machine {
@Override
public void doWork() {
printStartMessage(getClass().getSimpleName());
}

@Override
public void stopWork() {
printStopMessage(getClass().getSimpleName());
}
}
16 changes: 16 additions & 0 deletions src/main/java/core/basesyntax/Machine.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package core.basesyntax;

public abstract class Machine {

public abstract void doWork();

public abstract void stopWork();

public void printStartMessage(String message) {
System.out.println(message + " started working");
}

public void printStopMessage(String message) {
System.out.println(message + " stopped working");
}
}
11 changes: 10 additions & 1 deletion src/main/java/core/basesyntax/MainApp.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
package core.basesyntax;

public class MainApp {

public static void main(String[] args) {
Machine truck = new Truck();
Machine bulldozer = new Bulldozer();
Machine excavator = new Excavator();
Machine[] machines = {truck, bulldozer, excavator};
for (Machine machine : machines) {
machine.doWork();
machine.stopWork();
}
}
}
13 changes: 13 additions & 0 deletions src/main/java/core/basesyntax/Truck.java
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() {
printStartMessage(getClass().getSimpleName());
}

@Override
public void stopWork() {
printStopMessage(getClass().getSimpleName());
}
}

0 comments on commit 3c3eb54

Please sign in to comment.