This commit is contained in:
Your Name
2023-10-02 15:48:30 +02:00
parent 8bf2b012cb
commit 9a83c28137
26 changed files with 143 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
package P2;
public class A {
}

View File

@@ -0,0 +1,4 @@
package P2;
public class B extends A{
}

View File

@@ -0,0 +1,9 @@
package P2;
public class Brot extends Nahrungsmittel{
public Brot(){
super.setName("Brot");
super.setPreis(1f);
}
}

View File

@@ -0,0 +1,4 @@
package P2;
public class C extends A{
}

View File

@@ -0,0 +1,4 @@
package P2;
public class D extends A{
}

View File

@@ -0,0 +1,4 @@
package P2;
public class E {
}

View File

@@ -0,0 +1,20 @@
package P2;
public class Einkaufswagen<T> {
Nahrungsmittel[] produkte = new Nahrungsmittel[10];
int amount = 0;
void hinzufuegen(Nahrungsmittel produkt){
if (amount < 9){
produkte[amount++] = produkt;
}
else {
System.out.println("voller Lachs");
}
}
void ausgeben(){
for(int i = 0; i<amount;i++){
System.out.println(produkte[i].getName());
}
}
}

View File

@@ -0,0 +1,4 @@
package P2;
public class F {
}

View File

@@ -0,0 +1,5 @@
package P2;
public class MyGenericClass<T> {
// Inhalt der Klasse ist nicht wichtig
}

View File

@@ -0,0 +1,24 @@
package P2;
public abstract class Nahrungsmittel {
private String name;
private float preis;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public float getPreis() {
return preis;
}
public void setPreis(float preis) {
this.preis = preis;
}
}

View File

@@ -0,0 +1,11 @@
package P2;
public class Test {
public static void main(String[] args) {
var test= new MyGenericClass<A>();
testCreate(test);
}
static void testCreate(MyGenericClass<? super C> c ){
}
}

View File

@@ -0,0 +1,42 @@
package P2;
import java.util.Scanner;
public class Test2 <T,X>{
public static void main(String[] args) {
boolean end = false;
Scanner sc = new Scanner(System.in);
Einkaufswagen<? extends Nahrungsmittel> einkaufswagen = new Einkaufswagen();
while (!end) {
System.out.println("1: Brot");
System.out.println("2: Wurst");
System.out.println("3: Ausgeben");
System.out.println("4: handelsbuch(produkt, menge)");
System.out.println("5: Ende");
System.out.println("");
switch (sc.nextInt()) {
case 1:
einkaufswagen.hinzufuegen(new Brot());
break;
case 2:
einkaufswagen.hinzufuegen(new Wurst());
break;
case 3:
einkaufswagen.ausgeben();
break;
case 4:
case 5:
end = true;
break;
}
}
}
}

View File

@@ -0,0 +1,8 @@
package P2;
public class Wurst extends Nahrungsmittel{
public Wurst(){
super.setName("Wurst");
super.setPreis(1.1f);
}
}