Objektorientierung/Fahrzeug.java

37 lines
866 B
Java

public abstract class Fahrzeug
{
private double position;
private double speed;
private int wheels;
public void bewege( double time){
this.position += speed*time/60;
if (this instanceof Krankenwagen) {
System.out.println("TA-TÜ-TA-TAAAAAAA");
}
}
public void setSpeed(double s) {
speed = s;
if (this. speed > this.getMaxSpeed()) this.speed = this.getMaxSpeed();
}
public abstract double getMaxSpeed();
public int getWheelCount(){
return this.wheels;
}
public Fahrzeug(int w){
this.position = 0;
this.speed = 0;
this.wheels = w;
}
public String toString(){
return " fährt aktuell " + this.speed + "km/h und hat schon eine Strecke von " + this.position + " zurückgelegt";
}
}