Ubgrade 16.12

master
David 2022-12-16 12:52:49 +01:00
parent c930514042
commit 81c97ace26
6 changed files with 29 additions and 3 deletions

View File

@ -13,4 +13,7 @@ public class Auto extends Fahrzeug
protected Auto(int m){
super(m,4);
}
public String toString(){
return "Das Auto fährt aktuell " + Geschwindigkeit + "km/h und hat schon ein Strecke von "+Position+ " zurückgelegt";
}
}

View File

@ -10,4 +10,7 @@ public class Fahrrad extends Fahrzeug
public Fahrrad(){
super(30,2);
}
public String toString(){
return "Das Fahrrad fährt aktuell " + Geschwindigkeit + "km/h und hat schon ein Strecke von "+Position+ " zurückgelegt";
}
}

View File

@ -7,8 +7,8 @@
*/
public class Fahrzeug
{
private int Position;
private double Geschwindigkeit;
protected int Position;
protected double Geschwindigkeit;
private int Maximal;
private int Räder;

View File

@ -19,4 +19,7 @@ public class Krankenwagen extends Auto
public void BlaulichtAus(){
Blaulicht = false;
}
public String toString(){
return "Der Krankenwagen fährt aktuell " + Geschwindigkeit + "km/h und hat schon ein Strecke von "+Position+ " zurückgelegt";
}
}

View File

@ -11,4 +11,7 @@ public class Rennwagen extends Auto
super(220);
}
public String toString(){
return "Der Rennwagen fährt aktuell " + Geschwindigkeit + "km/h und hat schon ein Strecke von "+Position+ " zurückgelegt";
}
}

View File

@ -22,9 +22,23 @@ public class Wettrennen
for(int i = 0; i<arr.length; i++){
arr[i].bewege(60);
}
for(int i = 0; i < arr.length; i++ ){
for(int i = 0; i<arr.length; i++){
if(arr[i] instanceof Fahrrad ){
System.out.println("Objekt "+i+" ist ein Fahrrad.");
}
else if(arr[i] instanceof Krankenwagen){
System.out.println("Objekt "+i+" ist ein Krankenwagen.");
}
else if(arr[i] instanceof Rennwagen ){
System.out.println("Objekt "+i+" ist ein Rennwagen.");
}
else if(arr[i] instanceof Auto ){
System.out.println("Objekt "+i+" ist ein Auto.");
}
System.out.println(arr[i]);
}
}
}