commit 933b83b3929cb65fbb0b869d66446eda23d70288 Author: Aelita4 Date: Tue Nov 22 09:23:46 2022 +0100 Lab 6 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..583d6bb --- /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..09826e5 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1669100848325 + + + + + + + \ No newline at end of file diff --git a/Lab6.iml b/Lab6.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/Lab6.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/Adres.java b/src/Adres.java new file mode 100644 index 0000000..85c3cf7 --- /dev/null +++ b/src/Adres.java @@ -0,0 +1,22 @@ +public class Adres { + String ulica; + int numerDomu; + String kodPocztowy; + String miasto; + + public Adres(String ulica, int numerDomu, String kodPocztowy, String miasto) throws NieprawidlowyAdresException { + String errs = ""; + + if(ulica == null) errs += "Ulica nie moze byc nullem"; + if(numerDomu <= 0) errs += "Numer domu nie moze byc mniejszy lub rowny 0"; + if(kodPocztowy == null) errs += "Kod pocztowy nie moze byc nullem"; + if(miasto == null) errs += "Miasto nie moze byc nullem"; + + if(errs.length() > 0) throw new NieprawidlowyAdresException(errs); + + this.ulica = ulica; + this.numerDomu = numerDomu; + this.kodPocztowy = kodPocztowy; + this.miasto = miasto; + } +} diff --git a/src/BlednaWartoscDlaSilniException.java b/src/BlednaWartoscDlaSilniException.java new file mode 100644 index 0000000..ca4901f --- /dev/null +++ b/src/BlednaWartoscDlaSilniException.java @@ -0,0 +1,3 @@ +public class BlednaWartoscDlaSilniException extends Exception { + +} diff --git a/src/Main.java b/src/Main.java new file mode 100644 index 0000000..76160c2 --- /dev/null +++ b/src/Main.java @@ -0,0 +1,65 @@ +import transport.*; +import zwierzeta.Ryba; +import zwierzeta.Wieloryb; + +import java.util.InputMismatchException; +import java.util.Scanner; + +public class Main { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + + System.out.println("=== Zadanie 1 (transport) ==="); + Hugokopter h = new Hugokopter(); + h.lec(); + Lodz l = new Lodz(); + l.plyn(); + Samolot a = new Samolot(); + a.lec(); + Statek s = new Statek(); + s.plyn(); + + + System.out.println("=== Zadanie 2 (zwierzeta) ==="); + Wieloryb w = new Wieloryb(); + System.out.println(w.gatunek); + w.wynurz(); + w.zanurz(); + w.jedz(); + w.plyn(); + w.wydalaj(); + + + System.out.println("=== Zadanie 3 (sqrt exception) ==="); + float f1; + try { + f1 = scanner.nextFloat(); + } catch (InputMismatchException e) { + System.out.println("Input is not a float"); + return; + } + if(f1 < 0) throw new IllegalArgumentException("Bledna wartosc pierwiastka"); + System.out.println(Math.sqrt(f1)); + + + System.out.println("=== Zadanie 4 (silnia exception) ==="); + int x = scanner.nextInt(); + try { + if (x < 0) throw new BlednaWartoscDlaSilniException(); + } catch(BlednaWartoscDlaSilniException e) { + System.out.println("Bledna wartosc silnii"); + } + + + System.out.println("=== Zadanie 5 (adres exception) ==="); + String ulica = scanner.next(); + int numerDomu = scanner.nextInt(); + String kodPocztowy = scanner.next(); + String miasto = scanner.next(); + try { + Adres a = new Adres(ulica, numerDomu, kodPocztowy, miasto); + } catch(NieprawidlowyAdresException e) { + System.out.println(e.getMessage()); + } + } +} \ No newline at end of file diff --git a/src/NieprawidlowyAdresException.java b/src/NieprawidlowyAdresException.java new file mode 100644 index 0000000..f5a95d7 --- /dev/null +++ b/src/NieprawidlowyAdresException.java @@ -0,0 +1,5 @@ +public class NieprawidlowyAdresException extends Exception { + public NieprawidlowyAdresException(String message) { + super(message); + } +} diff --git a/src/transport/Hugokopter.java b/src/transport/Hugokopter.java new file mode 100644 index 0000000..a77aa9d --- /dev/null +++ b/src/transport/Hugokopter.java @@ -0,0 +1,7 @@ +package transport; + +public class Hugokopter implements Lata { + public void lec() { + System.out.println("Hugokopter gotowy do akcji"); + } +} diff --git a/src/transport/Lata.java b/src/transport/Lata.java new file mode 100644 index 0000000..f93532b --- /dev/null +++ b/src/transport/Lata.java @@ -0,0 +1,5 @@ +package transport; + +public interface Lata { + void lec(); +} diff --git a/src/transport/Lodz.java b/src/transport/Lodz.java new file mode 100644 index 0000000..bc2a861 --- /dev/null +++ b/src/transport/Lodz.java @@ -0,0 +1,7 @@ +package transport; + +public class Lodz implements Plywa { + public void plyn() { + System.out.println("Lodz plynie"); + } +} diff --git a/src/transport/Plywa.java b/src/transport/Plywa.java new file mode 100644 index 0000000..8619a04 --- /dev/null +++ b/src/transport/Plywa.java @@ -0,0 +1,5 @@ +package transport; + +public interface Plywa { + void plyn(); +} diff --git a/src/transport/Samolot.java b/src/transport/Samolot.java new file mode 100644 index 0000000..ec79422 --- /dev/null +++ b/src/transport/Samolot.java @@ -0,0 +1,7 @@ +package transport; + +public class Samolot implements Lata { + public void lec() { + System.out.println("Samolot leci"); + } +} diff --git a/src/transport/Statek.java b/src/transport/Statek.java new file mode 100644 index 0000000..ed2b55f --- /dev/null +++ b/src/transport/Statek.java @@ -0,0 +1,7 @@ +package transport; + +public class Statek implements Plywa { + public void plyn() { + System.out.println("Statek plynie"); + } +} diff --git a/src/zwierzeta/Latanie.java b/src/zwierzeta/Latanie.java new file mode 100644 index 0000000..95e7df2 --- /dev/null +++ b/src/zwierzeta/Latanie.java @@ -0,0 +1,6 @@ +package zwierzeta; + +public interface Latanie { + void lec(); + void wyladuj(); +} diff --git a/src/zwierzeta/Plywanie.java b/src/zwierzeta/Plywanie.java new file mode 100644 index 0000000..fc43739 --- /dev/null +++ b/src/zwierzeta/Plywanie.java @@ -0,0 +1,7 @@ +package zwierzeta; + +public interface Plywanie { + void plyn(); + void wynurz(); + void zanurz(); +} diff --git a/src/zwierzeta/Ryba.java b/src/zwierzeta/Ryba.java new file mode 100644 index 0000000..72cac3f --- /dev/null +++ b/src/zwierzeta/Ryba.java @@ -0,0 +1,28 @@ +package zwierzeta; + +public abstract class Ryba extends Zwierze { + String gatunek = "rybus pospolitus"; + + @Override + public void plyn() { + System.out.println("Ryba plynie"); + } + + @Override + public void wynurz() { + System.out.println("Ryba sie wynurza"); + } + + @Override + public void zanurz() { + System.out.println("Ryba sie zanurza"); + } + + public void jedz() { + System.out.println("Ryba je"); + } + + public void wydalaj() { + System.out.println("Ryba wydala"); + } +} diff --git a/src/zwierzeta/Wieloryb.java b/src/zwierzeta/Wieloryb.java new file mode 100644 index 0000000..c051e7c --- /dev/null +++ b/src/zwierzeta/Wieloryb.java @@ -0,0 +1,13 @@ +package zwierzeta; + +public class Wieloryb extends Ryba { + public String gatunek = "wielorybus pospolitus"; + + public void lec() { + + } + + public void wyladuj() { + + } +} diff --git a/src/zwierzeta/Zwierze.java b/src/zwierzeta/Zwierze.java new file mode 100644 index 0000000..1dac35f --- /dev/null +++ b/src/zwierzeta/Zwierze.java @@ -0,0 +1,5 @@ +package zwierzeta; + +public abstract class Zwierze implements Plywanie, Latanie { + String gatunek; +}