Advertisement
Guest User

Untitled

a guest
Oct 24th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. //Atributos
  2. public Coche coche;
  3. public String AveriaAsociada;
  4. public int NumeroCoches;
  5.  
  6. //Método1
  7. public void aceptarCoche(Coche coche, String AveriaAsociada) {
  8. this.coche = coche;
  9. this.AveriaAsociada = AveriaAsociada;
  10.  
  11. //Atender un coche a cada momento
  12. if (NumeroCoches == 0) {
  13. System.out.println("Puede entrar un coche");
  14. } else {
  15. System.out.println("Garaje ocupado");
  16. }
  17.  
  18. //Acumular averias
  19. this.coche.acumularAveria(Math.random()*100);
  20. this.NumeroCoches = 1;
  21.  
  22. //Aumentar en 10 el aceite del motor
  23. if (AveriaAsociada.equals("Aceite")) {
  24. int Litrosdeaceite = coche.getMotor().getLitrosdeaceite();
  25. coche.getMotor().setLitrosdeaceite(Litrosdeaceite + 10);
  26. }
  27. }
  28.  
  29. //Método2
  30. public void devolverCoche() {
  31. this.NumeroCoches = 0;
  32. System.out.println("Coche devuelto");
  33. }
  34.  
  35. /**
  36. * @param args
  37. * @author Borja
  38. */
  39. public static void main(String[] args) {
  40.  
  41. Garaje garaje = new Garaje();
  42.  
  43. Coche coche1 = new Coche("Marca", "Modelo");
  44. Coche coche2 = new Coche("Marca", "Modelo");
  45.  
  46. garaje.aceptarCoche(coche1, "Averia1");
  47. garaje.devolverCoche();
  48.  
  49. garaje.aceptarCoche(coche2, "Averia2");
  50. garaje.devolverCoche();
  51.  
  52. garaje.aceptarCoche(coche1, "Aceite");
  53. garaje.devolverCoche();
  54.  
  55. garaje.aceptarCoche(coche2, "Aceite");
  56. garaje.devolverCoche();
  57.  
  58. System.out.println("Informacion coche: " + coche1.getMarca() + coche1.getModelo() + coche1.getAverias());
  59. System.out.println("Informacion coche: " + coche2.getMarca() + coche2.getModelo() + coche2.getAverias());
  60.  
  61.  
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement