import javax.swing.JOptionPane; // To get windows panels
public class RetailSales
{
public static void main (String [] args)
{
// name of strings
String OnlineSales = "Welcome to the online retailer choose"
+ "choose the items you want to purchase";
String MoreItemsToCalculate;
String ProductNumber;
// name of integers
int TotalSaleItems = 0;
int AmmountOfItems = 0;
// Name of doubles
double RetailTotal = 0.0; // Retail Total goes here
double Total = 0.0; // Total locally for switch
//Price for products
final double ProductOne = 2.98;
final double ProductTwo = 4.50;
final double ProductThree = 3.98;
final double ProductFour = 4.49;
final double ProductFive = 6.87;
// condition to while statement
MoreItemsToCalculate = JOptionPane.showInputDialog
("Welcome to our online retailer, are you ready to check out? ");
MoreItemsToCalculate = MoreItemsToCalculate.toUpperCase();
while (MoreItemsToCalculate.equals ("YES"))
{
ProductNumber = JOptionPane.showInputDialog
("Please select an item from the list \n" +
"Product 1, $2.98 \n" +
"Product 2, $4.50 \n" +
"Product 3, $3.98 \n" +
"Product 4, $4.49 \n" +
"Product 5, $6.87 \n");
// check if the user cancelled out of program
if (ProductNumber == null)
{
JOptionPane.showMessageDialog (null, "You have clicked on the cancel button, hope to see you soon.");
System.exit (0); // exits loop
}
// check if there the input is empty
else
if (ProductNumber == (""))
{
JOptionPane.showMessageDialog (null, "You must make an entry in the input box");
System.exit (0); // exits loop
}
// check if its a valid input type for product list
else
if (Integer.parseInt (ProductNumber) < 1 | Integer.parseInt (ProductNumber) > 5)
{
JOptionPane.showMessageDialog (null, ProductNumber + "Is not a valid product number, try again");
System.exit(0); // exits loop
}
// Switch satement only allows intergers to be used
switch(Integer.parseInt(ProductNumber))
{
case 1:
AmmountOfItems = Integer.parseInt(JOptionPane.showInputDialog
("How many of this Items do you have?" ));
Total = AmmountOfItems * ProductOne;
TotalSaleItems = AmmountOfItems; //keeps track of number of items
RetailTotal = Total; //keeps track of Retail Total
break;
case 2:
AmmountOfItems = Integer.parseInt(JOptionPane.showInputDialog
("How many of this Items do you have?" ));
Total = AmmountOfItems * ProductTwo;
TotalSaleItems = AmmountOfItems + TotalSaleItems;
RetailTotal = Total + RetailTotal;
break;
case 3:
AmmountOfItems = Integer.parseInt(JOptionPane.showInputDialog
("How many of this Items do you have?" ));
Total = AmmountOfItems * ProductThree;
TotalSaleItems = AmmountOfItems + TotalSaleItems;
RetailTotal = Total + RetailTotal;
break;
case 4:
AmmountOfItems = Integer.parseInt(JOptionPane.showInputDialog
("How many of this Items do you have?" ));
Total = AmmountOfItems * ProductFour;
TotalSaleItems = AmmountOfItems + TotalSaleItems;
RetailTotal = Total + RetailTotal;
break;
case 5:
AmmountOfItems = Integer.parseInt(JOptionPane.showInputDialog
("How many of this Items do you have?" ));
Total = AmmountOfItems * ProductFive;
TotalSaleItems = AmmountOfItems + TotalSaleItems;
RetailTotal = Total + RetailTotal;
break;
default:
JOptionPane.showMessageDialog
(null, ProductNumber + "- is not a valid product number try again.");
} //end of switch statement
MoreItemsToCalculate = JOptionPane.showInputDialog ("Do you want to add any more items?" );
MoreItemsToCalculate = MoreItemsToCalculate.toUpperCase();
} //end of while statement
// displays the totals to screen
JOptionPane.showMessageDialog (null, "Thank you for shopping with us\n\n"+
"Total items: " + TotalSaleItems + "\n" +
"Total: " + RetailTotal +"\n");
System.exit(0); // exits loop
}// end of main method
}// end of RetailSales class
I always had a passion for the field of STEM (Science, Technology, Engineering, and Math) and I knew I wanted to do something to make a difference in the world. I just didn’t know where to start. I was an immigrant in a new country, grew up in a tough environment, and wasn’t sure how… Read More