Advertisement
Guest User

Untitled

a guest
May 22nd, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. package misobjetos;
  2.  
  3. public class Auto {
  4. private String patente, estado = "Apagado";
  5. private float nivelCombustible;
  6. private int velocidad;
  7. private String transmision = "P";
  8. private float kilometraje;
  9.  
  10.  
  11. public boolean cargarCombustible(float litros){
  12. nivelCombustible += litros;
  13. return true;
  14. }
  15.  
  16. public boolean acelerar(){
  17. if(estado.equals("Encendido") &&
  18. nivelCombustible >= 0.3f && velocidad <= 215){
  19. velocidad += 5;
  20. nivelCombustible -= 0.3f;
  21. estado = "En marcha";
  22.  
  23. if(velocidad > 1){
  24. transmision = "D";
  25. }
  26. return true;
  27. }
  28. return false;
  29. }
  30.  
  31. public String getTransmision(){
  32. return transmision;
  33. }
  34.  
  35. public boolean encender(){
  36. if(estado.equalsIgnoreCase("Apagado")){
  37. estado = "Encendido";
  38. return true;
  39. }
  40. return false;
  41. }
  42.  
  43. public boolean frenar(){
  44. if (velocidad >= 5) {
  45. velocidad -= 5;
  46. if (velocidad == 0) {
  47. estado = "Encendido";
  48. transmision = "P";
  49. }
  50. }
  51. return true;
  52.  
  53. }
  54.  
  55. public float getKilometraje(){
  56. return kilometraje;
  57.  
  58. }
  59.  
  60.  
  61. public boolean apagar(){
  62. if (estado.equalsIgnoreCase("Encendido")) {
  63. estado = "Apagado";
  64. return true;
  65. }
  66.  
  67. return false;
  68.  
  69. }
  70.  
  71. public int getVelocidad(){
  72. return velocidad;
  73. }
  74.  
  75. public float getNivelCombustible(){
  76. return nivelCombustible;
  77. }
  78.  
  79. public String getEstado(){
  80. return estado;
  81. }
  82.  
  83. public String getPatente(){
  84. return patente;
  85. }
  86.  
  87. public void patente(String laPatente){
  88. patente = laPatente;
  89. }
  90.  
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement