Hi! Newbie on Java. I'm doing this assignment for a cash register program. Our professor just explained what we're gonna do and stuff. Here's what i understood:
1.)Sales report (my code appears on the first diag box)
Product ID Product Name Quantity Price
2 Stuff 100
3 Stuff 100
4 Stuff 100
5 Stuff 100
2.)Prompt the user to enter product ID and quantity needed. ex:
ID: 2
Quantity needed: 5
3.)Present the new sales report. ex:
Product ID Product Name Quantity Price
2 Stuff 95
3 Stuff 100
4 Stuff 100
Here's what i've done so far:
import javax.swing.*;
public class products {
public static void main(String [] args) {
//FORMAT FOR DISPLAY AREA
JTextArea Display = new JTextArea(20,30);
JScrollPane Display2 = new JScrollPane(Display);
JTextArea Prods = new JTextArea(5,10);
//VARIABLES FOR INPUT ONLY
int id;
int qty;
Prods.setText("Product ID\t Product Name\t Product Qty.\t Product Price\n 1\t Nido\t 100\t 68.50\n 2\t Milo\t 100\t 50.50\n 3\t Coke\t 100\t 48.80\n 4\t Sprite\t 100\t 48.80\n 5\t Royal\t 100\t 48.80");
JOptionPane.showMessageDialog(null, Prods);
id=Integer.parseInt(JOptionPane.showInputDialog("Enter Product ID:"));
qty=Integer.parseInt(JOptionPane.showInputDialog("Enter Product Quantity:"));
switch(id){
case 1: int a,nido=100;
a=nido-qty;
Display.setText("Product ID\t " + "Product Name\t" + "Product Qty.\t" + "Product Price\n" + "1" + "\t Nido" + "\t"+a + "\t68.50");
JOptionPane.showMessageDialog(null, Display);
break;
case 2: int b, milo=100;
b=milo-qty;
Display.setText("Product ID\t " + "Product Name\t" + "Product Qty.\t" + "Product Price\n" + "2" + "\t Milo" + "\t"+b + "\t50.50");
JOptionPane.showMessageDialog(null, Display);
break;
case 3: int c,coke=100;
c=coke-qty;
Display.setText("Product ID\t " + "Product Name\t" + "Product Qty.\t" + "Product Price\n" + "3" + "\t Coke" + "\t"+c + "\t48.80");
JOptionPane.showMessageDialog(null, Display);
break;
case 4: int d,sprite=100;
d=sprite-qty;
Display.setText("Product ID\t " + "Product Name\t" + "Product Qty.\t" + "Product Price\n" + "4" + "\t Sprite" + "\t"+d + "\t48.80");
JOptionPane.showMessageDialog(null, Display);
break;
case 5: int e, royal=100;
e=royal-qty;
Display.setText("Product ID\t " + "Product Name\t" + "Product Qty.\t" + "Product Price\n" + "5" + "\t Royal" + "\t"+e + "\t48.80");
JOptionPane.showMessageDialog(null, Display);
break;
}
}
}
Here are my problems:
1.) How do i go back to the product ID input and quantity selection? (i know how to do that on c. but java has a different way i think?) (also, i'm planning to do a yes/no dialog box option but i dont know how.)
2.) How do i print the whole sales report? because it just prints 1 item in the sales report?