From 061a475a6b2d113898159ff4749278fd1601bd12 Mon Sep 17 00:00:00 2001 From: LordBaryhobal Date: Mon, 14 Oct 2024 09:15:25 +0200 Subject: [PATCH] added lab5 ex1 --- src/lab5_adapter/ex1/Engineer.java | 13 ++++++ src/lab5_adapter/ex1/Machine.java | 10 +++++ src/lab5_adapter/ex1/MachineAdapter.java | 44 +++++++++++++++++++ src/lab5_adapter/ex1/Main.java | 27 ++++++++++++ src/lab5_adapter/ex1/NewMachine.java | 19 ++++++++ src/lab5_adapter/ex1/NewMachineInterface.java | 5 +++ src/lab5_adapter/ex1/OldMachine.java | 39 ++++++++++++++++ 7 files changed, 157 insertions(+) create mode 100644 src/lab5_adapter/ex1/Engineer.java create mode 100644 src/lab5_adapter/ex1/Machine.java create mode 100644 src/lab5_adapter/ex1/MachineAdapter.java create mode 100644 src/lab5_adapter/ex1/Main.java create mode 100644 src/lab5_adapter/ex1/NewMachine.java create mode 100644 src/lab5_adapter/ex1/NewMachineInterface.java create mode 100644 src/lab5_adapter/ex1/OldMachine.java diff --git a/src/lab5_adapter/ex1/Engineer.java b/src/lab5_adapter/ex1/Engineer.java new file mode 100644 index 0000000..564662a --- /dev/null +++ b/src/lab5_adapter/ex1/Engineer.java @@ -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; + } +} diff --git a/src/lab5_adapter/ex1/Machine.java b/src/lab5_adapter/ex1/Machine.java new file mode 100644 index 0000000..1273d79 --- /dev/null +++ b/src/lab5_adapter/ex1/Machine.java @@ -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); +} diff --git a/src/lab5_adapter/ex1/MachineAdapter.java b/src/lab5_adapter/ex1/MachineAdapter.java new file mode 100644 index 0000000..745f3db --- /dev/null +++ b/src/lab5_adapter/ex1/MachineAdapter.java @@ -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(); + } +} diff --git a/src/lab5_adapter/ex1/Main.java b/src/lab5_adapter/ex1/Main.java new file mode 100644 index 0000000..0efac7c --- /dev/null +++ b/src/lab5_adapter/ex1/Main.java @@ -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); + } +} diff --git a/src/lab5_adapter/ex1/NewMachine.java b/src/lab5_adapter/ex1/NewMachine.java new file mode 100644 index 0000000..2a51bb9 --- /dev/null +++ b/src/lab5_adapter/ex1/NewMachine.java @@ -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(); + } +} diff --git a/src/lab5_adapter/ex1/NewMachineInterface.java b/src/lab5_adapter/ex1/NewMachineInterface.java new file mode 100644 index 0000000..186a4f9 --- /dev/null +++ b/src/lab5_adapter/ex1/NewMachineInterface.java @@ -0,0 +1,5 @@ +package lab5_adapter.ex1; + +public interface NewMachineInterface extends Machine { + Engineer getEngineer(); +} diff --git a/src/lab5_adapter/ex1/OldMachine.java b/src/lab5_adapter/ex1/OldMachine.java new file mode 100644 index 0000000..de83025 --- /dev/null +++ b/src/lab5_adapter/ex1/OldMachine.java @@ -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"; + } +}