Skip to content

Commit

Permalink
Created class Machine containing methods public abstract void doWork(…
Browse files Browse the repository at this point in the history
…) and public abstract void stopWork().

Add classes Truck, Bulldozer, Excavator that will inherit from Machine and override doWork() and stopWork() methods.
In Main class was created Machine array with Truck, Buldozer and Excavator and call methods doWork() and stopWork() in a loop.
  • Loading branch information
PeresadaKostya committed Jul 25, 2023
1 parent 2970b99 commit e6ddc94
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/java/core/basesyntax/Buldozer.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package core.basesyntax;

public class Buldozer extends Machine{
@Override
public void doWork() {
System.out.println("Buldozer started work");
}

@Override
public void stopwork() {
System.out.println("Buldozer stopped work");
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/core/basesyntax/Excavator.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package core.basesyntax;

public class Excavator extends Machine {
@Override
public void doWork() {
System.out.println("Excavator started work");
}

@Override
public void stopwork() {
System.out.println("Excavastor stopped work");
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/core/basesyntax/Machine.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package core.basesyntax;

public abstract class Machine {
public abstract void doWork();

public abstract void stopwork();

}
2 changes: 2 additions & 0 deletions src/main/java/core/basesyntax/MainApp.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package core.basesyntax;

public class MainApp {
Truck truck = new Truck();
Buldozer buldozer = new Buldozer();
Excavator excavator = new Excavator();

public void work() {
Machine [] machine = new Machine[] {truck, buldozer, excavator};
for (int i = 0; i < machine.length; i++) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/core/basesyntax/Truck.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package core.basesyntax;

public class Truck extends Machine{
@Override
public void doWork() {
System.out.println("Truck started work");
}

@Override
public void stopwork() {
System.out.println("Truck stopped work");
Expand Down

0 comments on commit e6ddc94

Please sign in to comment.