In the consultas()
method, how could you print the student's name and grades?
Until now, what it prints are memory addresses, and not the name and qualifications.
Note: The map that receives this method is a map that returns a method called darDeAlta()
which receives the data of a new student.
class Alumno {
private String nombre;
private int matricula;
private double calificaciones[];
Alumno(String nombre, int matricula, double calificaciones[]) {
this.calificaciones = calificaciones;
}
String getNombre() {
return nombre;
}
int getMat() {
return matricula;
}
double[] getCalif() {
return calificaciones;
}
void setCalif(double calif[]) {
calificaciones = calif;
}
}
public class Ejercicio {
Map<Integer, Alumno> alumnos = new TreeMap<>();
public Map darDeAlta() {
Scanner y = new Scanner(System.in);
//boolean b=false;
double d[] = new double[5];
System.out.println("Introduzca el nombre del estudiante");
String n = y.nextLine();
System.out.println("Introduzca su matricula (de 5 digitos)");
int m = y.nextInt();
System.out.println("Introduzca las calificaciones: \n");
for (int i = 0; i < 5; i++) {
System.out.println("Introduzca la calificacion");
d[i] = y.nextDouble();
}
if (alumnos.containsKey(m)) {
System.out.println("Esa matricula ya existe, ingrese otra matricula");
} else {
alumnos.put(m, new Alumno(n, m, d));
System.out.println("Se han dado de alta los datos :)");
System.out.println("Desea ingresar mas alumnos? \n");
String s = y.next();
//if (s.compareTo("si")==0 || s.compareTo("no")==0)
// b = true;
}
return alumnos;
}
public boolean consultas(Map alumnos) {
Scanner y = new Scanner(System.in);
boolean c;
System.out.println("Introduzca la matricula del estudiante a buscar");
int k = y.nextInt();
c = alumnos.containsKey(k);
if (c) {
System.out.println("Los datos son:\n" +"Nombre del alumno: "+ alumnos.get(k) + "Calificaciones: " + alumnos.values());
//System.out.println("Los datos son:\n" +"Nombre del alumno: "+ alumnos.get(k).getNombre() + "Calificaciones: " + al.getCalif());
} else {
System.out.println("El alumno no se encuentra");
}
return true;
}