Skip to content
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,13 @@
- [x] Kwalifikowana
- [x] Kompozycja

_w każdym przypadku: liczności 1-* lub *-* oraz automatyczne tworzenie poł. zwrotnego_
_w każdym przypadku: liczności 1-* lub *-* oraz automatyczne tworzenie poł. zwrotnego_

## MP3
- [x] Klasa abstrakcyjna
- [x] Disjoint
- [x] Polimorficzne wywołanie metody
- [x] Overlapping
- [x] Wielodziedziczenie
- [x] Wieloaspektowe
- [x] Dynamiczne
73 changes: 72 additions & 1 deletion src/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,30 @@
import java.io.ObjectOutputStream;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import companies.Company;
import companies.Corporation;
import companies.Employee;
import companies.EmployeeType;
import companies.OnePersonBuisness;
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.Screwdriver;
import tool.Tool;
import tool.ToolShop;
import tool.Toolbox;
import tool.Transaction;

public class Main {
final static String fileName = "data/data.kfc";

Expand All @@ -21,7 +43,7 @@ public static void main(String[] args) throws Exception {
Tool[] tools = {
new Tool("LG", "machanick", null, 2, languages0),
new Tool("Bosh", "automatic", "A new company", 5, languages1),
new Hammer("me", "one-hand", null, 10, new ArrayList<>()/**/)
new Hammer("me", "one-hand", null, 10, new ArrayList<>())
};

tools[0].owner = null; // atrybut opcjonalny - można to umieścić wartość lub podać null
Expand Down Expand Up @@ -102,5 +124,54 @@ public static void main(String[] args) throws Exception {

System.out.println("Parts: " + tools[0].getParts().toString()); // kompozycja - wypisanie kolekcji Parts z obiektu Tool

// -----------------------MP3-----------------------

// disjoint - klasy screwdriver oraz hammer są implementowane poprzez disjoint, jest to dziedziczenie rozłączne
Tool narzedzie = new Tool("Bosh", "automatic", "A new company", 5, languages1);
Screwdriver screwdriver = new Screwdriver("Maciej P", "krzyżakowo", null, 1, "red", languages1);
Hammer hammer = new Hammer("me", "one-hand", null, 10, new ArrayList<>());

System.out.println("Color of a screwdriver: " + screwdriver.getColor());
System.out.println(hammer.use());
System.out.println(narzedzie.use());

ArrayList<Company> companies = new ArrayList<>(); // klasa abstrakcyjna - powstaje tutaj lista przechowująca obiekty dziedziczące z klasy abstrakcyjnej, dlatego chodź nie są to obiekty klasy Company mogą one być w tej kolekcji
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());

ArrayList<Employee> employees = new ArrayList<>(); // overlapping - w tej kolekcji powajwiają się obiekty które mogą należeć do kilku klas na raz np do klasy student i 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()); // polimofriczne wywołanie metody - metoda działa inaczej zależnie od właściwej klasy obiektu, w tym trydnym przypadku jest to zależne od obiektu jak i wartości pola employeeType

OnePersonBuisness wyrobyKrawieckie = new OnePersonBuisness(
"Taka brama. 07-007 Bulb", "Wyroby Krawieckie", 1993,0.17
); // wielodziedziczenie - klasa OnePersonBuisness dziedziczy z klas SmallBuisness oraz Personable
System.out.println("Wiek: " + wyrobyKrawieckie.getAge());
System.out.println("Zarobek: " + wyrobyKrawieckie.getProfit());
System.out.println("Pieniądze po podatku: " + wyrobyKrawieckie.moneyAfterTax());

ArrayList<Game> games = new ArrayList<>(); // wieloaspektowe - obiekty dziedziczą wieloapektowo po kalsie Game, gry mogą być cyforwe lub wieloosobowe (widać to po konstruktorze), pojawiają się jako przykłady gry planszowe oraz fabularne
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());
}

Controler controler = new Keyboard("MSI", 2137, "chiness"); // dynamiczne - poprzez opcjonalne kopiowanie poprzedniego obiektu obiekt klasy Keyboard może stać się obiektem klasy Guitar i z powrotem
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());
}
}
21 changes: 21 additions & 0 deletions src/companies/Company.java
Original file line number Diff line number Diff line change
@@ -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 getProfit();

public String getName() {
return this.name;
}

public String getAddress() {
return this.address;
}
}
16 changes: 16 additions & 0 deletions src/companies/Corporation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package companies;

public class Corporation extends Company {
private double income;

public Corporation(String address, String name) {
super(address, name);
this.income = Math.random() * 100000;
}

@Override
public double getProfit() {
return income * 0.3;
}

}
82 changes: 82 additions & 0 deletions src/companies/Employee.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package companies;

import java.util.EnumSet;
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> employeeType;

public Employee(String name, boolean inWork, double salary, List<EmployeeType> 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() {
return name;
}

public boolean isInWork() {
return inWork;
}

public double getSalary() {
return salary;
}

public double getRealSalary() {
double resoult = 0;

if (this.employeeType.contains(EmployeeType.COMPANY)) {
if (resoult == 0)
resoult = this.salary * 0.7;
else
resoult += this.salary * 0.7;
}

if (this.employeeType.contains(EmployeeType.STUDENT)) {
if (resoult == 0)
resoult = this.salary;
else
resoult += this.salary;
}

if (this.employeeType.contains(EmployeeType.UNDERAGE)) {
if (resoult == 0)
resoult = this.salary;
else
resoult += this.salary;
}

if (this.employeeType.contains(EmployeeType.EMPLOYEE)) {
if (resoult == 0)
resoult = this.salary * 0.6;
else
resoult += this.salary * 0.6;
}

return resoult;
}
}
5 changes: 5 additions & 0 deletions src/companies/EmployeeType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package companies;

public enum EmployeeType {
STUDENT, UNDERAGE, EMPLOYEE, COMPANY
};
26 changes: 26 additions & 0 deletions src/companies/OnePersonBuisness.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package companies;

import java.time.LocalDateTime;

public class OnePersonBuisness extends SmallBuisness implements companies.Personable {
// multiheritage
// Company -> SmallBuisness -> OnePersonBuisness + 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);
}

}
10 changes: 10 additions & 0 deletions src/companies/Personable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package companies;

public interface Personable {
// multiheritage
public int getAge();

public double getProfit();

public double moneyAfterTax();
}
17 changes: 17 additions & 0 deletions src/companies/SmallBuisness.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package companies;

public class SmallBuisness extends Company {
// multiheritage
private double income;

public SmallBuisness(String address, String name) {
super(address, name);
this.income = Math.random() * 1000;
}

@Override
public double getProfit() {
return income * 0.7;
}

}
26 changes: 26 additions & 0 deletions src/games/BoardMultiplayerGame.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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";
}

}
19 changes: 19 additions & 0 deletions src/games/Controler.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
20 changes: 20 additions & 0 deletions src/games/FabularDigitalGame.java
Original file line number Diff line number Diff line change
@@ -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";
}

}
Loading