Can't get my inventory program to compile

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • zaidalin79
    New Member
    • Nov 2006
    • 59

    Can't get my inventory program to compile

    I have a java class that goes for another week or so, and I am going to fail if I can't figure out this simple program. I can't get anything to compile to at least get a few points... Here are the assignments...

    4. CheckPoint: Inventory Program Part 1
    • Resource: Java: How to Program
    • Due Date: Day 5 [Individual] forum
    • Choose a product that lends itself to an inventory (for example, products at your
    workplace, office supplies, music CDs, DVD movies, or software).
    • Create a product class that holds the item number, the name of the product, the number
    of units in stock, and the price of each unit.
    • Create a Java application that displays the product number, the name of the product, the
    number of units in stock, the price of each unit, and the value of the inventory (the
    number of units in stock multiplied by the price of each unit). Pay attention to the good
    programming practices in the text to ensure your source code is readable and well
    documented.


    1. CheckPoint: Inventory Program Part 2
    • Resource: Java: How to Program
    • Due Date: Day 4 [Individual] forum
    • Modify the Inventory Program so the application can handle multiple items. Use an array
    to store the items. The output should display the information one product at a time,
    including the item number, the name of the product, the number of units in stock, the
    price of each unit, and the value of the inventory of that product. In addition, the output
    should display the value of the entire inventory.
    • Create a method to calculate the value of the entire inventory.
    • Create another method to sort the array items by the name of the product.


    2. CheckPoint: Inventory Program Part 3
    • Resource: Java: How to Program
    • Due Date: Day 7 [Individual] forum
    • Modify the Inventory Program by creating a subclass of the product class that uses one
    additional unique feature of the product you chose (for the DVDs subclass, you could use
    movie title, for example). In the subclass, create a method to calculate the value of the
    inventory of a product with the same name as the method previously created for the
    product class. The subclass method should also add a 5% restocking fee to the value of
    the inventory of that product.
    • Modify the output to display this additional feature you have chosen and the restocking
    fee.


    4. CheckPoint: Inventory Program Part 4
    • Resource: Java: How to Program
    • Due Date: Day 5 [Individual] forum
    • Modify the Inventory Program to use a GUI. The GUI should display the information one
    product at a time, including the item number, the name of the product, the number of
    units in stock, the price of each unit, and the value of the inventory of that product. In
    addition, the GUI should display the value of the entire inventory, the additional attribute,
    and the restocking fee.


    2. CheckPoint: Inventory Program Part 5
    • Resource: Java: How to Program
    • Due Date: Day 7 [Individual] forum
    • Modify the Inventory Program by adding a button to the GUI that allows the user to move
    to the first item, the previous item, the next item, and the last item in the inventory. If the
    first item is displayed and the user clicks on the Previous button, the last item should
    display. If the last item is displayed and the user clicks on the Next button, the first item
    should display.
    • Add a company logo to the GUI using Java graphics classes.

    Here is the last program that I was able to get to compile... I am supposed to remove the user input section, but no matter what I try, it doesn't work....

    [Program removed as per site rules - see FAQ]

    Pleeeease java geniuses... HELP!!! :)
    I can be reached at <email removed>
    Last edited by MMcCarthy; Feb 20 '07, 05:40 AM. Reason: removing program code
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Let's go one stage at a time then

    [Program removed as per site rules - see FAQ]

    Comment

    • horace1
      Recognized Expert Top Contributor
      • Nov 2006
      • 1510

      #3
      your print statements in main() are a mixture of C++ and Java, i.e. to print to the screen in Java you use System.out.prin tln() not System.out.prin tf()
      main() should look like
      Code:
      public class Inventory
      {
         // main methods begins execution of java application
         public static void main( String args[])
         {
               Supplies mySupplies = new Supplies();
      
               System.out.println("\n\nItem Name: "+mySupplies.getItemName()); //display item name
                       System.out.println("Item Number: "+mySupplies.getItemNumber()); //display item number
                       System.out.println("Quantity in Stock: "+mySupplies.getStockQuantity()); //display quantity in stock
                       System.out.println("Item Price:$ "+mySupplies.getItemPrice()); //display item price
                       System.out.println("Value of Inventory:$ "+mySupplies.calculateInventoryValue()); //display total value of inventory for this item
      
               System.out.println("\n\nEnter item name or enter the word stop to quit:");//prompt
                    //   mySupplies.setItemName(input.next()); // read item name or stop
      
      
         } // end main method
      }//end class Inventory
      when run it gives
      Item Name:
      Item Number: 0.0
      Quantity in Stock: 0.0
      Item Price:$ 0.0
      Value of Inventory:$ 0.0


      Enter item name or enter the word stop to quit:

      you now need to call setItemName(), setItemNumber() , etc to set up data in mySupplies

      Comment

      • zaidalin79
        New Member
        • Nov 2006
        • 59

        #4
        yes please and thank you... you are a life saver!!

        Comment

        • zaidalin79
          New Member
          • Nov 2006
          • 59

          #5
          Originally posted by r035198x
          Let's go one stage at a time then

          [Program removed as per site rules - see FAQ]
          This one worked beautifully... I guess I was sort of close... Thank you so much... what is the next step...?
          Last edited by MMcCarthy; Feb 20 '07, 05:39 AM. Reason: removing program code

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by horace1
            your print statements in main() are a mixture of C++ and Java, i.e. to print to the screen in Java you use System.out.prin tln() not System.out.prin tf()

            [code removed as per site rules - see FAQ]

            you now need to call setItemName(), setItemNumber() , etc to set up data in mySupplies
            printf is now available in java 1.5
            Last edited by MMcCarthy; Feb 20 '07, 06:16 AM. Reason: removing program code

            Comment

            • r035198x
              MVP
              • Sep 2006
              • 13225

              #7
              Originally posted by zaidalin79
              This one worked beautifully... I guess I was sort of close... Thank you so much... what is the next step...?
              Being close is the reason why it was easy to help you. Now have a look at this and make additions so that we can sort by name and test that functionality

              [Code removed as per site rules - see FAQ]

              Comment

              • zaidalin79
                New Member
                • Nov 2006
                • 59

                #8
                Where can I add the %.2f to get the currency to diplay two decimals?

                Comment

                • r035198x
                  MVP
                  • Sep 2006
                  • 13225

                  #9
                  Originally posted by zaidalin79
                  Where can I add the %.2f to get the currency to diplay two decimals?
                  Change this line
                  Code:
                  System.out.println("Total Value is"+s.getTotalValue());
                  to make it use printf instead of println.

                  Comment

                  • r035198x
                    MVP
                    • Sep 2006
                    • 13225

                    #10
                    Originally posted by r035198x
                    Change this line
                    Code:
                    System.out.println("Total Value is"+s.getTotalValue());
                    to make it use printf instead of println.
                    Remember Product is just a name I chose, you should change it to something that can be a superclass of some other object as per requirement in Part3

                    Comment

                    • zaidalin79
                      New Member
                      • Nov 2006
                      • 59

                      #11
                      I did this

                      Code:
                      System.out.printf("Total Value is: $%.2f\n"+s.getTotalValue());
                      and got this

                      $Exception in thread "main" java.util.Missi ngFormatArgumen tException: Format specifier '.2f'
                      at java.util.Forma tter.format(Unk nown Source)
                      at java.io.PrintSt ream.format(Unk nown Source)
                      at java.io.PrintSt ream.printf(Unk nown Source)
                      at Inventory2.main (Inventory2.jav a:153)

                      Comment

                      • zaidalin79
                        New Member
                        • Nov 2006
                        • 59

                        #12
                        Product works doesn't it? it is a list of products that are in stock...

                        Could I use something like a date recieved, or maybe who the product was ordered by for the subclass?

                        Comment

                        • r035198x
                          MVP
                          • Sep 2006
                          • 13225

                          #13
                          Originally posted by zaidalin79
                          Product works doesn't it? it is a list of products that are in stock...

                          Could I use something like a date recieved, or maybe who the product was ordered by for the subclass?
                          And what would you be calling that Subclass?
                          Usually beginners are encouraged to write their own sort functions and all that. Here is how you properly use the Arrays.sort method. Read and understand the need for the comparable interface (if you have not yet done interfaces then that's the price you pay for not writting your own sort function. I have to go in the next fifteen minutes so here is where we've got so far

                          [code removed as per site rules - see FAQ]

                          Comment

                          • zaidalin79
                            New Member
                            • Nov 2006
                            • 59

                            #14
                            No... I am sorry... I do want to write my own sort function... I thought that was how you did it... Should I take out the import of Array then?

                            Will you be back on when you could help me more? You have already taught me more than my teacher has during the whole class...

                            Comment

                            • r035198x
                              MVP
                              • Sep 2006
                              • 13225

                              #15
                              Originally posted by zaidalin79
                              No... I am sorry... I do want to write my own sort function... I thought that was how you did it... Should I take out the import of Array then?

                              Will you be back on when you could help me more? You have already taught me more than my teacher has during the whole class...
                              It's a bit arguable you know. Deepends on what your teacher wants too. You would learn more java by using Arrays.sort, IMO. It is how you would want to do it in practice. On the other hand, writing your own bubblesort (or even quicksort function) might be less efficient but will improve your knowledge of loops and arrays. I suggest you ask your teacher and try to understand the Array.sort route for now. At the end, when you get time, do it both ways and compare. It's the best way to learn. Yeah I'll be in about tomorrow (about 15 hrs from now) but I'm sure there are some people around who will be able to help you.

                              Comment

                              Working...