1
Every time I try to create a objeto.add(); and put the attribute in it, it continue to give me an error. See my code:
public class Agencia {
private String nome;
private String endr;
Set<Conta> listaContas = new HashSet<Conta>();
private int nrAgencia;
public Agencia(int pNrAgencia, String pNome, String pEndr){
this.setNome(pNome);
this.setEndr(pEndr);
this.setNrAgencia(pNrAgencia);
//AQUI ESTA
//O Netbens me informa que ha um erro, e não consigo resolver
listaContas.add(pNrAgencia);
}
//Outra Classe
public class Conta {
Conta(int pnrConta, double pSaldo, Agencia agencia,Pessoa ptitular){
System.out.println("Nome:");
ptitular.setNome(scan.nextLine());
System.out.println("Endereço:");
ptitular.setEndr(scan.nextLine());
this.setNrConta(pnrConta);
this.setSaldo(pSaldo);
//Agencia
System.out.println("Informe o numero da agencia");
agencia.setNrAgencia(scan.nextInt());
}
public Conta() {
}
listaContasis aSet<Conta>, then you can only add instances ofContain it. You tried to addpNrAgencia, which is aint(and not aConta), therefore the mistake.– hkotsubo
in case I will instantiate the account class, inside the hashset ?
– Vitor
You create a
Contaand then adds her to theHashSet– hkotsubo
it has as to make a small simple example, because I did it and gave error, it may be that I am not understanding.
– Vitor