Advertisement
Guest User

Untitled

a guest
Feb 17th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class QueCocheMeCompro {
  4.  
  5. public static void main(String[] args) {
  6.  
  7. LinkedList <Coche> listaCoches = new LinkedList<>();
  8.  
  9. Coche c1 = new Coche("Skoda", "Kodiaq 2.0 TDI 150 CV", 194, 463, 540, 220, 1, 31500, Diesel, Automático);
  10. Coche c2 = new Coche("Nissan", "X-TRAIL DIG-T 163 CV", 182, 469, 550, 135, 3, 25500, Gasolina, Manual);
  11. Coche c3 = new Coche("Sangyong", "Rodius D22T 178 CV", 191, 513, 870, 180, 2, 27100, Diesel, Manual);
  12. Coche c4 = new Coche("Citroen", "Grand C4 Picasso 1.6 BlueHDI 120 CV", 182, 460, 645, 170, 2, 24600, Diesel, Manual);
  13. Coche c5 = new Coche("Toyota", "Prius 1.8 HSD 136 CV", 177, 464, 505, 200, 1, 23990, Híbrido, Automático);
  14.  
  15. listaCoches.add(c1);
  16. listaCoches.add(c2);
  17. listaCoches.add(c3);
  18. listaCoches.add(c4);
  19. listaCoches.add(c5);
  20.  
  21. Scanner teclado = new Scanner(System.in);
  22.  
  23. System.out.println("Introduce el ancho de la plaza de garaje");
  24. int anchoCochera = teclado.nextInt();
  25. System.out.println("Introduce el largo de la plaza de garaje");
  26. int largoCochera = teclado.nextInt();
  27. System.out.println("Introduce el precio máximo del coche");
  28. float precio = teclado.nextFloat();
  29.  
  30. System.out.println("Lista con todos los coches");
  31. mostrarTodos(listacoches);
  32. System.out.println("Lista con los coches válidos");
  33. mostrarTodos(cochesValidos);
  34. }
  35.  
  36. public static void mostrarTodos(LinkedList <Coche> 1) {
  37.  
  38. for (Coche c: 1) {
  39. System.out.println(c);
  40. }
  41.  
  42. }
  43.  
  44. public static LinkedList <Coche> cochesValidos(LinkedList <Coche> 1, int anchoCochera, int largoCochera, float precio) {
  45.  
  46. LinkedList <Coche> Valido = new LinkedList<>();
  47.  
  48. for (Coche c: 1) {
  49. if (c.esValido(anchoCochera, largoCochera, precio)) {
  50. Valido.add(c);
  51. }
  52. }
  53.  
  54. return Valido;
  55.  
  56. }
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement