added lab5 ex1
This commit is contained in:
parent
312a5276d7
commit
061a475a6b
13
src/lab5_adapter/ex1/Engineer.java
Normal file
13
src/lab5_adapter/ex1/Engineer.java
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
package lab5_adapter.ex1;
|
||||||
|
|
||||||
|
public class Engineer {
|
||||||
|
private String name;
|
||||||
|
public Engineer(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Engineer " + name;
|
||||||
|
}
|
||||||
|
}
|
10
src/lab5_adapter/ex1/Machine.java
Normal file
10
src/lab5_adapter/ex1/Machine.java
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package lab5_adapter.ex1;
|
||||||
|
|
||||||
|
public interface Machine {
|
||||||
|
int getNumberOfCapsules();
|
||||||
|
boolean isCompletelyUp();
|
||||||
|
void stop();
|
||||||
|
|
||||||
|
void setNumberOfCapsules(int capsules);
|
||||||
|
void setCompletelyUp(boolean completelyUp);
|
||||||
|
}
|
44
src/lab5_adapter/ex1/MachineAdapter.java
Normal file
44
src/lab5_adapter/ex1/MachineAdapter.java
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
package lab5_adapter.ex1;
|
||||||
|
|
||||||
|
public class MachineAdapter implements NewMachineInterface {
|
||||||
|
private OldMachine machine;
|
||||||
|
|
||||||
|
public MachineAdapter(OldMachine machine) {
|
||||||
|
this.machine = machine;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getNumberOfCapsules() {
|
||||||
|
return machine.getNumberOfCapsules();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCompletelyUp() {
|
||||||
|
return machine.isCompletelyUp();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void stop() {
|
||||||
|
machine.stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setNumberOfCapsules(int capsules) {
|
||||||
|
machine.setNumberOfCapsules(capsules);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCompletelyUp(boolean completelyUp) {
|
||||||
|
machine.setCompletelyUp(completelyUp);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Engineer getEngineer() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return machine.toString() + ", supervised by engineer " + getEngineer();
|
||||||
|
}
|
||||||
|
}
|
27
src/lab5_adapter/ex1/Main.java
Normal file
27
src/lab5_adapter/ex1/Main.java
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
package lab5_adapter.ex1;
|
||||||
|
|
||||||
|
public class Main {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Engineer engineer1 = new Engineer("Jean");
|
||||||
|
Engineer engineer2 = new Engineer("Maria");
|
||||||
|
Machine machine1 = new NewMachine("1159190947", engineer1);
|
||||||
|
Machine machine2 = new NewMachine("1247233941", engineer1);
|
||||||
|
Machine machine3 = new NewMachine("258952499", engineer2);
|
||||||
|
OldMachine oldMachine = new OldMachine("603742814");
|
||||||
|
Machine machine4 = new MachineAdapter(oldMachine);
|
||||||
|
|
||||||
|
machine1.setNumberOfCapsules(30);
|
||||||
|
machine2.setNumberOfCapsules(20);
|
||||||
|
machine3.setNumberOfCapsules(40);
|
||||||
|
oldMachine.setNumberOfCapsules(80);
|
||||||
|
//Machine 1159190947 is currently processing 30 capsules, supervised by engineer Engineer Jean
|
||||||
|
//Machine 1247233941 is currently processing 20 capsules, supervised by engineer Engineer Jean
|
||||||
|
//Machine 258952499 is currently processing 40 capsules, supervised by engineer Engineer Maria
|
||||||
|
//Machine 603742814 is currently processing 80 capsules, supervised by engineer null
|
||||||
|
|
||||||
|
System.out.println(machine1);
|
||||||
|
System.out.println(machine2);
|
||||||
|
System.out.println(machine3);
|
||||||
|
System.out.println(machine4);
|
||||||
|
}
|
||||||
|
}
|
19
src/lab5_adapter/ex1/NewMachine.java
Normal file
19
src/lab5_adapter/ex1/NewMachine.java
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
package lab5_adapter.ex1;
|
||||||
|
|
||||||
|
public class NewMachine extends OldMachine implements NewMachineInterface {
|
||||||
|
private Engineer engineer;
|
||||||
|
|
||||||
|
public NewMachine(String name, Engineer engineer) {
|
||||||
|
super(name);
|
||||||
|
this.engineer = engineer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Engineer getEngineer() {
|
||||||
|
return engineer;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return super.toString() + ", supervised by engineer " + getEngineer();
|
||||||
|
}
|
||||||
|
}
|
5
src/lab5_adapter/ex1/NewMachineInterface.java
Normal file
5
src/lab5_adapter/ex1/NewMachineInterface.java
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package lab5_adapter.ex1;
|
||||||
|
|
||||||
|
public interface NewMachineInterface extends Machine {
|
||||||
|
Engineer getEngineer();
|
||||||
|
}
|
39
src/lab5_adapter/ex1/OldMachine.java
Normal file
39
src/lab5_adapter/ex1/OldMachine.java
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
package lab5_adapter.ex1;
|
||||||
|
|
||||||
|
public class OldMachine implements Machine {
|
||||||
|
private String name;
|
||||||
|
private int capsules = 0;
|
||||||
|
private boolean completelyUp = false;
|
||||||
|
|
||||||
|
public OldMachine(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNumberOfCapsules(int capsules) {
|
||||||
|
this.capsules = capsules;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCompletelyUp(boolean completelyUp) {
|
||||||
|
this.completelyUp = completelyUp;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getNumberOfCapsules() {
|
||||||
|
return capsules;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCompletelyUp() {
|
||||||
|
return completelyUp;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void stop() {
|
||||||
|
System.out.println("Stopping machine " + name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Machine " + name + " is currently processing " + getNumberOfCapsules() + " capsules";
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user