Results 1 to 14 of 14
  1. #1
    marMcD is offline Member
    Join Date
    Feb 2009
    Posts
    12
    Rep Power
    0

    Default Inventory Program Part 3 ~ please help!

    Hello,

    Can anybody please help me figure out what I am missing here?

    I need to to create an inventory program that holds multiple items. In addition, I also have to add the manufacturer and a 5% restock fee. The inventory also calculates the total value of the entire inventory. I would really appreciate any help...

    I am getting one error but when I tried to remove this line, it gave me more errors.

    InventoryProgramPart3.java:174: illegal start of expression
    public double calculateInventory(product[])
    ^

    Here is my entire code:

    Java Code:
    class product
    {
         public int itemNumber;
         public String itemName;
         public int units;
         public double unitPrice;
    
    
         public void setItemNumber( int itemNumber )
         {
              this.itemNumber = itemNumber;
         }
    
         public int getItemNumber()
         {
              return itemNumber;
         }
    
         public void setItemName( String itemName )
         {
              this.itemName = itemName;
         }
    
         public String getItemName()
         {
              return itemName;
         }
    
         public void setUnits( int units )
     	{
              this.units = units;
         }
    
         public int getUnits()
         {
              return units;
         }
    
    
         public void setUnitPrice( double unitPrice )
         {
              this.unitPrice = unitPrice;
         }
    
         public double getUnitPrice()
         {
              return unitPrice;
         }
    
         // calculate supplies inventory value
         public double calculateValue()
         {
              return units * unitPrice;
         } // end method inventory value
    
        // initialize constructor
         product( int itemNumber, String itemName, int units, double unitPrice )
         {
    		 itemNumber = itemNumber;
    		 itemName = itemName;
    		 units = units;
    		 unitPrice = unitPrice;
    	 } // end constructor
    
    
        // display inventory
         public void displayInventory()
         {
              System.out.println(); // outputs blank line
    
              System.out.println( "Product Number:  "+itemNumber );
              System.out.println( "Product Name:  "+itemName );
              System.out.println( "Quantity Available:  "+ units );
              System.out.printf( "Unit Price:  $%.2f", unitPrice );
    
              manufacturer product = new manufacturer( "Corporate Express" );
    
              System.out.println( "\nManufacturer:  "+ product.getManufacturer() );
    
              // value() method and display the value
              System.out.printf( itemName +  "\nInventory value" + "is = $%.2f\n",
                   calculateValue() );
    
        }
    
    } // end class product
    
    class manufacturer extends product
    {
         // holds the supplies manufacturer
         private String suppliesManufacturer;
    
         // initialize constructor
         manufacturer( int itemNumber, String itemName, int units,
              double unitPrice, String manufacturer )
         {
              super( itemNumber, itemName, units, unitPrice );
              productManufacturer = manufacturer;
         } // end constructor
    
         // set product manufacturer
         public void setManufacturer( String manufacturer )
         {
              this.productManufacturer = manufacturer;
         } // end method
    
         // return product manufacturer
         public String getManufacturer()
         {
             return productManufacturer;
         } // end method
    
         // add 5% restocking fee
         public double calculateValue()
         {
              return super.calculateValue() * 1.05;
         } // end method
    
         // calculate restock fee
         public double calculateRestockFee()
         {
              return super.calculateValue() * .05;
         } //end method
    
         // String format
         public String toString()
         {
              String formatString = "Manufacturer:  %s";
              formatString += "Restock Fee:  $%.2f";
              formatString = String.format( formatString, productManufacturer,
                   super.calculateValue() * 0.05 );
              return( formatString + super.toString() );
         }
    
         // display inventory
         public void displayInventory()
         {
              super.displayInventory();
              System.out.println( toString() );
    
              // Display total value plus reStock fee
              System.out.printf(itemName+  "\nInventory value" +" is: $%.2f\n",
                   calculateRestockingFee() );
    
         } // end method display inventory
    
    } // end class manufacturer
    
    public class InventoryProgramPart3
    {
    
    	     // begin main method
    	     public static void main(String args[] )
    	     {
    	       	  // create array for products
    	          product product[] = new product[5];
    
    	          product highlighter = new product( 35000, "Highlighter", 24, 5.75 );
    	          product yellowPad = new product( 35001, "Yellow Pad", 20, 7.99 );
    	          product pencil = new product( 35002, "Pencil", 12, 3.25 );
    	          product scissors = new product( 35003, "Scissors", 6, 4.35 );
    	          product manilaFolder = new product( 35004, "Manila Folder", 36, 6.50 );
    
    					for (int i = 0; i < product.length; i++ )
    					{
    						System.out.println( "Product Number: /t" + product[i].getItemName());
    					}
    
    					// call calculateInventory method
    					public static double calculateInventory(product[])
    					{
    						double sum = 0;
    
    	 		   	      for ( int i = 0; i < product.length; product++)
    	 		   	      {
    						  sum += product.getUnitPrice();
    					  }
    					  	return sum;
    					}
    
    	  		System.out.printf( "\nTotal inventory value: $%.2f\n", product );
    
    
    
    	     } // end method main
    
     } // end class InventoryProgramPart3

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

    Default

    OK, look at this line carefully:
    Java Code:
    public double calculateInventory(product[])
    is it missing anything? Look carefully at what's in the parenthesis.

  3. #3
    marMcD is offline Member
    Join Date
    Feb 2009
    Posts
    12
    Rep Power
    0

    Default

    am I missing inventory?

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

    Default

    What's wrong with this method declaration?
    Java Code:
    void myMethod(int)
    Can you see it's missing something? What?

  5. #5
    marMcD is offline Member
    Join Date
    Feb 2009
    Posts
    12
    Rep Power
    0

    Default

    Hi Fubarable,

    I am sorry but I have no idea what is missing.. This is my first time writing a program and I am just beginning to learn.

    If you could point me out what it is I'd really appreciate it.

    Thanks!

  6. #6
    marMcD is offline Member
    Join Date
    Feb 2009
    Posts
    12
    Rep Power
    0

    Default

    Isn't it my method calculateInventory?
    I'm confused... :{

  7. #7
    marMcD is offline Member
    Join Date
    Feb 2009
    Posts
    12
    Rep Power
    0

    Default

    hi again,

    I add "void" to it but it still giving me the same error...

    What should I put instead?

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

    Default

    One problem I see is that your parameter variable declaration is incomplete. For instance look here:

    Java Code:
    // WRONG
    void myMethod(int)
    {
    }
    
    // RIGHT
    void myMethod(int myInt)
    {
    }
    Your code has a similar error with an array parameter. you never declare a variable there.

  9. #9
    marMcD is offline Member
    Join Date
    Feb 2009
    Posts
    12
    Rep Power
    0

    Default

    Hi again,

    I changed it to:

    public static void calculateInventory(double product)

    but still saying it is illegal start of expression..

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

    Default

    I was going through more of your code, and there seem to be a gabillion and a half errors. I'm not trying to be insulting, but we really have to know: let's put all cards on the table here; are you totally lost in your programming class at the current moment?

  11. #11
    marMcD is offline Member
    Join Date
    Feb 2009
    Posts
    12
    Rep Power
    0

    Default

    to be honest... I am.

    I am working on this for almost a week now. I learned how to create a class and arrays but I am having a hard time how to call a method. This was actually due this past Sunday. I am already getting 20% penalty.. tonight is my last chance to post it. Or I get no grades at all. :(

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

    Default

    The code is totally borked I'm afraid and not worth salvaging. If you really want to do this, I'd suggest scrapping this current attempt and starting over from the beginning.

    But you must change your style of programming to prevent the accumulation of many errors. Instead of typing in all the code and then testing it, create code in a step-wise iterative process. The key is to never try to add good code to bad code. Create the class skeleton, and immediately compile it to be sure there are no errors. Add a little bit of code -- the compile and fix. do not add any more code until all errors are fixed. Then add a little more code, compile, then fix, ... repeat as needed.

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

    Default

    Also, I find it best to write out my programs on paper first, usually using pseudocode before attempting to type code into the monitor.

  14. #14
    marMcD is offline Member
    Join Date
    Feb 2009
    Posts
    12
    Rep Power
    0

    Default

    Okay.. I'll try that.

    Thank you so much for your time and help.

Similar Threads

  1. Java Inventory Program Part 3
    By ljk8950 in forum New To Java
    Replies: 18
    Last Post: 07-28-2008, 05:47 AM
  2. Inventory Program Part 3 - DUE TODAY (7/28/08)
    By ljk8950 in forum New To Java
    Replies: 7
    Last Post: 07-27-2008, 10:28 PM
  3. Inventory part 3 program problems
    By badness in forum New To Java
    Replies: 1
    Last Post: 12-17-2007, 07:00 AM
  4. Inventory part 2 help please
    By badness in forum New To Java
    Replies: 1
    Last Post: 12-12-2007, 07:51 AM
  5. Inventory program
    By Nexcompac in forum New To Java
    Replies: 3
    Last Post: 07-27-2007, 05:51 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
  •