Advertisement
Guest User

Untitled

a guest
Jan 21st, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. class Flugzeug {
  2.  
  3.  
  4. // Attribute
  5. private double tankvolumen, fuellstand, reserve, verbrauch;
  6.  
  7. // Konstruktor
  8. Flugzeug(double tankvolumen, double fuellstand, double reserve, double verbrauch) {
  9. this.tankvolumen = tankvolumen;
  10. this.fuellstand = fuellstand;
  11. this.reserve = reserve;
  12. this.verbrauch = verbrauch;
  13. }
  14.  
  15. // Methoden
  16. double fuellstandOhneReserve() {
  17. return fuellstand - reserve;
  18. }
  19.  
  20. double verbrauch() {
  21. return verbrauch;
  22. }
  23.  
  24. void tanken(double nachfuellvolumen) {
  25. if (nachfuellvolumen >= 0)
  26. fuellstand += nachfuellvolumen;
  27. if (fuellstand > tankvolumen)
  28. fuellstand = tankvolumen;
  29. }
  30.  
  31. int verbrauchen(double verbraucht) {
  32. if (verbraucht >= 0)
  33. fuellstand -= verbraucht;
  34. if (fuellstand < 0)
  35. fuellstand = 0;
  36.  
  37. if (fuellstand >= reserve)
  38. return 2;
  39. else if (fuellstand > 0)
  40. return 1;
  41. else
  42. return 0;
  43. }
  44.  
  45. double reichweite() {
  46. double reichweite = (fuellstand - reserve) / verbrauch;
  47. if (reichweite < 0)
  48. return 0;
  49. else return reichweite;
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement