master
3009594 2024-10-27 23:34:52 +01:00
parent 02bd3c3032
commit 3cd180c763
10 changed files with 285 additions and 9 deletions

View File

@ -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();
}
}

View File

@ -11,7 +11,8 @@ public class Student {
private String geburtstag; private String geburtstag;
private int id; 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(); super();
this.name = name; this.name = name;
this.vorname = vorname; this.vorname = vorname;
@ -93,6 +94,4 @@ public class Student {
+ ", tele=" + tele + ", adresse=" + adresse + ", geburtstag=" + geburtstag + ", id=" + id + "]"; + ", tele=" + tele + ", adresse=" + adresse + ", geburtstag=" + geburtstag + ", id=" + id + "]";
} }
} }

View File

@ -2,6 +2,7 @@ package Hashmap.Autovermietung;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map;
public class Hashmap { public class Hashmap {
@ -22,11 +23,11 @@ public class Hashmap {
public static void main(String[] args) { public static void main(String[] args) {
// Erstellen einer Instanz der Klasse HashMap // Erstellen einer Instanz der Klasse HashMap
HashMap<String, Integer> map = new HashMap<>(); Map<String, Integer> map = new HashMap<>();
// Hinzufügen von Einträgen in die HashMap // Hinzufügen von Einträgen in die HashMap
map.put("Apfel", 3); map.put("Apfel", 3);
map.put("Apfe", 3); map.put("Apfe", 4);
map.put("Banane", 5); map.put("Banane", 5);
map.put("Orange", 2); map.put("Orange", 2);
@ -60,6 +61,17 @@ public class Hashmap {
int größe = map.size(); int größe = map.size();
System.out.println("Größe der HashMap: " + größe); 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 // Leeren der HashMap
map.clear(); map.clear();
System.out.println("HashMap nach dem Leeren: " + map); System.out.println("HashMap nach dem Leeren: " + map);

View File

@ -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);
}

View File

@ -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");
}
}

View File

@ -1,6 +1,7 @@
package VorlesungsFolien.Grundlagen_OOP; package VorlesungsFolien.Grundlagen_OOP;
import java.util.ArrayList; import java.util.ArrayList;
public class Gebäude { public class Gebäude {
private ArrayList<Hörsaal> räume = new ArrayList<>(); private ArrayList<Hörsaal> räume = new ArrayList<>();

View File

@ -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;
}
}
}

View File

@ -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");
}
}

View File

@ -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");
}
}

View File

@ -0,0 +1,30 @@
package oop.Abstraction.Zoo;
import java.util.ArrayList;
public class ZooMain {
public static void main(String[] args) throws Exception {
ArrayList<Animal> 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());
}
}