Starting to understand, but few problems I need advice on.
Ok, I am working on my inventory program that should allow the user to imput the product name, manufacturer, inventory number, quantity, and price. the program then needs to calculate the total of all the products in the inventory and the return fees of 5 % and then the grand total of the products plus the return fees. I have the basic code done and working, however, It only tracks one product, and the doubles do not turn out right in the end there should only be two numbers to the right of the desimal, but there is not. My questions are can someone give me a hint as to why the doubles are not perfoming correctly, and how do I track more than one item and have all those items display correctly. Sorry that is another problem I am having. When the system displays the results they are all in a line and don't look too appealing. Any tips to get them to display one item under the other? Thank you for all of your help and time. The code is below.
Code:
// this program tracks inventory
import javax.swing.JOptionPane; //program uses JOptionPane
/**
*
* @author Julie
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
boolean enterMoreData = true;
while(enterMoreData){
//obtain user input from JOptionPane input dialogs
//get product name
String productName =
JOptionPane.showInputDialog( "Please enter product Name.");
if (productName.equalsIgnoreCase("stop")) {
JOptionPane.showMessageDialog(null,"Good bye! Thank you for using inventory tracker.", "Good Bye", JOptionPane.PLAIN_MESSAGE);
System.exit(0);}
//get manufacturer
String productManufacturer =
JOptionPane.showInputDialog("Please enter the product Manufacturer.");
//get inventory number
String proNumber =
JOptionPane.showInputDialog("Please enter product inventory number");
int productNumber = Integer.parseInt(proNumber);//convert productNumber to integer
//get product quantity
String proQuantity =
JOptionPane.showInputDialog("Please enter the quantity of product in inventory.");
int productQuantity = Integer.parseInt( proQuantity);//convert product quantity to double.
if (productQuantity < 0)
{
JOptionPane.showMessageDialog(null,"You have entered a unusable number, please try again" + "Good Bye", "Neg. Number Entered", JOptionPane.PLAIN_MESSAGE);
System.exit(0); }
//Get product price
String proPrice =
JOptionPane.showInputDialog("Please enter the price of the product.");
double productPrice = Double.parseDouble(proPrice);//convert product price to double.
if (productPrice < 0)
{
JOptionPane.showMessageDialog(null, "You have entered a unusable number, please try again" + "Good Bye", "Neg. Number Entered", JOptionPane.PLAIN_MESSAGE);
System.exit(0); }
double total = (productPrice * productQuantity);
double restockingFee = ((productPrice * productQuantity)* 0.05);
double grandTotal = (restockingFee + total);
//display resutlts in a JOptionPane message dialog
JOptionPane.showMessageDialog(null, "The product name is:" + productName + "Product Manufacturer is: " + productManufacturer +
"Product inventory number is:" + productNumber,"General Product information",JOptionPane.PLAIN_MESSAGE);
JOptionPane.showMessageDialog(null, "The product price is: $ " + productPrice + "Total amount in inventory is: $"+ total
+ "Product restocking fee is: $"+ restockingFee + "Grand total of inventory, plus restocking fees is: $ " + grandTotal, "Product Totals", JOptionPane.INFORMATION_MESSAGE);
}//end while
}// class main
}// method main