Profissional prof = new Profissional(null, null);
List<Profissional> profissional = new ArrayList<Profissional>();
Scanner sc = new Scanner(System.in);
while(true) {
String comando = sc.next().toUpperCase();
if (comando.contentEquals("RP")) {
String categoriaPro = sc.next();
if(!categoriaPro.equals("Medicina")) {
System.out.println("Categoria inexistente");
}else if(!categoriaPro.equals("Enfermagem")) {
System.out.println("Categoria inexistente");
}else if(!categoriaPro.equals("Auxiliar")) {
System.out.println("Categoria inexistente");
}
String nomePro = sc.next();
prof.NomeVerificacao(profissional , nomePro, categoriaPro);
}
if(comando.contentEquals("SAIR")) {
break;
}
}
for(Profissional pro : profissional) {
System.out.println(pro);
}
This is my main.
public class Profissional {
private String nome;
private String categoria;
public Profissional(String nome, String categoria) {
this.nome = nome;
this.categoria = categoria;
}
// getters and setter
public void NomeVerificacao(List<Profissional> profissional, String nome, String categoria) {
if (profissional.isEmpty() == true) {
profissional.add(new Profissional(nome, categoria));
} else {
int i = 0;
for (; i < profissional.size(); i++) {
if (profissional.get(i).nome.equals(nome)) {
System.out.println("Profissional existente.");
break;
}
}
if (i == profissional.size()) {
profissional.add(new Profissional(nome, categoria));
}
}
}
}
i'm trying to create Object, in this case is a professional of an hospital. What is done is that can't have more that one professional with the same name, but what i can't figure it out is how to restrict the value of "categoriaPro" to "Medicina", "Enfermagem" and "Auxiliar". And if it isn't one of them i print the messagem "Categoria inexistente". but it isn't working. can any body help??