0
I’m developing a system with Jframe from a pharmacy. It’s a college issue. In the cashier operator comes in with the quantity X of product that the customer chooses from a list of n products and then with the unit value of each product that is worth Y. At the end the system must show the total purchase value by multiplying X * Y = ?. This code is simple to do and using the terminal or I do it smoothly. An example of how I control the loop through the terminal.
while (n == 0){
System.out.printf("\nEscolha:\n\t1 - Inserir novo produto\n\t0 - Valor Total");
k = input.nextInt();
if(k == 1){
System.out.println("Quantidade de produtos: ");
//recebe
System.out.println("Valor unitário");
//recebe
valorFinal = valorFinal + (quantidade * valorUnitario);
}
if(k == 0){
//qualquer coisa
n++;
//interrompe o laço e imprime o valor
}
}
Using Jframe it does not work like this, because there is no way the user choose option 1 or 0. In this case I thought to create a [Add Product] button and every time it was clicked the seller would add the products and unit value and when it clicked the button [Final Value] the loop would be broken and the result would be shown.
int n = 0;
double valorFinal = 0;
while(n == 0){
resposta = JOptionPane.showConfirmDialog(null, "Cadastrar nova compra?");
if(resposta == JOptionPane.YES_OPTION){
double qtdIten = Double.valueOf(jTextField1.getText());
double valor = Double.valueOf(jTextField2.getText());
valorFinal = (valorFinal + (valor * qtdIten));
}
else{
jTextArea1.setText("Valor da compra: "+valorFinal);
n++;
}
}
In a very amateur way I made this attempt with a Joptionpane but it did not work.
a simple
break;
must solve– Pedro Martins
Without a [mcve] can’t see how your screen works. So I removed the Jframe tag because there’s nothing related to this in the question.
– user28595