Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class QueCocheMeCompro {
- public static void main(String[] args) {
- LinkedList <Coche> listaCoches = new LinkedList<>();
- Coche c1 = new Coche("Skoda", "Kodiaq 2.0 TDI 150 CV", 194, 463, 540, 220, 1, 31500, Diesel, Automático);
- Coche c2 = new Coche("Nissan", "X-TRAIL DIG-T 163 CV", 182, 469, 550, 135, 3, 25500, Gasolina, Manual);
- Coche c3 = new Coche("Sangyong", "Rodius D22T 178 CV", 191, 513, 870, 180, 2, 27100, Diesel, Manual);
- Coche c4 = new Coche("Citroen", "Grand C4 Picasso 1.6 BlueHDI 120 CV", 182, 460, 645, 170, 2, 24600, Diesel, Manual);
- Coche c5 = new Coche("Toyota", "Prius 1.8 HSD 136 CV", 177, 464, 505, 200, 1, 23990, Híbrido, Automático);
- listaCoches.add(c1);
- listaCoches.add(c2);
- listaCoches.add(c3);
- listaCoches.add(c4);
- listaCoches.add(c5);
- Scanner teclado = new Scanner(System.in);
- System.out.println("Introduce el ancho de la plaza de garaje");
- int anchoCochera = teclado.nextInt();
- System.out.println("Introduce el largo de la plaza de garaje");
- int largoCochera = teclado.nextInt();
- System.out.println("Introduce el precio máximo del coche");
- float precio = teclado.nextFloat();
- System.out.println("Lista con todos los coches");
- mostrarTodos(listacoches);
- System.out.println("Lista con los coches válidos");
- mostrarTodos(cochesValidos);
- }
- public static void mostrarTodos(LinkedList <Coche> 1) {
- for (Coche c: 1) {
- System.out.println(c);
- }
- }
- public static LinkedList <Coche> cochesValidos(LinkedList <Coche> 1, int anchoCochera, int largoCochera, float precio) {
- LinkedList <Coche> Valido = new LinkedList<>();
- for (Coche c: 1) {
- if (c.esValido(anchoCochera, largoCochera, precio)) {
- Valido.add(c);
- }
- }
- return Valido;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement