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

5 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?

make a print method which is being called after each transaction and prints the updated contents

to "go back", just put it all in a while loop, which checks whether or not the input you gave, is the input to terminate the application

i know how to do it. i just dont know how to do it in dialog form

if you have a gui you don't need to use a while, as long as the gui is opened, it will execute the proper method upon user interaction

Slavi: he doesn't have a GUI.
EarhawkPH: if you know how to do it, you know how to do it. whether you use a Scanner instance and the command prompt to get your input, or dialogboxes, doesn't change anything about how to implement it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.