Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Flugzeug {
- // Attribute
- private double tankvolumen, fuellstand, reserve, verbrauch;
- // Konstruktor
- Flugzeug(double tankvolumen, double fuellstand, double reserve, double verbrauch) {
- this.tankvolumen = tankvolumen;
- this.fuellstand = fuellstand;
- this.reserve = reserve;
- this.verbrauch = verbrauch;
- }
- // Methoden
- double fuellstandOhneReserve() {
- return fuellstand - reserve;
- }
- double verbrauch() {
- return verbrauch;
- }
- void tanken(double nachfuellvolumen) {
- if (nachfuellvolumen >= 0)
- fuellstand += nachfuellvolumen;
- if (fuellstand > tankvolumen)
- fuellstand = tankvolumen;
- }
- int verbrauchen(double verbraucht) {
- if (verbraucht >= 0)
- fuellstand -= verbraucht;
- if (fuellstand < 0)
- fuellstand = 0;
- if (fuellstand >= reserve)
- return 2;
- else if (fuellstand > 0)
- return 1;
- else
- return 0;
- }
- double reichweite() {
- double reichweite = (fuellstand - reserve) / verbrauch;
- if (reichweite < 0)
- return 0;
- else return reichweite;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement