Necesito ayuda para Hacer los métodos con la clase Scanner
Publicado por Jose Luis (3 intervenciones) el 04/06/2019 00:50:47
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
protected SortedMap<Equipo, List<Jugador>> puntuaciones;
public Eurocopa(String nombreFichero) throws IOException {
puntuaciones = new TreeMap<Equipo, List<Jugador>>();
leerPuntuaciones(nombreFichero);
}
private void leerPuntuaciones(String nombreFichero) throws IOException {
BufferedReader br = new BufferedReader(new FileReader(nombreFichero));
leer(br);
br.close();
}
private void leer(BufferedReader br) throws IOException {
String lineaEquipo = br.readLine();
while (lineaEquipo != null) {
procesarEquipo(lineaEquipo, br);
lineaEquipo = br.readLine();
}
}
private void procesarEquipo(String lineaEquipo, BufferedReader br)
throws IOException {
StringTokenizer st = new StringTokenizer(lineaEquipo, " ");
try {
String nombre = st.nextToken();
int votos = Integer.parseInt(st.nextToken());
int numeroJugadores = Integer.parseInt(st.nextToken());
Equipo equipo = new Equipo(nombre, votos);
procesarJugadores(equipo, numeroJugadores, br);
} catch (NoSuchElementException e) {
throw new EurocopaException("Faltan datos de equipo");
} catch (NumberFormatException e) {
throw new EurocopaException("Formato incorrecto en datos de equipo");
}
}
private void procesarJugadores(Equipo eq, int numeroJugadores,
BufferedReader br) throws IOException {
List<Jugador> listaJugadores = new ArrayList<Jugador>();
for (int cont = 0; cont < numeroJugadores; cont++) {
String lineaJugador = br.readLine();
StringTokenizer st = new StringTokenizer(lineaJugador, " ");
try {
String nombre = st.nextToken();
String demarcacion = st.nextToken();
int valoracion = Integer.parseInt(st.nextToken());
Jugador j = new Jugador(nombre, demarcacion, valoracion);
listaJugadores.add(j);
} catch (NoSuchElementException e) {
throw new EurocopaException("Faltan datos de jugador");
} catch (NumberFormatException e) {
throw new EurocopaException(
"Formato incorrecto en datos de jugador");
}
}
puntuaciones.put(eq, listaJugadores);
}
Valora esta pregunta


0