a
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
package P2;
|
||||
|
||||
public class A {
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package P2;
|
||||
|
||||
public class B extends A{
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package P2;
|
||||
|
||||
public class Brot extends Nahrungsmittel{
|
||||
|
||||
public Brot(){
|
||||
super.setName("Brot");
|
||||
super.setPreis(1f);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package P2;
|
||||
|
||||
public class C extends A{
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package P2;
|
||||
|
||||
public class D extends A{
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package P2;
|
||||
|
||||
public class E {
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package P2;
|
||||
|
||||
public class F {
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package P2;
|
||||
|
||||
public class MyGenericClass<T> {
|
||||
// Inhalt der Klasse ist nicht wichtig
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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 ){
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package P2;
|
||||
|
||||
public class Wurst extends Nahrungsmittel{
|
||||
public Wurst(){
|
||||
super.setName("Wurst");
|
||||
super.setPreis(1.1f);
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user