I'm studying object-oriented vectors and I've decided to do some programming to get things done.
It consists of registering n vectors that will be bank accounts with name, password, account and balance . Using only the console as an interaction, they should be registered in positions in the vector separately each% w / w%.
Next, you should ask for a " log-in" which consists of name and password and both must pass a basic and rustic validation process, which would first be to see if the name typed in the log-in part corresponds to an account registered in the vector and if the answer is true option to enter the password , and the validation of this will be to see if the vector with the name chosen has the password also registered to that the user typed in log-in .
package application;
import java.util.Locale;
import java.util.Scanner;
import entities.ContaBancaria;
public class ProgramContaBancaria {
public static void main(String[] args) {
Locale.setDefault(Locale.US);
Scanner sc = new Scanner(System.in);
System.out.print("Digite quantas contas serão cadastradas: ");
int quantidade = sc.nextInt();
ContaBancaria[] conta = new ContaBancaria[quantidade];
System.out.println();
for(int i = 0; i < conta.length; i++) {
int x = 1;
x += i;
System.out.println("Conta #"+ x);
System.out.print("Digite o nome da conta para cadastro: ");
String name = sc.next();
System.out.print("Digite a senha para cadastro: ");
int password = sc.nextInt();
System.out.print("Digite o número da conta para cadastro: ");
int account = sc.nextInt();
conta[i] = new ContaBancaria(name, password, account);
System.out.println();
}
System.out.println("Clientes cadastrados com sucesso!");
System.out.println();
System.out.println(" Login");
System.out.print("Name: ");
String name = sc.next();
boolean check = false;
for(int i = 0; i < conta.length; i++) {
if(conta[i].getName().equals(name) ) {
check = true;
}
else
check = false;
}
if (check = true) {
System.out.print("Password: ");
}
else if (check = false){
System.out.print("Nome inválido: ");
String name2 = sc.next();
name += name2;
}
int password = sc.nextInt();
}
}
So the problem is, the compiler is not "respecting" the new conta(name,password,account,balance)
condition.
Regardless of what I do or type it gives as if(check = false){sysout("Nome inválido");}(...)
and already executes true
.
What's wrong? What could I do to improve / change?