Results 1 to 14 of 14
- 02-25-2009, 04:54 AM #1
Member
- Join Date
- Feb 2009
- Posts
- 12
- Rep Power
- 0
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
-
OK, look at this line carefully:
is it missing anything? Look carefully at what's in the parenthesis.Java Code:public double calculateInventory(product[])
- 02-25-2009, 05:06 AM #3
Member
- Join Date
- Feb 2009
- Posts
- 12
- Rep Power
- 0
am I missing inventory?
-
What's wrong with this method declaration?
Can you see it's missing something? What?Java Code:void myMethod(int)
- 02-25-2009, 05:15 AM #5
Member
- Join Date
- Feb 2009
- Posts
- 12
- Rep Power
- 0
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!
- 02-25-2009, 05:18 AM #6
Member
- Join Date
- Feb 2009
- Posts
- 12
- Rep Power
- 0
Isn't it my method calculateInventory?
I'm confused... :{
- 02-25-2009, 05:20 AM #7
Member
- Join Date
- Feb 2009
- Posts
- 12
- Rep Power
- 0
hi again,
I add "void" to it but it still giving me the same error...
What should I put instead?
-
One problem I see is that your parameter variable declaration is incomplete. For instance look here:
Your code has a similar error with an array parameter. you never declare a variable there.Java Code:// WRONG void myMethod(int) { } // RIGHT void myMethod(int myInt) { }
- 02-25-2009, 05:31 AM #9
Member
- Join Date
- Feb 2009
- Posts
- 12
- Rep Power
- 0
Hi again,
I changed it to:
public static void calculateInventory(double product)
but still saying it is illegal start of expression..
-
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?
- 02-25-2009, 05:41 AM #11
Member
- Join Date
- Feb 2009
- Posts
- 12
- Rep Power
- 0
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. :(
-
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.
-
Also, I find it best to write out my programs on paper first, usually using pseudocode before attempting to type code into the monitor.
- 02-25-2009, 05:57 AM #14
Member
- Join Date
- Feb 2009
- Posts
- 12
- Rep Power
- 0
Similar Threads
-
Java Inventory Program Part 3
By ljk8950 in forum New To JavaReplies: 18Last Post: 07-28-2008, 05:47 AM -
Inventory Program Part 3 - DUE TODAY (7/28/08)
By ljk8950 in forum New To JavaReplies: 7Last Post: 07-27-2008, 10:28 PM -
Inventory part 3 program problems
By badness in forum New To JavaReplies: 1Last Post: 12-17-2007, 07:00 AM -
Inventory part 2 help please
By badness in forum New To JavaReplies: 1Last Post: 12-12-2007, 07:51 AM -
Inventory program
By Nexcompac in forum New To JavaReplies: 3Last Post: 07-27-2007, 05:51 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks