0
I’m studying vectors in object orientation and decided to do a little program to put some things into practice.
It consists of making the record of n vectors that will be bank accounts with name, password, Account and balance. Using only the console as an interaction, they should be registered at positions on the vector separately each new conta(name,password,account,balance)
.
Soon after, one should ask for a kind of "log-in" which consists of name and password and both must pass a basic and rustic validation process, which would first see if the name typed in the part of log-in corresponds to an account registered in the vector and if the answer is true give the option to type the password, and the validation of this will be to see if the vector with the name chosen has the password registered also to which 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();
}
}
Here’s the problem, the compiler is not "respecting" the condition if(check = false){sysout("Nome inválido");}(...)
.
Regardless of what I do or type it gives as true
and already executes the sysout{("Password: );}
.
What’s wrong? What could I do to improve/change?