public class Nota {
int Valor ;
int Contador;
public static void main(String[] args) {
ArrayList<Nota> Cedulas = new ArrayList<Nota>();
Nota Notade1 = new Nota();
Cedulas.add(Notade1);
Notade1.Valor = 1;
Notade1.Contador = 0;
Nota Notade2 = new Nota();
Cedulas.add(Notade2);
Notade2.Valor = 2;
Notade2.Contador = 0;
Nota Notade5 = new Nota();
Cedulas.add(Notade5);
Notade5.Valor = 5;
Notade5.Contador = 0;
Nota Notade10 = new Nota();
Cedulas.add(Notade10);
Notade10.Valor = 10;
Notade10.Contador = 0;
Nota Notade20 = new Nota();
Cedulas.add(Notade20);
Notade20.Valor = 20;
Notade20.Contador = 0;
Nota Notade50 = new Nota();
Cedulas.add(Notade50);
Notade50.Valor = 50;
Notade50.Contador = 0;
Nota Notade100 = new Nota();
Cedulas.add(Notade100);
Notade100.Valor = 100;
Notade100.Contador = 0;
int ValorTotal = 0;
JOptionPane.showInputDialog(" Digite o valor a ser sacado ", ValorTotal);
for (int indice = 0; indice < Cedulas.size(); indice++) {
while (Notade100.Valor >= ValorTotal ){
ValorTotal = ValorTotal - Notade100.Valor;
Notade100.Contador = Notade100.Contador++;
}
while (Notade50.Valor >= ValorTotal ){
ValorTotal = ValorTotal - Notade50.Valor;
Notade50.Contador = Notade50.Contador++;
}
while (Notade20.Valor >= ValorTotal ){
ValorTotal = ValorTotal - Notade20.Valor;
Notade20.Contador = Notade20.Contador++;
}
while (Notade10.Valor >= ValorTotal ){
ValorTotal = ValorTotal - Notade10.Valor;
Notade10.Contador = Notade10.Contador++;
}
while (Notade5.Valor >= ValorTotal ){
ValorTotal = ValorTotal - Notade5.Valor;
Notade5.Contador = Notade5.Contador++;
}
while (Notade2.Valor >= ValorTotal ){
ValorTotal = ValorTotal - Notade2.Valor;
Notade2.Contador = Notade2.Contador++;
}
while (Notade1.Valor >= ValorTotal ){
ValorTotal = ValorTotal - Notade1.Valor;
Notade1.Contador = Notade1.Contador++;
}
}
JOptionPane.showMessageDialog(null,
" Notas de 1 : " + Notade1.Contador +
" Notas de 2 : " + Notade2.Contador +
" Notas de 5 : " + Notade5.Contador +
" Notas de 10 : " + Notade10.Contador +
" Notas de 20 : " + Notade20.Contador +
" Notas de 50 : " + Notade50.Contador +
" Notas de 100 : " + Notade100.Contador);
}
}
A idéia seria um caixa eletronico para dispensar notas.
Tipo o valor colocado para retirada foi 200
ele daria
nota de 100 = 1
nota de 50 = 1
nota de 20 = 1
nota de 10 = 1
nota de 5 = 2
nota de 2 = 3
nota de 1 = 4
só que aparece tudo 0 as notas.
desculpem mais sou iniciante.