Skip to content

Commit

Permalink
implement abstact class Machine
Browse files Browse the repository at this point in the history
implements Bulldozer,Excavator,Truck;and overriding method doWork,stopWork
added psvm to MainApp
  • Loading branch information
mkarmadev committed Jul 18, 2023
1 parent ea616af commit 581e455
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/main/java/core/basesyntax/Bulldozer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package core.basesyntax;

public class Bulldozer extends Machine {

@Override
public void doWork() {
System.out.println("Bulldozer started its work.");
}

@Override
public void stopWork() {
System.out.println("Bulldozer stopped its work.");
}
}
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() {
System.out.println("Excavator started its work.");
}

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

public abstract class Machine {

public abstract void doWork();

public abstract void stopWork();

}
13 changes: 13 additions & 0 deletions src/main/java/core/basesyntax/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,17 @@

public class MainApp {

public static void main(String[] args) {

Machine truck = new Truck();
Machine bulldozer = new Bulldozer();
Machine excavator = new Excavator();

Machine[] machines = new Machine[] {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() {
System.out.println("Truck started its work.");
}

@Override
public void stopWork() {
System.out.println("Truck stopped its work.");
}
}

0 comments on commit 581e455

Please sign in to comment.