Advertisement
Guest User

Untitled

a guest
Jan 29th, 2020
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1.  
  2. public class Motorino {
  3. private double Cilindrata;
  4. private boolean Acceso;
  5. private double Velocita;
  6. private double CapacitaSerbatoio;
  7. private double Carburante;
  8.  
  9. public Motorino() {
  10. this.Acceso = false;
  11. this.Velocita = 0.0;
  12. this.Cilindrata = 50.0;
  13. this.CapacitaSerbatoio = 10.0;
  14. this.Carburante = 10.0;
  15. }
  16.  
  17. public Motorino(int Cilindrata, double CapacitaSerbatoio, double Carburante) {
  18. this.Acceso = false;
  19. this.Velocita = 0;
  20. this.Cilindrata = Cilindrata;
  21. this.CapacitaSerbatoio = CapacitaSerbatoio;
  22. if (Carburante <= CapacitaSerbatoio) {
  23. this.Carburante = Carburante;
  24. }
  25. }
  26.  
  27. public void Accendi() {
  28. this.Acceso = true;
  29. }
  30.  
  31. public void Spegni() {
  32. this.Acceso = false;
  33. }
  34.  
  35. public boolean Accelera() {
  36. double VelocitaMassima = (this.Cilindrata / 100.0) * 110.0;
  37. double Delta = VelocitaMassima / 100; // 1% del massimo
  38. if (this.Velocita < VelocitaMassima) {
  39. this.Velocita += Delta;
  40. this.Consuma();
  41. return true;
  42. }
  43. return false;
  44. }
  45.  
  46. public boolean Frena() {
  47. double VelocitaMassima = (this.Cilindrata / 100.0) * 110.0;
  48. double Delta = (VelocitaMassima / 100.0) * 2.0; // 2% del massimo
  49. if (this.Velocita > 0) {
  50. this.Velocita -= Delta;
  51. return true;
  52. }
  53. return false;
  54. }
  55.  
  56. public boolean Consuma() {
  57. double Delta = (this.CapacitaSerbatoio / 100.0) * 2.0; // 2% del massimo
  58. if (this.Carburante > 0) {
  59. this.Carburante -= Delta;
  60. return true;
  61. }
  62. return false;
  63. }
  64.  
  65. public void Rifornisci(double Carburante) {
  66. if (Carburante + this.CapacitaSerbatoio <= this.CapacitaSerbatoio) {
  67. this.CapacitaSerbatoio += Carburante;
  68. }
  69. }
  70.  
  71. public double getCilindrata() {
  72. return Cilindrata;
  73. }
  74.  
  75. public void setCilindrata(int cilindrata) {
  76. Cilindrata = cilindrata;
  77. }
  78.  
  79. public boolean isAcceso() {
  80. return Acceso;
  81. }
  82.  
  83. public void setAcceso(boolean acceso) {
  84. Acceso = acceso;
  85. }
  86.  
  87. public double getVelocita() {
  88. return Velocita;
  89. }
  90.  
  91. public void setVelocita(double velocita) {
  92. Velocita = velocita;
  93. }
  94.  
  95. public double getCapacitaSerbatoio() {
  96. return CapacitaSerbatoio;
  97. }
  98.  
  99. public void setCapacitaSerbatoio(double capacitaSerbatoio) {
  100. CapacitaSerbatoio = capacitaSerbatoio;
  101. }
  102.  
  103. public double getCarburante() {
  104. return Carburante;
  105. }
  106.  
  107. public void setCarburante(double carburante) {
  108. Carburante = carburante;
  109. }
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement