Results 1 to 4 of 4
  1. #1
    JR2010 is offline Member
    Join Date
    Apr 2011
    Posts
    15
    Rep Power
    0

    Default 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.

    Java 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

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    You should be using your other classes with this class, that is your Product class and your Inventory class (if you have on).

  3. #3
    JR2010 is offline Member
    Join Date
    Apr 2011
    Posts
    15
    Rep Power
    0

    Default I am confused by classes

    I don't know how to make another class or how to get them to work together. My teacher won't help me with that either. I have asked three times and all he tells me is to read the book. The book doesn't help me. Do I make another file? If so, how do I get them to work together? I am really confused and have been searching the internet for weeks and still can not get the answer. Is what I have the way it should be, then create another file to track everything and yet another file to compute the results and display them?

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by JR2010 View Post
    I don't know how to make another class or how to get them to work together.
    Based on your other posts, you should already have the other class(es).


    My teacher won't help me with that either. I have asked three times and all he tells me is to read the book. The book doesn't help me.
    Keep at it, as you need to understand the basics for us to be able to help you. I find that I learn complex subjects best when I study multiple sources including several books and online tutorials. As with most other complex subjects, you get better at it with practice.

Similar Threads

  1. Help starting an assingment
    By LeslieMJ in forum New To Java
    Replies: 20
    Last Post: 03-29-2011, 01:46 PM
  2. Starting Out...
    By maknib in forum Java Gaming
    Replies: 1
    Last Post: 11-11-2010, 08:15 PM
  3. Help with starting program please
    By SF163 in forum New To Java
    Replies: 5
    Last Post: 11-07-2009, 03:33 PM
  4. Starting with Databasing
    By DavidG24 in forum JDBC
    Replies: 3
    Last Post: 09-13-2009, 08:51 AM
  5. just starting
    By specbailey in forum New To Java
    Replies: 23
    Last Post: 08-13-2007, 11:25 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •