Auf die Ül#tze Fertig Los
parent
111ad97e29
commit
0157f69fb2
19
Auto.java
19
Auto.java
|
@ -2,9 +2,18 @@
|
||||||
class Auto extends Fahrzeug
|
class Auto extends Fahrzeug
|
||||||
{
|
{
|
||||||
public Auto(){
|
public Auto(){
|
||||||
super(140, 4);
|
super(4);
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getMaxSpeed(){
|
||||||
|
return 140;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String toString(){
|
||||||
|
if (! (this instanceof Krankenwagen || this instanceof Rennwagen)){
|
||||||
|
return "Das Auto" + super.toString();
|
||||||
|
}
|
||||||
|
return super.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
protected Auto(double m ){
|
|
||||||
super (m, 4);
|
|
||||||
}
|
|
||||||
}
|
|
10
Fahrrad.java
10
Fahrrad.java
|
@ -2,7 +2,15 @@
|
||||||
public class Fahrrad extends Fahrzeug
|
public class Fahrrad extends Fahrzeug
|
||||||
{
|
{
|
||||||
public Fahrrad(){
|
public Fahrrad(){
|
||||||
super(30, 2);
|
super(2);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public double getMaxSpeed(){
|
||||||
|
return 30;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString(){
|
||||||
|
return "Das Fahrrad" + super.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,32 +1,36 @@
|
||||||
|
|
||||||
public class Fahrzeug
|
public abstract class Fahrzeug
|
||||||
{
|
{
|
||||||
private double position;
|
private double position;
|
||||||
private double speed;
|
private double speed;
|
||||||
private double max;
|
|
||||||
private int wheels;
|
private int wheels;
|
||||||
|
|
||||||
public void bewege( double time){
|
public void bewege( double time){
|
||||||
this.position += speed*time/60;
|
this.position += speed*time/60;
|
||||||
|
if (this instanceof Krankenwagen) {
|
||||||
|
System.out.println("TA-TÜ-TA-TAAAAAAA");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSpeed(double s ) {
|
public void setSpeed(double s) {
|
||||||
this.speed = s;
|
speed = s;
|
||||||
if (this.speed > this.max) this.speed = this.max;
|
if (this. speed > this.getMaxSpeed()) this.speed = this.getMaxSpeed();
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getMaxSpeed(){
|
public abstract double getMaxSpeed();
|
||||||
return this.max;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getWheelCount(){
|
public int getWheelCount(){
|
||||||
return this.wheels;
|
return this.wheels;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Fahrzeug(double m, int w){
|
public Fahrzeug(int w){
|
||||||
this.position = 0;
|
this.position = 0;
|
||||||
this.speed = 0;
|
this.speed = 0;
|
||||||
this.max = m;
|
|
||||||
this.wheels = w;
|
this.wheels = w;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String toString(){
|
||||||
|
return " fährt aktuell " + this.speed + "km/h und hat schon eine Strecke von " + this.position + " zurückgelegt";
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
public class Fahrzeugtest
|
||||||
|
{
|
||||||
|
public static void test(){
|
||||||
|
Fahrzeug[] f = new Fahrzeug[5];
|
||||||
|
f[0] = new Auto();
|
||||||
|
f[1] = new Rennwagen();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,11 +8,17 @@ public class Krankenwagen extends Auto
|
||||||
|
|
||||||
blaulicht = false;
|
blaulicht = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void turnOn()
|
public void turnOn()
|
||||||
{
|
{
|
||||||
blaulicht = true;
|
blaulicht = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void turnOff(){
|
public void turnOff(){
|
||||||
blaulicht = false;
|
blaulicht = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String toString(){
|
||||||
|
return "Der Krankenwagen" + super.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,9 +26,9 @@ public class Rennen
|
||||||
}
|
}
|
||||||
|
|
||||||
public void durchfuehren(){
|
public void durchfuehren(){
|
||||||
while (true){
|
/* while (true){
|
||||||
if
|
if
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,14 @@
|
||||||
public class Rennwagen extends Auto
|
public class Rennwagen extends Auto
|
||||||
{
|
{
|
||||||
public Rennwagen(){
|
public Rennwagen(){
|
||||||
super(220);
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getMaxSpeed(){
|
||||||
|
return 220;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString(){
|
||||||
|
return "Der Rennwagen" + super.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
import java.util.ArrayList;
|
||||||
|
public class Wettrennen
|
||||||
|
{
|
||||||
|
private ArrayList<Fahrzeug> Teilnehmer = new ArrayList<Fahrzeug>();
|
||||||
|
|
||||||
|
public void AufDiePlätze(){
|
||||||
|
Teilnehmer.add(new Fahrrad());
|
||||||
|
Teilnehmer.add(new Auto());
|
||||||
|
Teilnehmer.add(new Rennwagen());
|
||||||
|
Teilnehmer.add(new Krankenwagen());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Fertig(){
|
||||||
|
Teilnehmer.get(0).setSpeed(20);
|
||||||
|
Teilnehmer.get(1).setSpeed(150);
|
||||||
|
Teilnehmer.get(2).setSpeed(200);
|
||||||
|
Teilnehmer.get(3).setSpeed(80);
|
||||||
|
Teilnehmer.get(0).bewege(4*60);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Los(){
|
||||||
|
for (int i = 1; i < Teilnehmer.size() + 1 ; i++){
|
||||||
|
Teilnehmer.get(i - 1).bewege(60);
|
||||||
|
System.out.println(Teilnehmer.get(i - 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue