commit a1d22e92c2b74616ca45583685d93e72829cad58 Author: Aelita4 Date: Tue Nov 15 09:27:13 2022 +0100 Lab 5 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f68d109 --- /dev/null +++ b/.gitignore @@ -0,0 +1,29 @@ +### IntelliJ IDEA ### +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..07115cd --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..4b70421 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..be2e46f --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,96 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1668496014923 + + + + + + + \ No newline at end of file diff --git a/Lab5.iml b/Lab5.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/Lab5.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/Figura.java b/src/Figura.java new file mode 100644 index 0000000..7826660 --- /dev/null +++ b/src/Figura.java @@ -0,0 +1,25 @@ +class Figura { + + //pola metody i kontruktory + Punkt punkt; + String kolor = "bialy"; + + + Figura(){ + punkt = new Punkt(0,0); + } + Figura(String kolor){ + this.kolor=kolor; + } + Figura(Punkt punkt){ + this.punkt=punkt; + } + String getKolor(){ + return kolor; + } + String opis(){ + return "Klasa Figura. Kolor obiektu: "+kolor; + } + + +} \ No newline at end of file diff --git a/src/Klient.java b/src/Klient.java new file mode 100644 index 0000000..799182b --- /dev/null +++ b/src/Klient.java @@ -0,0 +1,12 @@ +public class Klient { + String imie, nazwisko; + + public Klient(String imie, String nazwisko) { + this.imie = imie; + this.nazwisko = nazwisko; + } + + public String getImieNazwisko() { + return imie + " " + nazwisko; + } +} diff --git a/src/Ksiazka.java b/src/Ksiazka.java new file mode 100644 index 0000000..7b90e2f --- /dev/null +++ b/src/Ksiazka.java @@ -0,0 +1,18 @@ +public class Ksiazka { + String isbn; + String tytul; + String autor; + int rokWydania; + + public Ksiazka(String isbn, String tytul, String autor, int rokWydania) { + this.isbn = isbn; + this.tytul = tytul; + this.autor = autor; + this.rokWydania = rokWydania; + } + + public void opis() { + System.out.println(tytul + ", " + autor + ", rok " + rokWydania); + System.out.println("ISBN: " + isbn); + } +} diff --git a/src/Ksiegarnia.java b/src/Ksiegarnia.java new file mode 100644 index 0000000..1f8a3bc --- /dev/null +++ b/src/Ksiegarnia.java @@ -0,0 +1,31 @@ +public class Ksiegarnia { + Ksiazka[] ksiazki = new Ksiazka[20]; + int ksiazkiIndex = 0; + Klient[] klienci = new Klient[20]; + int klienciIndex = 0; + + public void addKlient(Klient k) { + klienci[klienciIndex++] = k; + } + + public void addKlient(String imie, String nazwisko) { + Klient k = new Klient(imie, nazwisko); + klienci[klienciIndex++] = k; + } + + public void addKsiazka(Ksiazka k) { + ksiazki[ksiazkiIndex++] = k; + } + + public void getKsiazki() { + for(int i = 0; i < ksiazkiIndex; i++) { + ksiazki[i].opis(); + } + } + + public void getKlienci() { + for(int i = 0; i < klienciIndex; i++) { + System.out.println(klienci[i].getImieNazwisko()); + } + } +} diff --git a/src/Kwadrat.java b/src/Kwadrat.java new file mode 100644 index 0000000..b20da63 --- /dev/null +++ b/src/Kwadrat.java @@ -0,0 +1,18 @@ +public class Kwadrat extends Prostokat { + public Kwadrat(double bok) { + super(bok, bok); + } + + public double getBok() { + return wys; + } + + public void setBok(double bok) { + wys = bok; + szer = bok; + } + + String opis(){ + return "Klasa Kwadrat. Kolor obiektu: " + kolor + ", bok " + szer; + } +} diff --git a/src/Main.java b/src/Main.java new file mode 100644 index 0000000..26924e9 --- /dev/null +++ b/src/Main.java @@ -0,0 +1,77 @@ +public class Main { + public static void main(String[] args) { + System.out.println("=== Zadanie 1 (punkty) ==="); + Punkt p1 = new Punkt(); + Punkt p2 = new Punkt(2, 3); + Punkt p3 = new Punkt(Math.PI, Math.E); + + System.out.println(p1.getX() + ", " + p1.getY()); + p1.setX(10); + p1.setY(20); + System.out.println(p1.getX() + ", " + p1.getY()); + + p2.opis(); + p2.zeruj(); + p2.opis(); + + p3.opis(); + p3.przesun(2, -1); + p3.opis(); + + Figura f1 = new Figura(); + Figura f2 = new Figura(p3); + Figura f3 = new Figura("czarny"); + + System.out.println(f1.opis()); + System.out.println(f3.getKolor()); + + Prostokat pr1 = new Prostokat(4, 6.5); + System.out.println(pr1.getPowierzchnia()); + + Trojkat t1 = new Trojkat(3.5, 6); + System.out.println(t1.podst + ", " + t1.wys); + + System.out.println(pr1.opis()); + pr1.przesun(3, 5); + System.out.println(pr1.opis()); + + Kwadrat k1 = new Kwadrat(4); + + System.out.println(k1.opis()); + System.out.println(pr1.opis()); + System.out.println(t1.opis()); + System.out.println(f1.opis()); + + Okrag o1 = new Okrag(p3, 5); + + System.out.println(o1.opis()); + + + System.out.println("=== Zadanie 2 (samochody) ==="); + SamochodOsobowy s1 = new SamochodOsobowy(); + Samochod s2 = new Samochod(); + Samochod citroen = new Samochod("Citroen", "C2", "E477F56BA1", "srebrny", 2004, 245000); + + s1.opis(); + s2.opis(); + citroen.opis(); + + + System.out.println("=== Zadanie 3 (kompozycja) ==="); + Ksiegarnia ks = new Ksiegarnia(); + ks.addKlient("Stefan", "Stefanowski"); + Klient k = new Klient("Zdzichu", "Zdzichowski"); + ks.addKlient(k); + + Ksiazka ks1 = new Ksiazka("9780786222728", "Harry Potter and the Philosopher's Stone", "J. K. Rowling", 1997); + Powiesc ks2 = new Powiesc("9780545229937", "The Hunger Games", "Suzanne Collins", 2009, "fantastyka"); + Podrecznik ks3 = new Podrecznik("1234567890123", "Wczoraj i dzis", "Stefan Zdzichowski", 2012, "historia", 2023); + + ks.addKsiazka(ks1); + ks.addKsiazka(ks2); + ks.addKsiazka(ks3); + + ks.getKsiazki(); + ks.getKlienci(); + } +} \ No newline at end of file diff --git a/src/Okrag.java b/src/Okrag.java new file mode 100644 index 0000000..90b7fe7 --- /dev/null +++ b/src/Okrag.java @@ -0,0 +1,42 @@ +public class Okrag extends Figura { + double promien; + + public Okrag(Punkt srodek, double promien) { + this.punkt = srodek; + this.promien = promien; + } + + public Okrag() { + punkt = new Punkt(); + promien = 0; + } + + public double getPowierzchnia() { + return Math.PI * Math.pow(promien, 2); + } + + public double getSrednica() { + return 2 * Math.PI * promien; + } + + public void setPromien(double p) { + if(p < 0) throw new IllegalArgumentException("Promien musi byc liczba dodatnia"); + promien = p; + } + + public double getPromien() { + return promien; + } + + public boolean wSrodku(Punkt p) { + if(p.x > promien || p.y > promien) return false; + double tempX = Math.pow(p.x - punkt.x, 2); + double tempY = Math.pow(p.y - punkt.y, 2); + if(tempX + tempY <= Math.pow(promien, 2)) return true; + return false; + } + + String opis(){ + return "Klasa Okrag. Kolor obiektu: " + kolor + ", srodek " + punkt.getX() + ", " + punkt.getY() + ", promien " + getPromien(); + } +} diff --git a/src/Podrecznik.java b/src/Podrecznik.java new file mode 100644 index 0000000..796cb3d --- /dev/null +++ b/src/Podrecznik.java @@ -0,0 +1,15 @@ +public class Podrecznik extends Ksiazka { + String przedmiot; + int rocznik; + + public Podrecznik(String isbn, String tytul, String autor, int rokWydania, String przedmiot, int rocznik) { + super(isbn, tytul, autor, rokWydania); + this.przedmiot = przedmiot; + this.rocznik = rocznik; + } + + public void opis() { + super.opis(); + System.out.println("Przedmiot " + przedmiot + " dla rocznika " + rocznik); + } +} diff --git a/src/Powiesc.java b/src/Powiesc.java new file mode 100644 index 0000000..c71a7be --- /dev/null +++ b/src/Powiesc.java @@ -0,0 +1,13 @@ +public class Powiesc extends Ksiazka { + String gatunek; + + public Powiesc(String isbn, String tytul, String autor, int rokWydania, String gatunek) { + super(isbn, tytul, autor, rokWydania); + this.gatunek = gatunek; + } + + public void opis() { + super.opis(); + System.out.println("Gatunek" + gatunek); + } +} diff --git a/src/Prostokat.java b/src/Prostokat.java new file mode 100644 index 0000000..ad0de68 --- /dev/null +++ b/src/Prostokat.java @@ -0,0 +1,28 @@ +class Prostokat extends Figura { + double wys=0, szer=0; + + Prostokat(double wys,double szer){ + super(); + this.wys = wys; + this.szer = szer; + } + + public Prostokat(double wys, double szer, String kolor) { + super(kolor); + this.wys = wys; + this.szer = szer; + } + + double getPowierzchnia() { + return (szer * wys); + } + + public void przesun(int x, int y) { + szer += x; + wys += y; + } + + String opis(){ + return "Klasa Prostokat. Kolor obiektu: " + kolor + ", wysokosc " + wys + ", szerokosc " + szer; + } +} \ No newline at end of file diff --git a/src/Punkt.java b/src/Punkt.java new file mode 100644 index 0000000..91e4c9b --- /dev/null +++ b/src/Punkt.java @@ -0,0 +1,43 @@ +public class Punkt { + public double x, y; + + public Punkt() { + x = 0; + y = 0; + } + + public Punkt(double x, double y) { + this.x = x; + this.y = y; + } + + public double getX() { + return x; + } + + public void setX(double x) { + this.x = x; + } + + public double getY() { + return y; + } + + public void setY(double y) { + this.y = y; + } + + public void zeruj() { + x = 0; + y = 0; + } + + public void opis() { + System.out.println("Punkt (" + x + ", " + y + ")"); + } + + public void przesun(double x, double y) { + this.x += x; + this.y += y; + } +} diff --git a/src/Samochod.java b/src/Samochod.java new file mode 100644 index 0000000..eb6289d --- /dev/null +++ b/src/Samochod.java @@ -0,0 +1,42 @@ +import java.util.Scanner; + +public class Samochod { + String marka, model, nadwozie, kolor; + int rokProdukcji, przebieg; + + public Samochod() { + Scanner scanner = new Scanner(System.in); + System.out.print("Marka: "); + marka = scanner.next(); + System.out.print("Model: "); + model = scanner.next(); + System.out.print("Nadwozie: "); + nadwozie = scanner.next(); + System.out.print("Kolor: "); + kolor = scanner.next(); + System.out.print("Rok produkcji: "); + rokProdukcji = scanner.nextInt(); + System.out.print("Przebieg: "); + przebieg = scanner.nextInt(); + if(przebieg < 0) throw new IllegalArgumentException("Przebieg nie moze byc ujemny"); + } + + public Samochod(String marka, String model, String nadwozie, String kolor, int rokProdukcji, int przebieg) { + this.marka = marka; + this.model = model; + this.nadwozie = nadwozie; + this.kolor = kolor; + this.rokProdukcji = rokProdukcji; + this.przebieg = przebieg; + } + + public void opis() { + System.out.println("Samochod marki " + marka); + System.out.println("Model " + model); + System.out.println("Nadwozie " + nadwozie); + System.out.println("Kolor " + kolor); + System.out.println("Rok produkcji " + rokProdukcji); + System.out.println("Przebieg " + przebieg); + System.out.println(); + } +} diff --git a/src/SamochodOsobowy.java b/src/SamochodOsobowy.java new file mode 100644 index 0000000..8805721 --- /dev/null +++ b/src/SamochodOsobowy.java @@ -0,0 +1,32 @@ +import java.util.Scanner; + +public class SamochodOsobowy extends Samochod { + double waga, pojemnoscSilnika; + int iloscOsob; + + public SamochodOsobowy() { + super(); + Scanner scanner = new Scanner(System.in); + System.out.print("Waga: "); + waga = scanner.nextDouble(); + if(waga < 2 || waga > 4.5) throw new IllegalArgumentException("Waga musi byc w przedziale 2-4.5"); + System.out.print("Pojemnosc silnika: "); + pojemnoscSilnika = scanner.nextDouble(); + if(pojemnoscSilnika < 0.8 || pojemnoscSilnika > 3) throw new IllegalArgumentException("Pojemnosc silnika musi byc w przedziale 0.8-3.0"); + System.out.print("Ilosc osob: "); + iloscOsob = scanner.nextInt(); + } + + public void opis() { + System.out.println("Samochod osobowy marki " + marka); + System.out.println("Model " + model); + System.out.println("Nadwozie " + nadwozie); + System.out.println("Kolor " + kolor); + System.out.println("Rok produkcji " + rokProdukcji); + System.out.println("Przebieg " + przebieg); + System.out.println("Waga " + waga + " t"); + System.out.println("Pojemnosc silnika " + pojemnoscSilnika + " cc"); + System.out.println("Ilosc osob " + iloscOsob); + System.out.println(); + } +} diff --git a/src/Trojkat.java b/src/Trojkat.java new file mode 100644 index 0000000..f5b7fbd --- /dev/null +++ b/src/Trojkat.java @@ -0,0 +1,19 @@ +class Trojkat extends Figura { + double wys=0, podst=0; + + Trojkat(double wys, double podst) { + super(); + this.wys = wys; + this.podst = podst; + } + + public Trojkat(double wys, double podst, String kolor) { + super(kolor); + this.wys = wys; + this.podst = podst; + } + + String opis(){ + return "Klasa Trojkat. Kolor obiektu: " + kolor + ", wysokosc " + wys + ", podstawa " + podst; + } +} \ No newline at end of file