import java.awt.*;
import java.text.NumberFormat;
import java.util.Locale;
import javax.swing.*;

public class SalesFigures

{   
   public static void main (String[]args)

    {
       float prod1 = 0, prod2 = 0, prod3 = 0;
        float prod4 = 0, prod5 = 0;

       String inputString;
        int prodId = 1;

        // Need user input to determine outcome

        while (prodId != 0) // While loop
        {
          inputString = JOptionPane.showInputDialog(
          "Enter product number (Enter 0 to stop):");
          prodId = Integer.parseInt(inputString);

          if (prodId >= 1 && prodId <= 5) // Determine total items sold
          {
           inputString = JOptionPane.showInputDialog(
            "Enter number of items sold:");
            int quantity = Integer.parseInt (inputString);

            switch (prodId)           // Switch used to add price * number of items sold
            {
             case 1:
                prod1 += quantity * 2.98;
                 break;

             case 2:
                prod2 += quantity * 4.50;
                 break;

             case 3:
                prod3 += quantity * 9.98;
                 break;

             case 4:
                prod4 += quantity * 4.49;
                 break;

             case 5:
                prod5 += quantity * 6.87;
                 break;
            }
          }

          else if ( prodId != 0) 
          {
             JOptionPane.showMessageDialog(null,
              "Product number must be 1-5 or 0 to stop",
              "Input Error", JOptionPane.INFORMATION_MESSAGE);
          }
         }

        NumberFormat moneyFormat = NumberFormat.getCurrencyInstance (Locale.US);

        String output = "Product 1:" + moneyFormat.format (prod1);
        output += "\nProduct 2:" + moneyFormat.format (prod2);
        output += "\nProduct 3:" + moneyFormat.format (prod3);
        output += "\nProduct 4:" + moneyFormat.format (prod4);
        output += "\nProduct 5:" + moneyFormat.format (prod5)+ "\n";

        JTextArea outputArea = new JTextArea (6, 20);
        outputArea.setText ( output);

        JOptionPane.showMessageDialog (null, outputArea,
        "Totals" , JOptionPane.INFORMATION_MESSAGE);

        System.exit (0);

     }
    }

Is there a question or problem?

Or are you just sharing some code?

I'm sorry I am asking how would I go about figuring out how to calculate and display the subtotal after each pair of inputs and total cost of all of the products...I have been looking in my textbook and online and can only get this far...Any help that can push me in the right direction is greatly appricated

Where in the code are the values that you need to add up to get the subtotals?
Can you define the input that is used to compute a subtotal?
Then given the subtotals how would you compute the total cost?

Can you explain in detail what is wrong with the posted code?

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.