From 3cb356816d7634444e6831959c7b72edc214828f Mon Sep 17 00:00:00 2001 From: kileruncio Date: Thu, 16 Mar 2023 22:40:06 +0100 Subject: [PATCH 01/13] feat: init abstract class --- README.md | 9 ++++++++- src/App.java | 3 +++ src/companies/Company.java | 21 +++++++++++++++++++++ src/companies/Ford.java | 16 ++++++++++++++++ 4 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 src/companies/Company.java create mode 100644 src/companies/Ford.java diff --git a/README.md b/README.md index 734d25c..3dd486b 100644 --- a/README.md +++ b/README.md @@ -18,4 +18,11 @@ - [x] Kompozycja -_w każdym przypadku: liczności 1-* lub *-* oraz automatyczne tworzenie poł. zwrotnego_ \ No newline at end of file +_w każdym przypadku: liczności 1-* lub *-* oraz automatyczne tworzenie poł. zwrotnego_ + +## MP3 + - [ ] Klasa abstrakcyjna i polimorficzne wołanie metod + - [ ] Overlapping + - [ ] Wielodziedziczenie + - [ ] Wieloaspektowe + - [ ] Dynamiczne \ No newline at end of file diff --git a/src/App.java b/src/App.java index 459a7d6..ca52a81 100644 --- a/src/App.java +++ b/src/App.java @@ -83,5 +83,8 @@ public static void main(String[] args) { System.out.println("Parts: " + tools[0].getParts().toString()); + + // -----------------------MP3----------------------- + } } diff --git a/src/companies/Company.java b/src/companies/Company.java new file mode 100644 index 0000000..368ae82 --- /dev/null +++ b/src/companies/Company.java @@ -0,0 +1,21 @@ +package companies; + +public abstract class Company { + private String address; + private String name; + + public Company(String address, String name) { + this.address = address; + this.name = name; + } + + public abstract double getIncome(); + + public String getName() { + return this.name; + } + + public String getAddress() { + return this.address; + } +} diff --git a/src/companies/Ford.java b/src/companies/Ford.java new file mode 100644 index 0000000..fc36a8e --- /dev/null +++ b/src/companies/Ford.java @@ -0,0 +1,16 @@ +package companies; + +public class Ford extends Company { + private double income; + + public Ford(String address, String name) { + super(address, name); + this.income = Math.random()*1000; + } + + @Override + public double getIncome() { + return income; + } + +} From 6a6c020bca81b721c936aaa6a820f77b431c7d67 Mon Sep 17 00:00:00 2001 From: kileruncio Date: Thu, 16 Mar 2023 22:44:26 +0100 Subject: [PATCH 02/13] chore: cleaning --- src/App.java | 8 ++++++++ src/{ => tool}/Hammer.java | 1 + src/{ => tool}/Owner.java | 1 + src/{ => tool}/Part.java | 1 + src/{ => tool}/Tool.java | 1 + src/{ => tool}/ToolShop.java | 1 + src/{ => tool}/Toolbox.java | 1 + src/{ => tool}/Transaction.java | 1 + 8 files changed, 15 insertions(+) rename src/{ => tool}/Hammer.java (96%) rename src/{ => tool}/Owner.java (98%) rename src/{ => tool}/Part.java (97%) rename src/{ => tool}/Tool.java (99%) rename src/{ => tool}/ToolShop.java (96%) rename src/{ => tool}/Toolbox.java (98%) rename src/{ => tool}/Transaction.java (97%) diff --git a/src/App.java b/src/App.java index ca52a81..e1e84df 100644 --- a/src/App.java +++ b/src/App.java @@ -5,6 +5,14 @@ import java.util.ArrayList; import java.util.List; +import tool.Hammer; +import tool.Owner; +import tool.Part; +import tool.Tool; +import tool.ToolShop; +import tool.Toolbox; +import tool.Transaction; + public class App { final static String fileName = "data/data.kfc"; diff --git a/src/Hammer.java b/src/tool/Hammer.java similarity index 96% rename from src/Hammer.java rename to src/tool/Hammer.java index 08d62c6..6b84ca5 100644 --- a/src/Hammer.java +++ b/src/tool/Hammer.java @@ -1,3 +1,4 @@ +package tool; import java.util.List; public class Hammer extends Tool { diff --git a/src/Owner.java b/src/tool/Owner.java similarity index 98% rename from src/Owner.java rename to src/tool/Owner.java index bc43bb7..b73fa41 100644 --- a/src/Owner.java +++ b/src/tool/Owner.java @@ -1,3 +1,4 @@ +package tool; import java.util.ArrayList; import java.util.Map; import java.util.TreeMap; diff --git a/src/Part.java b/src/tool/Part.java similarity index 97% rename from src/Part.java rename to src/tool/Part.java index 428c074..a52a79b 100644 --- a/src/Part.java +++ b/src/tool/Part.java @@ -1,3 +1,4 @@ +package tool; public class Part { private Tool tool; private String name; diff --git a/src/Tool.java b/src/tool/Tool.java similarity index 99% rename from src/Tool.java rename to src/tool/Tool.java index a064021..bac95fb 100644 --- a/src/Tool.java +++ b/src/tool/Tool.java @@ -1,3 +1,4 @@ +package tool; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; diff --git a/src/ToolShop.java b/src/tool/ToolShop.java similarity index 96% rename from src/ToolShop.java rename to src/tool/ToolShop.java index 5e375d4..f983ebd 100644 --- a/src/ToolShop.java +++ b/src/tool/ToolShop.java @@ -1,3 +1,4 @@ +package tool; import java.util.ArrayList; public class ToolShop { diff --git a/src/Toolbox.java b/src/tool/Toolbox.java similarity index 98% rename from src/Toolbox.java rename to src/tool/Toolbox.java index e759a6f..65c53ca 100644 --- a/src/Toolbox.java +++ b/src/tool/Toolbox.java @@ -1,3 +1,4 @@ +package tool; import java.util.ArrayList; public class Toolbox { diff --git a/src/Transaction.java b/src/tool/Transaction.java similarity index 97% rename from src/Transaction.java rename to src/tool/Transaction.java index a237ba1..30c419a 100644 --- a/src/Transaction.java +++ b/src/tool/Transaction.java @@ -1,3 +1,4 @@ +package tool; import java.time.LocalDateTime; public class Transaction { From 568a3ee5b995b22f53d5128c735f8cd698a7356b Mon Sep 17 00:00:00 2001 From: kileruncio Date: Mon, 20 Mar 2023 22:43:15 +0100 Subject: [PATCH 03/13] feat: abstract class --- README.md | 2 +- src/companies/Alpabet.java | 16 ++++++++++++++++ src/companies/Company.java | 2 +- src/companies/Ford.java | 4 ++-- 4 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 src/companies/Alpabet.java diff --git a/README.md b/README.md index 3dd486b..d2ffa88 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ _w każdym przypadku: liczności 1-* lub *-* oraz automatyczne tworzenie poł. zwrotnego_ ## MP3 - - [ ] Klasa abstrakcyjna i polimorficzne wołanie metod + - [x] Klasa abstrakcyjna i polimorficzne wołanie metod - [ ] Overlapping - [ ] Wielodziedziczenie - [ ] Wieloaspektowe diff --git a/src/companies/Alpabet.java b/src/companies/Alpabet.java new file mode 100644 index 0000000..d5c5d81 --- /dev/null +++ b/src/companies/Alpabet.java @@ -0,0 +1,16 @@ +package companies; + +public class Alpabet extends Company { + private double income; + + public Alpabet(String address, String name) { + super(address, name); + this.income = Math.random()*100000; + } + + @Override + public double getProfit() { + return income * 0.3; + } + +} diff --git a/src/companies/Company.java b/src/companies/Company.java index 368ae82..5351795 100644 --- a/src/companies/Company.java +++ b/src/companies/Company.java @@ -9,7 +9,7 @@ public Company(String address, String name) { this.name = name; } - public abstract double getIncome(); + public abstract double getProfit(); public String getName() { return this.name; diff --git a/src/companies/Ford.java b/src/companies/Ford.java index fc36a8e..bac00a3 100644 --- a/src/companies/Ford.java +++ b/src/companies/Ford.java @@ -9,8 +9,8 @@ public Ford(String address, String name) { } @Override - public double getIncome() { - return income; + public double getProfit() { + return income * 0.7; } } From 33a57e26171ec1f1412b155328de7112f305a6ad Mon Sep 17 00:00:00 2001 From: kileruncio Date: Mon, 20 Mar 2023 23:23:41 +0100 Subject: [PATCH 04/13] feat: overlapping --- README.md | 2 +- src/companies/Alpabet.java | 4 +-- src/companies/Employee.java | 64 +++++++++++++++++++++++++++++++++ src/companies/EmployeeType.java | 5 +++ src/companies/Ford.java | 4 +-- 5 files changed, 74 insertions(+), 5 deletions(-) create mode 100644 src/companies/Employee.java create mode 100644 src/companies/EmployeeType.java diff --git a/README.md b/README.md index d2ffa88..6a69209 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ _w każdym przypadku: liczności 1-* lub *-* oraz automatyczne tworzenie poł. z ## MP3 - [x] Klasa abstrakcyjna i polimorficzne wołanie metod - - [ ] Overlapping + - [x] Overlapping - [ ] Wielodziedziczenie - [ ] Wieloaspektowe - [ ] Dynamiczne \ No newline at end of file diff --git a/src/companies/Alpabet.java b/src/companies/Alpabet.java index d5c5d81..9d80e80 100644 --- a/src/companies/Alpabet.java +++ b/src/companies/Alpabet.java @@ -5,12 +5,12 @@ public class Alpabet extends Company { public Alpabet(String address, String name) { super(address, name); - this.income = Math.random()*100000; + this.income = Math.random() * 100000; } @Override public double getProfit() { return income * 0.3; } - + } diff --git a/src/companies/Employee.java b/src/companies/Employee.java new file mode 100644 index 0000000..774b180 --- /dev/null +++ b/src/companies/Employee.java @@ -0,0 +1,64 @@ +package companies; + +import java.util.EnumSet; + +public class Employee { + private String name; + private boolean inWork; + private double salary; + + private EnumSet employeeType; + + public Employee(String name, boolean inWork, double salary, EnumSet employeeType) { + this.name = name; + this.inWork = inWork; + this.salary = salary; + this.employeeType = employeeType; + } + + public String getName() { + return name; + } + + public boolean isInWork() { + return inWork; + } + + public double getSalary() { + return salary; + } + + public double getRealSalary() { + double resoult = 0; + + if (this.employeeType.add(EmployeeType.Company)) { + if (resoult == 0) + resoult = this.salary * 0.7; + else + resoult += this.salary * 0.7; + } + + if (this.employeeType.add(EmployeeType.Student)) { + if (resoult == 0) + resoult = this.salary; + else + resoult += this.salary; + } + + if (this.employeeType.add(EmployeeType.Underage)) { + if (resoult == 0) + resoult = this.salary; + else + resoult += this.salary; + } + + if (this.employeeType.add(EmployeeType.Employee)) { + if (resoult == 0) + resoult = this.salary * 0.6; + else + resoult += this.salary * 0.6; + } + + return resoult; + } +} diff --git a/src/companies/EmployeeType.java b/src/companies/EmployeeType.java new file mode 100644 index 0000000..02f504c --- /dev/null +++ b/src/companies/EmployeeType.java @@ -0,0 +1,5 @@ +package companies; + +public enum EmployeeType { + Student, Underage, Employee, Company +}; diff --git a/src/companies/Ford.java b/src/companies/Ford.java index bac00a3..3d8e5d1 100644 --- a/src/companies/Ford.java +++ b/src/companies/Ford.java @@ -5,12 +5,12 @@ public class Ford extends Company { public Ford(String address, String name) { super(address, name); - this.income = Math.random()*1000; + this.income = Math.random() * 1000; } @Override public double getProfit() { return income * 0.7; } - + } From 1b205bc3879378b1b5ff39fa3c51597a274d8cc5 Mon Sep 17 00:00:00 2001 From: kileruncio Date: Mon, 20 Mar 2023 23:32:04 +0100 Subject: [PATCH 05/13] feat & fix: abstract implementation --- src/App.java | 10 +++++++++- src/companies/{Alpabet.java => Corporation.java} | 4 ++-- src/companies/{Ford.java => SmallBuisness.java} | 4 ++-- 3 files changed, 13 insertions(+), 5 deletions(-) rename src/companies/{Alpabet.java => Corporation.java} (68%) rename src/companies/{Ford.java => SmallBuisness.java} (67%) diff --git a/src/App.java b/src/App.java index e1e84df..3aa5d9c 100644 --- a/src/App.java +++ b/src/App.java @@ -5,6 +5,9 @@ import java.util.ArrayList; import java.util.List; +import companies.Corporation; +import companies.Company; +import companies.SmallBuisness; import tool.Hammer; import tool.Owner; import tool.Part; @@ -91,8 +94,13 @@ public static void main(String[] args) { System.out.println("Parts: " + tools[0].getParts().toString()); + // -----------------------MP3----------------------- - // -----------------------MP3----------------------- + ArrayList companies = new ArrayList<>(); + companies.add(new SmallBuisness("Topolowa 8, 00-999 Warcaby", "Wyroby Tomka")); + companies.add(new Corporation("USA", "Nivea")); + for(Company company : companies) + System.out.println(company.getProfit()); } } diff --git a/src/companies/Alpabet.java b/src/companies/Corporation.java similarity index 68% rename from src/companies/Alpabet.java rename to src/companies/Corporation.java index 9d80e80..8a89c6f 100644 --- a/src/companies/Alpabet.java +++ b/src/companies/Corporation.java @@ -1,9 +1,9 @@ package companies; -public class Alpabet extends Company { +public class Corporation extends Company { private double income; - public Alpabet(String address, String name) { + public Corporation(String address, String name) { super(address, name); this.income = Math.random() * 100000; } diff --git a/src/companies/Ford.java b/src/companies/SmallBuisness.java similarity index 67% rename from src/companies/Ford.java rename to src/companies/SmallBuisness.java index 3d8e5d1..00950cf 100644 --- a/src/companies/Ford.java +++ b/src/companies/SmallBuisness.java @@ -1,9 +1,9 @@ package companies; -public class Ford extends Company { +public class SmallBuisness extends Company { private double income; - public Ford(String address, String name) { + public SmallBuisness(String address, String name) { super(address, name); this.income = Math.random() * 1000; } From 504fb3a476e4f84333113a69a2594c464b94c191 Mon Sep 17 00:00:00 2001 From: kileruncio Date: Mon, 20 Mar 2023 23:50:52 +0100 Subject: [PATCH 06/13] feat & fixes: overlapping implementation --- src/App.java | 15 ++++++++++++++- src/companies/Employee.java | 5 +++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/App.java b/src/App.java index 3aa5d9c..1fdbcae 100644 --- a/src/App.java +++ b/src/App.java @@ -3,9 +3,13 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.util.ArrayList; +import java.util.Arrays; +import java.util.EnumSet; import java.util.List; import companies.Corporation; +import companies.Employee; +import companies.EmployeeType; import companies.Company; import companies.SmallBuisness; import tool.Hammer; @@ -96,11 +100,20 @@ public static void main(String[] args) { // -----------------------MP3----------------------- + // abstract & polimorfizm ArrayList companies = new ArrayList<>(); companies.add(new SmallBuisness("Topolowa 8, 00-999 Warcaby", "Wyroby Tomka")); companies.add(new Corporation("USA", "Nivea")); for(Company company : companies) - System.out.println(company.getProfit()); + System.out.println("Profit of a company: " + company.getProfit()); + + // overlapping + ArrayList employees = new ArrayList<>(); + employees.add(new Employee("MK", true, 3500.50, Arrays.asList(EmployeeType.Employee))); + employees.add(new Employee("MK", true, 3500.50, Arrays.asList(EmployeeType.Student, EmployeeType.Underage))); + + for (Employee employee: employees) + System.out.println("Real salary: " + employee.getRealSalary()); } } diff --git a/src/companies/Employee.java b/src/companies/Employee.java index 774b180..c1592c2 100644 --- a/src/companies/Employee.java +++ b/src/companies/Employee.java @@ -1,6 +1,7 @@ package companies; import java.util.EnumSet; +import java.util.List; public class Employee { private String name; @@ -9,11 +10,11 @@ public class Employee { private EnumSet employeeType; - public Employee(String name, boolean inWork, double salary, EnumSet employeeType) { + public Employee(String name, boolean inWork, double salary, List employeeType) { this.name = name; this.inWork = inWork; this.salary = salary; - this.employeeType = employeeType; + this.employeeType = EnumSet.copyOf(employeeType); } public String getName() { From 0c93d3739de0a04647901d495708dd8372cee105 Mon Sep 17 00:00:00 2001 From: kileruncio Date: Tue, 21 Mar 2023 00:15:10 +0100 Subject: [PATCH 07/13] feat: multiheritage --- README.md | 2 +- src/App.java | 12 +++++++++--- src/companies/OnePersonBuisness.java | 24 ++++++++++++++++++++++++ src/companies/Personable.java | 9 +++++++++ 4 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 src/companies/OnePersonBuisness.java create mode 100644 src/companies/Personable.java diff --git a/README.md b/README.md index 6a69209..dc0ca46 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,6 @@ _w każdym przypadku: liczności 1-* lub *-* oraz automatyczne tworzenie poł. z ## MP3 - [x] Klasa abstrakcyjna i polimorficzne wołanie metod - [x] Overlapping - - [ ] Wielodziedziczenie + - [x] Wielodziedziczenie - [ ] Wieloaspektowe - [ ] Dynamiczne \ No newline at end of file diff --git a/src/App.java b/src/App.java index 1fdbcae..f56a89e 100644 --- a/src/App.java +++ b/src/App.java @@ -4,12 +4,12 @@ import java.io.ObjectOutputStream; import java.util.ArrayList; import java.util.Arrays; -import java.util.EnumSet; import java.util.List; import companies.Corporation; import companies.Employee; import companies.EmployeeType; +import companies.OnePersonBuisness; import companies.Company; import companies.SmallBuisness; import tool.Hammer; @@ -105,7 +105,7 @@ public static void main(String[] args) { companies.add(new SmallBuisness("Topolowa 8, 00-999 Warcaby", "Wyroby Tomka")); companies.add(new Corporation("USA", "Nivea")); - for(Company company : companies) + for (Company company : companies) System.out.println("Profit of a company: " + company.getProfit()); // overlapping @@ -113,7 +113,13 @@ public static void main(String[] args) { employees.add(new Employee("MK", true, 3500.50, Arrays.asList(EmployeeType.Employee))); employees.add(new Employee("MK", true, 3500.50, Arrays.asList(EmployeeType.Student, EmployeeType.Underage))); - for (Employee employee: employees) + for (Employee employee : employees) System.out.println("Real salary: " + employee.getRealSalary()); + + // multiheritage + OnePersonBuisness wyrobyKrawieckie = new OnePersonBuisness("Taka brama. 07-007 Bulb", "Wyroby Krawieckie", 1993, 0.17); + System.out.println("Wiek: " + wyrobyKrawieckie.getAge()); + System.out.println("Zarobek: " + wyrobyKrawieckie.getProfit()); + System.out.println("Pieniądze po podatku: " + wyrobyKrawieckie.moneyAfterTax()); } } diff --git a/src/companies/OnePersonBuisness.java b/src/companies/OnePersonBuisness.java new file mode 100644 index 0000000..670600b --- /dev/null +++ b/src/companies/OnePersonBuisness.java @@ -0,0 +1,24 @@ +package companies; + +import java.time.LocalDateTime; + +public class OnePersonBuisness extends SmallBuisness implements companies.Personable { + private int yearOfBirth; + private double tax; + + public OnePersonBuisness(String address, String name, int yearOfBirth, double tax) { + super(address, name); + this.yearOfBirth = yearOfBirth; + this.tax = tax; + } + + public int getAge() { + return LocalDateTime.now().getYear() - this.yearOfBirth; + } + + @Override + public double moneyAfterTax() { + return super.getProfit() * (1 - this.tax); + } + +} diff --git a/src/companies/Personable.java b/src/companies/Personable.java new file mode 100644 index 0000000..c6e3943 --- /dev/null +++ b/src/companies/Personable.java @@ -0,0 +1,9 @@ +package companies; + +public interface Personable { + public int getAge(); + + public double getProfit(); + + public double moneyAfterTax(); +} From 7c77e3a7ae0e0a827ef6f3776fce9b6b703c2a5b Mon Sep 17 00:00:00 2001 From: kileruncio Date: Tue, 21 Mar 2023 22:48:20 +0100 Subject: [PATCH 08/13] feat: multispacts --- README.md | 2 +- src/App.java | 18 +++++++++++++ src/games/BoardGame.java | 15 +++++++++++ src/games/DigitalGame.java | 15 +++++++++++ src/games/Game.java | 52 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 src/games/BoardGame.java create mode 100644 src/games/DigitalGame.java create mode 100644 src/games/Game.java diff --git a/README.md b/README.md index dc0ca46..8ea10e4 100644 --- a/README.md +++ b/README.md @@ -24,5 +24,5 @@ _w każdym przypadku: liczności 1-* lub *-* oraz automatyczne tworzenie poł. z - [x] Klasa abstrakcyjna i polimorficzne wołanie metod - [x] Overlapping - [x] Wielodziedziczenie - - [ ] Wieloaspektowe + - [x] Wieloaspektowe - [ ] Dynamiczne \ No newline at end of file diff --git a/src/App.java b/src/App.java index f56a89e..bdc1784 100644 --- a/src/App.java +++ b/src/App.java @@ -12,6 +12,9 @@ import companies.OnePersonBuisness; import companies.Company; import companies.SmallBuisness; +import games.BoardGame; +import games.DigitalGame; +import games.Game; import tool.Hammer; import tool.Owner; import tool.Part; @@ -121,5 +124,20 @@ public static void main(String[] args) { System.out.println("Wiek: " + wyrobyKrawieckie.getAge()); System.out.println("Zarobek: " + wyrobyKrawieckie.getProfit()); System.out.println("Pieniądze po podatku: " + wyrobyKrawieckie.moneyAfterTax()); + + // multiaspects + ArrayList games = new ArrayList<>(); + games.add(new BoardGame("lego", 120.0, 3)); + games.add(new DigitalGame("EA", 260.0, "at least one brain")); + + for (Game game : games) { + if (game.hasNumberOfRequiredPlayers()) + System.out.println("Liczba wymaganych graczy: " + game.getNumberOfRequiredPlayers()); + else if (game.hasRequirements()) + System.out.println("Wymagania: " + game.getRequirements()); + } + + //dynamic + } } diff --git a/src/games/BoardGame.java b/src/games/BoardGame.java new file mode 100644 index 0000000..be31e4d --- /dev/null +++ b/src/games/BoardGame.java @@ -0,0 +1,15 @@ +package games; + +public class BoardGame extends Game { + + public BoardGame(String producer, double price, int numberOfRequiredPlayers) { + super(producer, price, numberOfRequiredPlayers); + + } + + @Override + public String play() { + return "Game is being played"; + } + +} diff --git a/src/games/DigitalGame.java b/src/games/DigitalGame.java new file mode 100644 index 0000000..3263050 --- /dev/null +++ b/src/games/DigitalGame.java @@ -0,0 +1,15 @@ +package games; + +public class DigitalGame extends Game { + + public DigitalGame(String producer, double price, String requirements) { + super(producer, price, requirements); + + } + + @Override + public String play() { + return "Turning game on"; + } + +} diff --git a/src/games/Game.java b/src/games/Game.java new file mode 100644 index 0000000..0a80072 --- /dev/null +++ b/src/games/Game.java @@ -0,0 +1,52 @@ +package games; + +public abstract class Game { + private String producer; + private double price; + private int numberOfRequiredPlayers = 0; + private String requirements = ""; + + + public Game(String producer, double price){ + this.producer = producer; + this.price = price; + } + + public Game(String producer, double price, int numberOfRequiredPlayers){ + this.producer = producer; + this.price = price; + this.numberOfRequiredPlayers = numberOfRequiredPlayers; + } + + public Game(String producer, double price, String requirements){ + this.producer = producer; + this.price = price; + this.requirements = requirements; + } + + public boolean hasNumberOfRequiredPlayers(){ + return this.numberOfRequiredPlayers != 0; + } + + public boolean hasRequirements(){ + return this.requirements.length() > 0; + } + + public double getPrice() { + return price; + } + + public String getProducer() { + return producer; + } + + public int getNumberOfRequiredPlayers(){ + return this.numberOfRequiredPlayers; + } + + public String getRequirements() { + return requirements; + } + + public abstract String play(); +} From e833a1e982f870797f7f65b9ce57b6c283332200 Mon Sep 17 00:00:00 2001 From: kileruncio Date: Wed, 22 Mar 2023 01:07:05 +0100 Subject: [PATCH 09/13] feat: dynamic --- README.md | 2 +- src/App.java | 12 ++++++++++-- src/games/Controler.java | 19 +++++++++++++++++++ src/games/Guitar.java | 25 +++++++++++++++++++++++++ src/games/Keyboard.java | 25 +++++++++++++++++++++++++ 5 files changed, 80 insertions(+), 3 deletions(-) create mode 100644 src/games/Controler.java create mode 100644 src/games/Guitar.java create mode 100644 src/games/Keyboard.java diff --git a/README.md b/README.md index 8ea10e4..00fee95 100644 --- a/README.md +++ b/README.md @@ -25,4 +25,4 @@ _w każdym przypadku: liczności 1-* lub *-* oraz automatyczne tworzenie poł. z - [x] Overlapping - [x] Wielodziedziczenie - [x] Wieloaspektowe - - [ ] Dynamiczne \ No newline at end of file + - [x] Dynamiczne \ No newline at end of file diff --git a/src/App.java b/src/App.java index bdc1784..58d6556 100644 --- a/src/App.java +++ b/src/App.java @@ -13,8 +13,11 @@ import companies.Company; import companies.SmallBuisness; import games.BoardGame; +import games.Controler; import games.DigitalGame; import games.Game; +import games.Guitar; +import games.Keyboard; import tool.Hammer; import tool.Owner; import tool.Part; @@ -137,7 +140,12 @@ else if (game.hasRequirements()) System.out.println("Wymagania: " + game.getRequirements()); } - //dynamic - + // dynamic + Controler controler = new Keyboard("MSI", 2137, "chiness"); + System.out.println(controler.toString()); + controler = new Guitar(controler, 2); + System.out.println(controler.toString()); + controler = new Keyboard(controler, "English simplified"); + System.out.println(controler.toString()); } } diff --git a/src/games/Controler.java b/src/games/Controler.java new file mode 100644 index 0000000..35e12ed --- /dev/null +++ b/src/games/Controler.java @@ -0,0 +1,19 @@ +package games; + +public abstract class Controler { + private String producer; + private int numberOfButtons; + + public Controler(String producer, int numberOfButtons) { + this.producer = producer; + this.numberOfButtons = numberOfButtons; + } + + public int getNumberOfButtons() { + return numberOfButtons; + } + + public String getProducer() { + return producer; + } +} diff --git a/src/games/Guitar.java b/src/games/Guitar.java new file mode 100644 index 0000000..3faab77 --- /dev/null +++ b/src/games/Guitar.java @@ -0,0 +1,25 @@ +package games; + +public class Guitar extends Controler { + private int numberOfPorts; + + public Guitar(String producer, int numberOfButtons, int numberOfPorts) { + super(producer, numberOfButtons); + this.numberOfPorts = numberOfPorts; + } + + public Guitar(Controler controler, int numberOfPorts) { + super(controler.getProducer(), controler.getNumberOfButtons()); + this.numberOfPorts = numberOfPorts; + } + + public int getNumberOfPorts() { + return numberOfPorts; + } + + @Override + public String toString() { + return "Guitar, producer: " + this.getProducer() + " nuber of ports: " + getNumberOfPorts(); + } + +} diff --git a/src/games/Keyboard.java b/src/games/Keyboard.java new file mode 100644 index 0000000..a21238a --- /dev/null +++ b/src/games/Keyboard.java @@ -0,0 +1,25 @@ +package games; + +public class Keyboard extends Controler { + private String typeOfKeyboard; + + public Keyboard(String producer, int numberOfButtons, String typeOfKeyboard) { + super(producer, numberOfButtons); + this.typeOfKeyboard = typeOfKeyboard; + } + + public Keyboard(Controler controler, String typeOfKeyboard) { + super(controler.getProducer(), controler.getNumberOfButtons()); + this.typeOfKeyboard = typeOfKeyboard; + } + + public String getTypeOfKeyboard() { + return typeOfKeyboard; + } + + @Override + public String toString() { + return "Keyboard, producer: " + this.getProducer() + " type of keyboard: " + getTypeOfKeyboard(); + } + +} From b57ef3760b8ef59a64bc34849523f3c9616ca600 Mon Sep 17 00:00:00 2001 From: kileruncio Date: Tue, 28 Mar 2023 21:30:55 +0200 Subject: [PATCH 10/13] fix: overlapping --- src/App.java | 7 ++++--- src/companies/Employee.java | 27 ++++++++++++++++++++++----- src/companies/EmployeeType.java | 2 +- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/App.java b/src/App.java index 58d6556..c674857 100644 --- a/src/App.java +++ b/src/App.java @@ -116,14 +116,15 @@ public static void main(String[] args) { // overlapping ArrayList employees = new ArrayList<>(); - employees.add(new Employee("MK", true, 3500.50, Arrays.asList(EmployeeType.Employee))); - employees.add(new Employee("MK", true, 3500.50, Arrays.asList(EmployeeType.Student, EmployeeType.Underage))); + employees.add(new Employee("MK", true, 3500.50, Arrays.asList(EmployeeType.EMPLOYEE), true)); + employees.add(new Employee("MK", true, 3500.50, Arrays.asList(EmployeeType.STUDENT, EmployeeType.UNDERAGE), true)); for (Employee employee : employees) System.out.println("Real salary: " + employee.getRealSalary()); // multiheritage - OnePersonBuisness wyrobyKrawieckie = new OnePersonBuisness("Taka brama. 07-007 Bulb", "Wyroby Krawieckie", 1993, 0.17); + OnePersonBuisness wyrobyKrawieckie = new OnePersonBuisness("Taka brama. 07-007 Bulb", "Wyroby Krawieckie", 1993, + 0.17); System.out.println("Wiek: " + wyrobyKrawieckie.getAge()); System.out.println("Zarobek: " + wyrobyKrawieckie.getProfit()); System.out.println("Pieniądze po podatku: " + wyrobyKrawieckie.moneyAfterTax()); diff --git a/src/companies/Employee.java b/src/companies/Employee.java index c1592c2..2b4433f 100644 --- a/src/companies/Employee.java +++ b/src/companies/Employee.java @@ -4,17 +4,34 @@ import java.util.List; public class Employee { + // overlapping private String name; private boolean inWork; private double salary; + private int NIP; + private boolean insurance; private EnumSet employeeType; - public Employee(String name, boolean inWork, double salary, List employeeType) { + public Employee(String name, boolean inWork, double salary, List employeeType, boolean insurance) { this.name = name; this.inWork = inWork; this.salary = salary; this.employeeType = EnumSet.copyOf(employeeType); + if (this.employeeType.contains(EmployeeType.EMPLOYEE)) + this.insurance = insurance; + } + + public boolean isInsurance() { + return insurance; + } + + public void setNIP(int NIP) { + this.NIP = NIP; + } + + public int getNIP() { + return this.employeeType.contains(EmployeeType.COMPANY) ? NIP : 0; } public String getName() { @@ -32,28 +49,28 @@ public double getSalary() { public double getRealSalary() { double resoult = 0; - if (this.employeeType.add(EmployeeType.Company)) { + if (this.employeeType.contains(EmployeeType.COMPANY)) { if (resoult == 0) resoult = this.salary * 0.7; else resoult += this.salary * 0.7; } - if (this.employeeType.add(EmployeeType.Student)) { + if (this.employeeType.contains(EmployeeType.STUDENT)) { if (resoult == 0) resoult = this.salary; else resoult += this.salary; } - if (this.employeeType.add(EmployeeType.Underage)) { + if (this.employeeType.contains(EmployeeType.UNDERAGE)) { if (resoult == 0) resoult = this.salary; else resoult += this.salary; } - if (this.employeeType.add(EmployeeType.Employee)) { + if (this.employeeType.contains(EmployeeType.EMPLOYEE)) { if (resoult == 0) resoult = this.salary * 0.6; else diff --git a/src/companies/EmployeeType.java b/src/companies/EmployeeType.java index 02f504c..d31a5ac 100644 --- a/src/companies/EmployeeType.java +++ b/src/companies/EmployeeType.java @@ -1,5 +1,5 @@ package companies; public enum EmployeeType { - Student, Underage, Employee, Company + STUDENT, UNDERAGE, EMPLOYEE, COMPANY }; From 892e568a4a1a2ac7e8031ffffe6aa5fa9541724a Mon Sep 17 00:00:00 2001 From: kileruncio Date: Tue, 28 Mar 2023 21:52:40 +0200 Subject: [PATCH 11/13] fix: multiheritage --- src/companies/OnePersonBuisness.java | 2 ++ src/companies/Personable.java | 1 + src/companies/SmallBuisness.java | 1 + 3 files changed, 4 insertions(+) diff --git a/src/companies/OnePersonBuisness.java b/src/companies/OnePersonBuisness.java index 670600b..4acb588 100644 --- a/src/companies/OnePersonBuisness.java +++ b/src/companies/OnePersonBuisness.java @@ -3,6 +3,8 @@ import java.time.LocalDateTime; public class OnePersonBuisness extends SmallBuisness implements companies.Personable { + // multiheritage + // Company -> SmallBuisness -> OnePersonBuisness + companies.Personable private int yearOfBirth; private double tax; diff --git a/src/companies/Personable.java b/src/companies/Personable.java index c6e3943..21ef575 100644 --- a/src/companies/Personable.java +++ b/src/companies/Personable.java @@ -1,6 +1,7 @@ package companies; public interface Personable { + // multiheritage public int getAge(); public double getProfit(); diff --git a/src/companies/SmallBuisness.java b/src/companies/SmallBuisness.java index 00950cf..fb8f31a 100644 --- a/src/companies/SmallBuisness.java +++ b/src/companies/SmallBuisness.java @@ -1,6 +1,7 @@ package companies; public class SmallBuisness extends Company { + // multiheritage private double income; public SmallBuisness(String address, String name) { From 32213b87f943a6cb3e8bf0f6ac5093a2ed9364ff Mon Sep 17 00:00:00 2001 From: kileruncio Date: Tue, 28 Mar 2023 22:21:00 +0200 Subject: [PATCH 12/13] fix: multiaspects --- src/App.java | 11 ++++++----- src/games/BoardGame.java | 15 --------------- src/games/BoardMultiplayerGame.java | 27 +++++++++++++++++++++++++++ src/games/DigitalGame.java | 15 --------------- src/games/FabularDigitalGame.java | 20 ++++++++++++++++++++ src/games/Game.java | 2 ++ 6 files changed, 55 insertions(+), 35 deletions(-) delete mode 100644 src/games/BoardGame.java create mode 100644 src/games/BoardMultiplayerGame.java delete mode 100644 src/games/DigitalGame.java create mode 100644 src/games/FabularDigitalGame.java diff --git a/src/App.java b/src/App.java index c674857..d85e6da 100644 --- a/src/App.java +++ b/src/App.java @@ -12,9 +12,9 @@ import companies.OnePersonBuisness; import companies.Company; import companies.SmallBuisness; -import games.BoardGame; +import games.BoardMultiplayerGame; import games.Controler; -import games.DigitalGame; +import games.FabularDigitalGame; import games.Game; import games.Guitar; import games.Keyboard; @@ -117,7 +117,8 @@ public static void main(String[] args) { // overlapping ArrayList employees = new ArrayList<>(); employees.add(new Employee("MK", true, 3500.50, Arrays.asList(EmployeeType.EMPLOYEE), true)); - employees.add(new Employee("MK", true, 3500.50, Arrays.asList(EmployeeType.STUDENT, EmployeeType.UNDERAGE), true)); + employees.add( + new Employee("MK", true, 3500.50, Arrays.asList(EmployeeType.STUDENT, EmployeeType.UNDERAGE), true)); for (Employee employee : employees) System.out.println("Real salary: " + employee.getRealSalary()); @@ -131,8 +132,8 @@ public static void main(String[] args) { // multiaspects ArrayList games = new ArrayList<>(); - games.add(new BoardGame("lego", 120.0, 3)); - games.add(new DigitalGame("EA", 260.0, "at least one brain")); + games.add(new BoardMultiplayerGame("lego", 120.0, 3, "dixit", 300)); + games.add(new FabularDigitalGame("EA", 260.0, "at least one brain", 4)); for (Game game : games) { if (game.hasNumberOfRequiredPlayers()) diff --git a/src/games/BoardGame.java b/src/games/BoardGame.java deleted file mode 100644 index be31e4d..0000000 --- a/src/games/BoardGame.java +++ /dev/null @@ -1,15 +0,0 @@ -package games; - -public class BoardGame extends Game { - - public BoardGame(String producer, double price, int numberOfRequiredPlayers) { - super(producer, price, numberOfRequiredPlayers); - - } - - @Override - public String play() { - return "Game is being played"; - } - -} diff --git a/src/games/BoardMultiplayerGame.java b/src/games/BoardMultiplayerGame.java new file mode 100644 index 0000000..97ec048 --- /dev/null +++ b/src/games/BoardMultiplayerGame.java @@ -0,0 +1,27 @@ +package games; + +public class BoardMultiplayerGame extends Game { + private String title; + private int lengthOfPlay; + + public BoardMultiplayerGame(String producer, double price, int numberOfRequiredPlayers, String title, + int lengthOfPlay) { + super(producer, price, numberOfRequiredPlayers); + this.title = title; + this.lengthOfPlay = lengthOfPlay; + } + + public String getTitle() { + return title; + } + + public int getLengthOfPlay() { + return lengthOfPlay; + } + + @Override + public String play() { + return "Game is being played"; + } + +} diff --git a/src/games/DigitalGame.java b/src/games/DigitalGame.java deleted file mode 100644 index 3263050..0000000 --- a/src/games/DigitalGame.java +++ /dev/null @@ -1,15 +0,0 @@ -package games; - -public class DigitalGame extends Game { - - public DigitalGame(String producer, double price, String requirements) { - super(producer, price, requirements); - - } - - @Override - public String play() { - return "Turning game on"; - } - -} diff --git a/src/games/FabularDigitalGame.java b/src/games/FabularDigitalGame.java new file mode 100644 index 0000000..72d2868 --- /dev/null +++ b/src/games/FabularDigitalGame.java @@ -0,0 +1,20 @@ +package games; + +public class FabularDigitalGame extends Game { + private int possilbeEdings; + + public FabularDigitalGame(String producer, double price, String requirements, int possilbeEdings) { + super(producer, price, requirements); + this.possilbeEdings = possilbeEdings; + } + + public int getPossilbeEdings() { + return possilbeEdings; + } + + @Override + public String play() { + return "Turning game on"; + } + +} diff --git a/src/games/Game.java b/src/games/Game.java index 0a80072..27d18db 100644 --- a/src/games/Game.java +++ b/src/games/Game.java @@ -13,12 +13,14 @@ public Game(String producer, double price){ } public Game(String producer, double price, int numberOfRequiredPlayers){ + // multiplayer this.producer = producer; this.price = price; this.numberOfRequiredPlayers = numberOfRequiredPlayers; } public Game(String producer, double price, String requirements){ + // digital this.producer = producer; this.price = price; this.requirements = requirements; From 0dfb565c14266e0825e0d0040ceb91f7f21929a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Piszcz?= Date: Fri, 8 Dec 2023 16:34:30 +0100 Subject: [PATCH 13/13] deleted App --- src/App.java | 154 --------------------------------------------------- 1 file changed, 154 deletions(-) delete mode 100644 src/App.java diff --git a/src/App.java b/src/App.java deleted file mode 100644 index 7cf4b11..0000000 --- a/src/App.java +++ /dev/null @@ -1,154 +0,0 @@ -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import companies.Corporation; -import companies.Employee; -import companies.EmployeeType; -import companies.OnePersonBuisness; -import companies.Company; -import companies.SmallBuisness; -import games.BoardMultiplayerGame; -import games.Controler; -import games.FabularDigitalGame; -import games.Game; -import games.Guitar; -import games.Keyboard; -import tool.Hammer; -import tool.Owner; -import tool.Part; -import tool.Tool; -import tool.ToolShop; -import tool.Toolbox; -import tool.Transaction; - -public class App { - final static String fileName = "data/data.kfc"; - - public static void main(String[] args) { - List languages0 = new ArrayList<>(); - List languages1 = new ArrayList<>(); - languages0.add("en"); - languages0.add("fr"); - languages1.add("jp"); - languages1.add("hr"); - - Tool[] tools = { - new Tool(null, "machanick", null, 2, languages0), - new Tool("Bosh", "automatic", "producer", 5, languages1), - new Hammer("me", "one-hand", null, 1, new ArrayList<>()) - }; - - for (Tool it : tools) { - System.out.println(it.toString()); - System.out.println(it.use()); - } - - System.out.println(Tool.numberOfDifferentTools()); - - try { - var out = new ObjectOutputStream(new FileOutputStream(fileName)); - Tool.writeTools(out); - out.close(); - - var in = new ObjectInputStream(new FileInputStream(fileName)); - Tool.readTools(in); - in.close(); - } catch (Exception exc) { - exc.printStackTrace(); - } - - System.out.println("------------------------\n"); - - System.out.println(Tool.numberOfDifferentTools()); - System.out.println(Tool.getFromTools()); - - // -----------------------MP2----------------------- - Toolbox toolbox1 = new Toolbox(); - ToolShop toolShop1 = new ToolShop("cheap"); - Owner owner1 = new Owner("alice", "xx-343-yt"); - - // normal - try { - tools[0].addToToolbox(toolbox1); - } catch (Exception exc) { - exc.printStackTrace(); - } - - System.out.println(toolbox1.getTools().toString()); - - // attribute - Transaction transaction = new Transaction(48.24, owner1, toolShop1); - System.out.println(owner1.getTransactions().toString()); - System.out.println(toolShop1.getTransactions().toString()); - - // aggravated - try { - owner1.addToolbox("basic", toolbox1); - } catch (Exception exc) { - exc.printStackTrace(); - } - - System.out.println("Owner has: " + owner1.getToolboxes().toString()); - - // composition - try { - Part.createPart("screw", tools[0]); - } catch (Exception exc) { - exc.printStackTrace(); - } - - System.out.println("Parts: " + tools[0].getParts().toString()); - - // -----------------------MP3----------------------- - - // abstract & polimorfizm - ArrayList companies = new ArrayList<>(); - companies.add(new SmallBuisness("Topolowa 8, 00-999 Warcaby", "Wyroby Tomka")); - companies.add(new Corporation("USA", "Nivea")); - - for (Company company : companies) - System.out.println("Profit of a company: " + company.getProfit()); - - // overlapping - ArrayList employees = new ArrayList<>(); - employees.add(new Employee("MK", true, 3500.50, Arrays.asList(EmployeeType.EMPLOYEE), true)); - employees.add( - new Employee("MK", true, 3500.50, Arrays.asList(EmployeeType.STUDENT, EmployeeType.UNDERAGE), true)); - - for (Employee employee : employees) - System.out.println("Real salary: " + employee.getRealSalary()); - - // multiheritage - OnePersonBuisness wyrobyKrawieckie = new OnePersonBuisness("Taka brama. 07-007 Bulb", "Wyroby Krawieckie", 1993, - 0.17); - System.out.println("Wiek: " + wyrobyKrawieckie.getAge()); - System.out.println("Zarobek: " + wyrobyKrawieckie.getProfit()); - System.out.println("Pieniądze po podatku: " + wyrobyKrawieckie.moneyAfterTax()); - - // multiaspects - ArrayList games = new ArrayList<>(); - games.add(new BoardMultiplayerGame("lego", 120.0, 3, "dixit", 300)); - games.add(new FabularDigitalGame("EA", 260.0, "at least one brain", 4)); - - for (Game game : games) { - if (game.hasNumberOfRequiredPlayers()) - System.out.println("Liczba wymaganych graczy: " + game.getNumberOfRequiredPlayers()); - else if (game.hasRequirements()) - System.out.println("Wymagania: " + game.getRequirements()); - } - - // dynamic - Controler controler = new Keyboard("MSI", 2137, "chiness"); - System.out.println(controler.toString()); - controler = new Guitar(controler, 2); - System.out.println(controler.toString()); - controler = new Keyboard(controler, "English simplified"); - System.out.println(controler.toString()); - } -} -