I am creating an application where each user has their respective profile. These profiles are stored in a ArrayList
. I have problems when creating a method to find registered or present users in ArrayList
and I have to do it with 2 parameters Nombre
and Apellido
.
I have the following class:
import java.util.*;
public class Profilo {
static String Nombre;
static String Apellido;
String Intereses;
boolean visible;
//contructor
public Profilo(String nombre, String apellido,String intereses,
boolean visibilidad) {
this.Nombre= nombre;
this.Apellido= apellido;
this.Intereses= intereses;
this.visible = visibilidad;
}
public String getNombre() {
return this.Nome;
}
public String getApellido() {
return this.Cognome;
}
And another class that will contain the methods to login, register and search for users:
import java.util.ArrayList;
import java.util.Scanner;
public class PerfilManager {
static ArrayList<Profilo> Users = new ArrayList();
static Scanner sc = new Scanner(System.in);
public static void Login() {
//codigo
}
public static void Registrarse() {
//codigo
}
public static void InizializaDati(){
String nombre;
String apellido;
String intereses;
boolean visibile;
System.out.println("nombre:");
nombre= sc.next();
System.out.println("apellido:");
apellido = sc.next();
System.out.println("intereses:");
intereses= sc.next();
System.out.println("visible?(true/false)");
visibile = sc.nextBoolean();
Perfil perfil= new Perfil(nombre,apellido,intereses,visibile);
Users.add(perfil);
System.out.println("peril creado!");
ShowPerfil();
}
public static void BuscaPerfil(String nome , String cognome) {
for(int i = 0 ; i < Users.size();i++) {
if(Users.get(i).visibile != false) {
//muestra perfil
} else {
System.out.println("Este perfil es privado");
}
}
}
}