diff --git a/README.md b/README.md index 734d25c..993a944 100644 --- a/README.md +++ b/README.md @@ -18,4 +18,14 @@ - [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_ + + +## MP4 + - [x] Atrybutu + - [x] Unique + - [x] Subset + - [x] Ordered + - [x] Bag + - [x] Xor + - [x] Ograniczenie Własne \ No newline at end of file diff --git a/src/App.java b/src/App.java index 459a7d6..a0ca0fa 100644 --- a/src/App.java +++ b/src/App.java @@ -5,6 +5,11 @@ import java.util.ArrayList; import java.util.List; +import taxOffice.Author; +import taxOffice.Director; +import taxOffice.Document; +import taxOffice.TaxOffice; + public class App { final static String fileName = "data/data.kfc"; @@ -83,5 +88,88 @@ public static void main(String[] args) { System.out.println("Parts: " + tools[0].getParts().toString()); + // -----------------------MP4----------------------- + + // atrybut + TaxOffice taxOffice; + try { + taxOffice = new TaxOffice("kajki 3"); + taxOffice.setNumber(5); + System.out.println(taxOffice.getNumber()); + taxOffice.setNumber(-2); + } catch (Exception exc) { + System.out.println(exc); + } + + // Unique + try { + TaxOffice to = new TaxOffice("ladna 2"); + TaxOffice ti = new TaxOffice("kajki 3"); + } catch (Exception exc) { + System.out.println(exc); + } + + // Subset + try { + TaxOffice to = new TaxOffice("jp2 2"); + Director director1 = new Director(); + Director director2 = new Director(); + to.addDirector(director1); + to.addDirector(director2); + to.chooseMainDirector(director2); + System.out.println(to.getMainDirector()); + to.chooseMainDirector(new Director()); + } catch (Exception exc) { + exc.printStackTrace(); + } + + // Ordered + Document d = new Document(); + Document o = new Document(); + Document c = new Document(); + Document u = new Document(); + Document m = new Document(); + Document e = new Document(); + Document n = new Document(); + Document t = new Document(); + Document.showAllDocuments(); + + // Bag + Author[] authors1 = { new Author(0) }; + Author[] authors2 = { new Author(0), new Author(1) }; + Author[] authors3 = { new Author(0), new Author(1), new Author(2) }; + + Document doc = new Document(authors1, "zlksmfspdokf"); + Document ume = new Document(authors2, "xdfdvcbcvb"); + Document nt = new Document(authors3, "qwewqrertrtt7ui"); + + System.out.println(doc.showRelation()); + System.out.println(ume.showRelation()); + System.out.println(nt.showRelation()); + + // Xor + try { + Director di = new Director(); + TaxOffice tx = new TaxOffice("k puchatka 3"); + authors1[0].setDirector(di); + authors2[1].setTaxoffice(tx); + authors1[0].setTaxoffice(tx); + } catch (Exception exc) { + exc.printStackTrace(); + } + + // Ograniczenie Własne + Document cument = new Document(); + System.out.println(cument.getNumberOfCopies()); + cument.makeCopy(); + System.out.println(cument.getNumberOfCopies()); + cument.destoyCopy(); + System.out.println(cument.getNumberOfCopies()); + cument.destoyCopy(); + System.out.println(cument.getNumberOfCopies()); + cument.destoyCopy(); + System.out.println(cument.getNumberOfCopies()); + cument.makeCopy(); + System.out.println(cument.getNumberOfCopies()); } } diff --git a/src/taxOffice/Author.java b/src/taxOffice/Author.java new file mode 100644 index 0000000..3de88bd --- /dev/null +++ b/src/taxOffice/Author.java @@ -0,0 +1,37 @@ +package taxOffice; + +import java.util.ArrayList; +import java.util.List; + +public class Author { + private List documents; + private int id; + private TaxOffice taxoffice; + private Director director; + + public Author(int id) { + this.id = id; + } + + public void setTaxoffice(TaxOffice taxoffice) throws Exception { + if (this.director == null) + this.taxoffice = taxoffice; + else + throw new Exception("Coannot be in relation with director and tax office"); + } + + public void setDirector(Director director) throws Exception { + if (this.taxoffice == null) + this.director = director; + else + throw new Exception("Coannot be in relation with director and tax office"); + + } + + public void setDocuments(DocumentAuthor... documentauthor) { + this.documents = new ArrayList<>(); + for (DocumentAuthor da : documentauthor) { + this.documents.add(da); + } + } +} diff --git a/src/taxOffice/Director.java b/src/taxOffice/Director.java new file mode 100644 index 0000000..2be50ca --- /dev/null +++ b/src/taxOffice/Director.java @@ -0,0 +1,10 @@ +package taxOffice; + +public class Director { + private TaxOffice taxOffice; + private Author author; + + public void setTaxOffice(TaxOffice taxOffice) { + this.taxOffice = taxOffice; + } +} diff --git a/src/taxOffice/Document.java b/src/taxOffice/Document.java new file mode 100644 index 0000000..a365320 --- /dev/null +++ b/src/taxOffice/Document.java @@ -0,0 +1,58 @@ +package taxOffice; + +import java.util.ArrayList; +import java.util.List; + +public class Document { + private static List documents = new ArrayList<>(); + private List authors; + private int numberOfCopies; + + public Document() { + this.numberOfCopies = 1; + documents.add(this); + } + + public int getNumberOfCopies() { + return numberOfCopies; + } + + public Document(Author[] authors, String edition) { + this.numberOfCopies = 1; + documents.add(this); + setAuthors(authors, edition); + } + + public void makeCopy(){ + if (this.numberOfCopies > 0) + this.numberOfCopies++; + } + + public void destoyCopy(){ + if (this.numberOfCopies >= 1) + this.numberOfCopies--; + } + + private void setAuthors(Author[] authors, String edition) { + this.authors = new ArrayList<>(); + for (Author author : authors) { + DocumentAuthor da = new DocumentAuthor(edition); + da.setDocument(this); + da.setAuthor(author); + this.authors.add(da); + } + } + + public String showRelation() { + String resoult = ""; + for (DocumentAuthor da : authors) { + resoult += da.toString() + " || "; + } + return resoult; + } + + public static void showAllDocuments() { + for (Document d : documents) + System.out.println(d); + } +} diff --git a/src/taxOffice/DocumentAuthor.java b/src/taxOffice/DocumentAuthor.java new file mode 100644 index 0000000..6dd55c3 --- /dev/null +++ b/src/taxOffice/DocumentAuthor.java @@ -0,0 +1,20 @@ +package taxOffice; + +public class DocumentAuthor { + private Author author; + private Document document; + private String edition; + + public DocumentAuthor(String edition) { + this.edition = edition; + } + + public void setAuthor(Author author) { + this.author = author; + this.author.setDocuments(this); + } + + public void setDocument(Document document) { + this.document = document; + } +} diff --git a/src/taxOffice/TaxOffice.java b/src/taxOffice/TaxOffice.java new file mode 100644 index 0000000..24cd034 --- /dev/null +++ b/src/taxOffice/TaxOffice.java @@ -0,0 +1,63 @@ +package taxOffice; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class TaxOffice { + private String address; + private int number; + private List directors; + private Director mainDirector; + private List authors; + public static Set addresses = new HashSet<>(); + + public TaxOffice(String addres) throws Exception { + this.directors = new ArrayList<>(); + this.authors = new ArrayList<>(); + setAddress(addres); + } + + public String getAddress() { + return this.address; + } + + public int getNumber() { + return this.number; + } + + private void setAddress(String address) throws Exception { + if (!addresses.contains(address)) { + addresses.add(address); + this.address = address; + } else + throw new Exception("Ther's already TaxOffice with this address"); + } + + public void setNumber(int number) throws Exception { + if (number > 0) + this.number = number; + else + throw new Exception("Number of a TaxOffice must be positive"); + } + + public void addDirector(Director director){ + if (directors == null){ + this.directors = new ArrayList<>(); + } + this.directors.add(director); + director.setTaxOffice(this); + } + + public void chooseMainDirector(Director director) throws Exception { + if (this.directors.contains(director)) + this.mainDirector = director; + else + throw new Exception("This Director is not a part of this TaxOffice"); + } + + public Director getMainDirector() { + return mainDirector; + } +}