I have a problem with a JAVA exercise, I can not fix it, although I'm pretty sure it's pretty simple. It's a simple crud:
Below is the main code
import java.util.Scanner;
public class Crud{
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
int max = 4;
Conta conta[] = new Conta[max];
Conta c = new Conta();
int op;
int indice = 0;
do{
System.out.println("1 - criar conta");
System.out.println("2 - consultar conta");
System.out.println("7 - sair");
System.out.print("escolha: ");
op = scan.nextInt();
switch(op){
case 1:
if(indice < max){
c = new Conta();
System.out.println("Número da conta: ");
String num = scan.nextLine();
c.setNumero(num);
scan.nextLine();
System.out.println("Saldo: ");
double saldo = scan.nextDouble();
c.setSaldo(saldo);
conta[indice] = c;
indice++;
}else{
System.out.println("");
System.out.println("Número limite total de contas atingido!");
System.out.println("");
}
break;
case 2:
if(indice >= 0){
System.out.print("Digite o número da conta por favor: ");
String busca = scan.nextLine();
scan.nextLine();
for(int i = 0; i <= indice; i++){
if(busca.equals(conta[i].getNumero())){
int achou = i;
System.out.println("número - " + conta[achou].getNumero());
System.out.println("saldo - " + conta[achou].getSaldo());
}
}
}else{
System.out.println("");
System.out.println("Nenhuma conta cadastrada no momento...");
System.out.println("");
}
break;
default:
System.out.println("Opção inválida");
}
}while(op != 7);
}
}
Here is the code for the Account class:
public class Conta{
private String numero;
private double saldo;
public String getNumero(){
return numero;
}
public void setNumero(String numero){
this.numero = numero;
}
public double getSaldo(){
return saldo;
}
public void setSaldo(double saldo){
this.saldo = saldo;
}
}
I can not show the account number only the balance and I can not get the account by the number that is option 2.