In the following code I need to enter two car identifiers per Scanner
and show me which is the car that has traveled the most kilometers.
How could it be done?
import java.util.Scanner;
public class Pruebas {
public static void main(String[] args) {
Scanner teclado = new Scanner(System.in);
Coches coche = new Coches();
// Se almacenan un numero máximo de coches (4), una vez introducidos 4 coches avisa al usuario de que no se pueden agregar más coches.
Coches array [] = new Coches [4];
int contador = 0;
if (contador < array.length) {
System.out.println("Introduce el identificador del coche : ");
int identificador;
int kilometros;
System.out.print("Identificador :");
identificador = teclado.nextInt();
System.out.print("Kilometros :");
kilometros = teclado.nextInt();
coche = new Coches(identificador,kilometros);
array [contador] = coche;
contador++;
System.out.print("Coche dado de alta");
System.out.println();
}else{
System.out.print("Se ha alcanzado el maximo de coches");
}
// Comparar coches: el usuario introducirá dos identificadores de coches y se mostrará el coche que haya recorrido más kilometros.
//EDIT
// Comparar dos coches introduciendo sus identificadores.
System.out.print("Introduzca el primer identificador :");
System.out.print("Introduzca el segundo identificador :");
}
}