From 3cd180c76348aeef77f5e7bede33fadc500e4df6 Mon Sep 17 00:00:00 2001 From: 3009594 Date: Sun, 27 Oct 2024 23:34:52 +0100 Subject: [PATCH] =?UTF-8?q?=C3=9Cbungen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BuilderPatter/Student.java | 71 +++++++++++++++++++ .../Domain/Student.java | 11 ++- .../src/Hashmap/Autovermietung/Hashmap.java | 18 ++++- .../src/Lambda/ÜbungenTestate.java | 71 +++++++++++++++++++ Programmierung2/src/Lambda/Übungtestate2.java | 28 ++++++++ .../Grundlagen_OOP/Gebäude.java | 1 + .../src/oop/Abstraction/Zoo/Animal.java | 38 ++++++++++ .../src/oop/Abstraction/Zoo/Cat.java | 13 ++++ .../src/oop/Abstraction/Zoo/Dog.java | 13 ++++ .../src/oop/Abstraction/Zoo/ZooMain.java | 30 ++++++++ 10 files changed, 285 insertions(+), 9 deletions(-) create mode 100644 Programmierung2/src/DesignPatterns/Erzeugungsmuster_CreationalPatterns/BuilderPatter/Student.java create mode 100644 Programmierung2/src/Lambda/ÜbungenTestate.java create mode 100644 Programmierung2/src/Lambda/Übungtestate2.java create mode 100644 Programmierung2/src/oop/Abstraction/Zoo/Animal.java create mode 100644 Programmierung2/src/oop/Abstraction/Zoo/Cat.java create mode 100644 Programmierung2/src/oop/Abstraction/Zoo/Dog.java create mode 100644 Programmierung2/src/oop/Abstraction/Zoo/ZooMain.java diff --git a/Programmierung2/src/DesignPatterns/Erzeugungsmuster_CreationalPatterns/BuilderPatter/Student.java b/Programmierung2/src/DesignPatterns/Erzeugungsmuster_CreationalPatterns/BuilderPatter/Student.java new file mode 100644 index 0000000..eb3e985 --- /dev/null +++ b/Programmierung2/src/DesignPatterns/Erzeugungsmuster_CreationalPatterns/BuilderPatter/Student.java @@ -0,0 +1,71 @@ +package DesignPatterns.Erzeugungsmuster_CreationalPatterns.BuilderPatter; + +public class Student { + + private String name; + private String vorname; + + public Student() { + + } + + private Student(BuildStu b) { + this.name = b.name; + this.vorname = b.vorname; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getVorname() { + return vorname; + } + + public void setVorname(String vorname) { + this.vorname = vorname; + } + + + + public static class BuildStu{ + private String name; + private String vorname; + + public BuildStu setname(String name) { + + this.name = name; + return this; + } + + public BuildStu setvorname(String vorname) { + + this.vorname = vorname; + return this; + } + + public Student builder() { + + return new Student(this); + } + + } + + public class Test{ + int i =2 ; + } + + public static void main(String[] args) { + int i = 2; + Student s = new Student.BuildStu() + .setname("obai") + .setvorname("omar") + .builder(); + + Student.Test test = new Student().new Test(); + } +} diff --git a/Programmierung2/src/GUIAnwendungen/StudentManagementSystem/Domain/Student.java b/Programmierung2/src/GUIAnwendungen/StudentManagementSystem/Domain/Student.java index 64abc13..15a7689 100644 --- a/Programmierung2/src/GUIAnwendungen/StudentManagementSystem/Domain/Student.java +++ b/Programmierung2/src/GUIAnwendungen/StudentManagementSystem/Domain/Student.java @@ -1,7 +1,7 @@ package GUIAnwendungen.StudentManagementSystem.Domain; public class Student { - + private String name; private String vorname; private String geschlecht; @@ -10,8 +10,9 @@ public class Student { private String adresse; private String geburtstag; private int id; - - public Student(String name, String vorname, String geschlecht, String email, String tele, String adresse,String geburtstag, int id) { + + public Student(String name, String vorname, String geschlecht, String email, String tele, String adresse, + String geburtstag, int id) { super(); this.name = name; this.vorname = vorname; @@ -92,7 +93,5 @@ public class Student { return "Student [name=" + name + ", vorname=" + vorname + ", geschlecht=" + geschlecht + ", email=" + email + ", tele=" + tele + ", adresse=" + adresse + ", geburtstag=" + geburtstag + ", id=" + id + "]"; } - - - + } diff --git a/Programmierung2/src/Hashmap/Autovermietung/Hashmap.java b/Programmierung2/src/Hashmap/Autovermietung/Hashmap.java index 1070829..01e1374 100644 --- a/Programmierung2/src/Hashmap/Autovermietung/Hashmap.java +++ b/Programmierung2/src/Hashmap/Autovermietung/Hashmap.java @@ -2,6 +2,7 @@ package Hashmap.Autovermietung; import java.util.HashMap; import java.util.LinkedHashMap; +import java.util.Map; public class Hashmap { @@ -22,11 +23,11 @@ public class Hashmap { public static void main(String[] args) { // Erstellen einer Instanz der Klasse HashMap - HashMap map = new HashMap<>(); + Map map = new HashMap<>(); // Hinzufügen von Einträgen in die HashMap map.put("Apfel", 3); - map.put("Apfe", 3); + map.put("Apfe", 4); map.put("Banane", 5); map.put("Orange", 2); @@ -59,7 +60,18 @@ public class Hashmap { // Erhalten der Größe der HashMap int größe = map.size(); System.out.println("Größe der HashMap: " + größe); - + + System.out.println(); + System.out.println("Values: "); + for (Integer s : map.values()) + System.out.println(s); + + + System.out.println(); + System.out.println("Keys: "); + for (String s : map.keySet()) + System.out.println(s); + // Leeren der HashMap map.clear(); System.out.println("HashMap nach dem Leeren: " + map); diff --git a/Programmierung2/src/Lambda/ÜbungenTestate.java b/Programmierung2/src/Lambda/ÜbungenTestate.java new file mode 100644 index 0000000..29eada4 --- /dev/null +++ b/Programmierung2/src/Lambda/ÜbungenTestate.java @@ -0,0 +1,71 @@ +package Lambda; + +public class ÜbungenTestate { + + public static void main(String[] args) { + +// check t = (a,b) -> a +b; +// +// int erg = t.sumOfTwoInt(12, 12); +// +// System.out.println(t.sumOfTwoInt(12, 12)); +// +// check t2 = new check(){ +// +// @Override +// public int sumOfTwoInt(int a, int b) { +// +// return a+b; +// } +// }; +// +// System.out.println(t2.sumOfTwoInt(12, 3)); + int f = 10; + int erg = test(12, 12,f, (a,b) -> a+b+f); + System.out.println(erg); + + + checkString st = s -> s.isEmpty(); + + System.out.println(st.checkifEmpty("das")); + + int f2 = add(12,a -> 12 ,12,b -> 12); + System.out.println(f2); + } + + public static int test(int a, int b,int f, check c) { + return c.sumOfTwoInt(a,b); + } + + public static int add(int Zahlx, zahlX x, int Zahly, zahlY y) { + int er1 = x.zx(Zahlx); + int er2 = y.zy(Zahly); + + return er1 + er2; + } + + +} + +interface check{ + + int sumOfTwoInt(int a, int b); +} + +interface checkString{ + + boolean checkifEmpty(String s); +} + + +interface zahlX{ + + int zx(int x); +} + +interface zahlY{ + + int zy(int y); +} + + diff --git a/Programmierung2/src/Lambda/Übungtestate2.java b/Programmierung2/src/Lambda/Übungtestate2.java new file mode 100644 index 0000000..0f77030 --- /dev/null +++ b/Programmierung2/src/Lambda/Übungtestate2.java @@ -0,0 +1,28 @@ +package Lambda; + +public class Übungtestate2 { + + public static void main(String[] args) { + + Test23 t = new Test23() { + + @Override + public void print () { + System.out.println("Annynom Innere Klasse"); + } + + + }; + t.print(); + } + + + +} + +class Test23 { + + public void print () { + System.out.println("Test"); + } +} diff --git a/Programmierung2/src/VorlesungsFolien/Grundlagen_OOP/Gebäude.java b/Programmierung2/src/VorlesungsFolien/Grundlagen_OOP/Gebäude.java index c627d12..2e388f0 100644 --- a/Programmierung2/src/VorlesungsFolien/Grundlagen_OOP/Gebäude.java +++ b/Programmierung2/src/VorlesungsFolien/Grundlagen_OOP/Gebäude.java @@ -1,6 +1,7 @@ package VorlesungsFolien.Grundlagen_OOP; import java.util.ArrayList; + public class Gebäude { private ArrayList räume = new ArrayList<>(); diff --git a/Programmierung2/src/oop/Abstraction/Zoo/Animal.java b/Programmierung2/src/oop/Abstraction/Zoo/Animal.java new file mode 100644 index 0000000..eaa4151 --- /dev/null +++ b/Programmierung2/src/oop/Abstraction/Zoo/Animal.java @@ -0,0 +1,38 @@ +package oop.Abstraction.Zoo; + + +public abstract class Animal { + private String name; + private int birthyear; + private String species; + + public Animal(String name, int birthyear) { + this.name = name; + this.birthyear = birthyear; + + species = this.getClass().getName(); + species = species.substring(species.lastIndexOf(".")+1); + } + + public abstract void speak(); + + public String getSpecies() { + return species; + } + + public static Animal tiereErzeugen(String nameTier) { + + switch(nameTier) { + case "Katze": + return new Cat(nameTier,12); + + case "Hund": + return new Dog(nameTier,12); + + default: + return null; + + } + } + +} diff --git a/Programmierung2/src/oop/Abstraction/Zoo/Cat.java b/Programmierung2/src/oop/Abstraction/Zoo/Cat.java new file mode 100644 index 0000000..9335137 --- /dev/null +++ b/Programmierung2/src/oop/Abstraction/Zoo/Cat.java @@ -0,0 +1,13 @@ +package oop.Abstraction.Zoo; +public class Cat extends Animal { + + public Cat(String name, int birthyear) { + super(name, birthyear); + } + + @Override + public void speak() { + System.out.println(super.getSpecies() + " macht: Meow"); + } + +} diff --git a/Programmierung2/src/oop/Abstraction/Zoo/Dog.java b/Programmierung2/src/oop/Abstraction/Zoo/Dog.java new file mode 100644 index 0000000..16d9f64 --- /dev/null +++ b/Programmierung2/src/oop/Abstraction/Zoo/Dog.java @@ -0,0 +1,13 @@ +package oop.Abstraction.Zoo; +public class Dog extends Animal { + + public Dog(String name, int birthyear) { + super(name, birthyear); + } + + @Override + public void speak() { + System.out.println(super.getSpecies() + " macht: Woof"); + } + +} diff --git a/Programmierung2/src/oop/Abstraction/Zoo/ZooMain.java b/Programmierung2/src/oop/Abstraction/Zoo/ZooMain.java new file mode 100644 index 0000000..d0055eb --- /dev/null +++ b/Programmierung2/src/oop/Abstraction/Zoo/ZooMain.java @@ -0,0 +1,30 @@ +package oop.Abstraction.Zoo; +import java.util.ArrayList; + +public class ZooMain { + + public static void main(String[] args) throws Exception { + ArrayList tiere = new ArrayList<>(); + +// // Animal a = new Animal("Animal", "1934"); // abstrakt, daher keine Instanzen möglich! +// +// Animal c = new Cat("Sylvester", 1947); +// c.speak(); +// +// Cat cat = (Cat) c; +// +// tiere.add(c); +// +// Animal d = new Dog("Spike", 1963); +// d.speak(); +// tiere.add(d); + + Animal t = Animal.tiereErzeugen("Hund"); + + System.out.println(t.toString()); + + System.out.println("Anzahl der Tiere im Zoo: " + tiere.size()); + + } + +}