El ejercicio pide que el metodo devuelva a los estudiantes que se encuentran dentro del ArrayList que tengan la misma 'carrera' que se recibe por parametro que es un String.
La clase Estudiante:
public class Estudiante {
private int dip;
private String nomb;
private String apel;
private int edad;
private String carrera;
private int tel;
private String email;
public Estudiante(int dip, String nombre, String apellido,int edad,
String carrera, int tel, String email)
{
this.dip = dip;
this.nomb = nombre;
this.apel = apellido;
this.edad = edad;
this.carrera = carrera;
this.tel =tel;
this.email = email;
}
public void mostrar()
{
System.out.println("Estudiante: "+getNomb()+" "+getApel()+
", "+getEdad()+" años, "+getTel()+", "+getEmail());
}
public int getDip() {
return dip;
}
public void setDip(int dip) {
this.dip = dip;
}
public String getNomb() {
return nomb;
}
public void setNomb(String nomb) {
this.nomb = nomb;
}
public String getApel() {
return apel;
}
public void setApel(String apel) {
this.apel = apel;
}
public int getEdad() {
return edad;
}
public void setEdad(int edad) {
this.edad = edad;
}
public String getCarrera() {
return carrera;
}
public void setCarrera(String carrera) {
this.carrera = carrera;
}
public int getTel() {
return tel;
}
public void setTel(int tel) {
this.tel = tel;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
El metodo a implementar es el siguiente. PD: este metodo pertenece a otra clase llamada DbUniversidad.
public ArrayList<Estudiante> listaEstudiantes(String carrera)
Esto es lo que he hecho:
public ArrayList<Estudiante> listaEstudiantes(String carrera)
{
for(Estudiante e : alum)
{
if(e.getCarrera().equals(carrera))
return alum;
}
Tengo problemas para saber como devolver el arraylist y que solo aparezcan la carrera que se a recibido por parametro. Gracias,