Skip to content
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

Created class Machine and method toWork() and stopWork(), #1587

Closed
wants to merge 7 commits into from
11 changes: 11 additions & 0 deletions src/main/java/Bulldozer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
public class Bulldozer extends Machine {
@Override
public void doWork() {
System.out.println("Bulldozer started work!");
}

@Override
public void stopWork() {
System.out.println("Bulldozer stopped work!");
}
}
11 changes: 11 additions & 0 deletions src/main/java/Excavator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
public class Excavator extends Machine {
@Override
public void doWork() {
System.out.println("Excavator started work!");
}

@Override
public void stopWork() {
System.out.println("Excavator stopped work!");
}
}
5 changes: 5 additions & 0 deletions src/main/java/Machine.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public abstract class Machine {
public abstract void doWork();

public abstract void stopWork();
}
16 changes: 16 additions & 0 deletions src/main/java/MainApp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
public class MainApp {
public static void main(String[] args) {
Excavator excavator = new Excavator();
Bulldozer bulldozer = new Bulldozer();
Truck truck = new Truck();

Machine[] machine = new Machine[] {excavator, bulldozer, truck};
Comment on lines +3 to +7
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variables for single usage are rarely required

Suggested change
Excavator excavator = new Excavator();
Bulldozer bulldozer = new Bulldozer();
Truck truck = new Truck();
Machine[] machine = new Machine[] {excavator, bulldozer, truck};
Machine[] machine = new Machine[] {new Excavator(), new Bulldozer(), new Truck()};

for (Machine machinery : machine) {
machinery.doWork();
machinery.stopWork();
}

}
}


Comment on lines +15 to +16
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 unnecessary empty lines

13 changes: 13 additions & 0 deletions src/main/java/Truck.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
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");
}
}
Loading