3
My goal is to deposit in several notes (10, 20, 50 and 100).
For this, in the method main
left so:
static Scanner lerInfo = new Scanner(System.in);
public static void main(String[] args) {
int nOpc = 0;
while (nOpc != 9) {
System.out.println("Opções: ");
System.out.println("1-Depósito");
System.out.println("2-Saque");
System.out.println("3-Extrato");
System.out.println("9-Sair");
System.out.println("Qual opção deseja?");
nOpc = lerInfo.nextInt();
if (nOpc == 1) {
Deposito deposito = new Deposito();
System.out.println("Informe a quantidade de cédulas de CEM para Depósito: ");
deposito.setQtdCem(lerInfo.nextInt());
deposito.setTotalCem(lerInfo.nextInt()*100);
System.out.println("Informe a quantidade de cédulas de CINQUENTA para Depósito: ");
deposito.setQtdCinq(lerInfo.nextInt());
deposito.setTotalCinq(lerInfo.nextInt()*50);
System.out.println("Informe a quantidade de cédulas de VINTE para Depósito: ");
deposito.setQtdVinte(lerInfo.nextInt());
deposito.setTotalVinte(lerInfo.nextInt()*20);
System.out.println("Informe a quantidade de cédulas de DEZ para Depósito: ");
deposito.setQtdDez(lerInfo.nextInt());
deposito.setTotalDez(lerInfo.nextInt()*10);
// deposito.setTotalNoCaixa(deposito.getTotalCem()+deposito.getTotalCinq()+deposito.getTotalVinte()+deposito.getTotalDez());
// System.out.println(deposito.getTotalNoCaixa());
}
if (nOpc == 2) {
Saque();
}
if (nOpc == 3) {
// ImprimeExtrato();
}
if (nOpc == 9) {
return;
}
}
And in class Deposito
, left so:
package model;
public class Deposito {
private int qtdCem;
private int qtdCinq;
private int qtdVinte;
private int qtdDez;
private int totalCem;
private int totalCinq;
private int totalVinte;
private int totalDez;
private int totalNoCaixa;
public int getQtdCem() {
return qtdCem;
}
public void setQtdCem(int qtdCem) {
this.qtdCem = qtdCem;
}
public int getQtdCinq() {
return qtdCinq;
}
public void setQtdCinq(int qtdCinq) {
this.qtdCinq = qtdCinq;
}
public int getQtdVinte() {
return qtdVinte;
}
public void setQtdVinte(int qtdVinte) {
this.qtdVinte = qtdVinte;
}
public int getQtdDez() {
return qtdDez;
}
public void setQtdDez(int qtdDez) {
this.qtdDez = qtdDez;
}
public int getTotalCem() {
return totalCem;
}
public void setTotalCem(int totalCem) {
this.totalCem = totalCem;
}
public int getTotalCinq() {
return totalCinq;
}
public void setTotalCinq(int totalCinq) {
this.totalCinq = totalCinq;
}
public int getTotalVinte() {
return totalVinte;
}
public void setTotalVinte(int totalVinte) {
this.totalVinte = totalVinte;
}
public int getTotalDez() {
return totalDez;
}
public void setTotalDez(int totalDez) {
this.totalDez = totalDez;
}
public int getTotalNoCaixa() {
return totalNoCaixa;
}
public void setTotalNoCaixa(int totalNoCaixa) {
this.totalNoCaixa = totalNoCaixa;
}
}
My problem occurs (checked through debug) when I do the first set
:
deposito.setQtdCem(lerInfo.nextInt());
Here the system is stopped, locked, in an infinite loop. Could you please assist me where I’m going wrong? No error message or anything, just stays in the loop.
The function
nextInt()
should be waiting for an entry (whole, in case). Wouldn’t that be it? TheScanner
is waiting for input...– Leonardo Alves Machado
Sorry, had not copied this line: Static Scanner lerInfo = new Scanner(System.in); It is just a variable that receives the input.
– Victor Freidinger
Buddy, Scanner is waiting for an entrance. If you don’t type anything, just stand there. That’s not what you’re seeing?
– Leonardo Alves Machado
But I’m typing, Leonardo.
– Victor Freidinger
I added the locking moment: Options: 1-Deposit 2-Loot 3-Extract 9-Quit What option do you want? 1 Enter the amount of CEM banknotes for Deposit: 7 ** And it is locked here.
– Victor Freidinger
When you type 9, get out of the loop?
– Leonardo Alves Machado
But in that case, shouldn’t you go to the next println? If I use in the same way, not being called via external class (all within the same class), it will be a beauty.
– Victor Freidinger
Yes, when I type 9 out of the loop.
– Victor Freidinger
Where are the implementation of methods: setTotalCem(), setTotalCinq(), setTotalVinte(), setTotalDez() class Deposit?
– RXSD
They are all within the same Deposit. I did not add here because the class would be too big. But, I will change to improve.
– Victor Freidinger
@Victorfreidinger, when typing the desired number your breakpoint is still stopped in the line of the set() method or simply it disappears?
– RXSD