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);
}
}
boxofsnacks 0 Newbie Poster
NormR1 563 Posting Sage Team Colleague
boxofsnacks 0 Newbie Poster
NormR1 563 Posting Sage Team Colleague
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.