Carey Brown wrote:Inventory - line 6 - itemNumber should be an integer not a double.
Inventory - line 8 - not necessary. inventoryValue is calculated on the fly.
Launcher - Line 7 - not necessary.
Launcher - Line 10 - should be "books" with a lower case 'b'. This is the Java convention.
Inventory - line 75 - probably should have been declared 'static'. Returning 'Inventory[]' seems pointless as the sorting is done in-place and will modify the content of 'theinventory'.
Inventory - line 26 & 36 - could have been implemented as a toString() method in Inventory and then called here with System.out.println( Books[counter] );
Calling sort at line 32 just involves calling the Sortinventory() (again, should start with lower case) method. If you change the method to static then you need the class name, dot (.), method name. You'll have to pass in your array of Inventory as an argument. You could assign the return value back to your 'Books' variable, but as I mentioned, that doesn't really do anything given the way the sort was written.
Edit:
'itemStock' should probably be an integer also.
Carey Brown wrote:Inventory - line 6 - itemNumber should be an integer not a double.
Inventory - line 8 - not necessary. inventoryValue is calculated on the fly.
Launcher - Line 7 - not necessary.
Launcher - Line 10 - should be "books" with a lower case 'b'. This is the Java convention.
Inventory - line 75 - probably should have been declared 'static'. Returning 'Inventory[]' seems pointless as the sorting is done in-place and will modify the content of 'theinventory'.
Inventory - line 26 & 36 - could have been implemented as a toString() method in Inventory and then called here with System.out.println( Books[counter] );
Calling sort at line 32 just involves calling the Sortinventory() (again, should start with lower case) method. If you change the method to static then you need the class name, dot (.), method name. You'll have to pass in your array of Inventory as an argument. You could assign the return value back to your 'Books' variable, but as I mentioned, that doesn't really do anything given the way the sort was written.
Edit:
'itemStock' should probably be an integer also.
Carey Brown wrote:Inventory - line 6 - itemNumber should be an integer not a double.
Inventory - line 8 - not necessary. inventoryValue is calculated on the fly.
Launcher - Line 7 - not necessary.
Launcher - Line 10 - should be "books" with a lower case 'b'. This is the Java convention.
Inventory - line 75 - probably should have been declared 'static'. Returning 'Inventory[]' seems pointless as the sorting is done in-place and will modify the content of 'theinventory'.
Inventory - line 26 & 36 - could have been implemented as a toString() method in Inventory and then called here with System.out.println( Books[counter] );
Calling sort at line 32 just involves calling the Sortinventory() (again, should start with lower case) method. If you change the method to static then you need the class name, dot (.), method name. You'll have to pass in your array of Inventory as an argument. You could assign the return value back to your 'Books' variable, but as I mentioned, that doesn't really do anything given the way the sort was written.
Edit:
'itemStock' should probably be an integer also.
Second question I have is if I change itemNumber and itemStock to integers in my variables, do I also need to change them to integers through the rest of the code? such as in the constructor? I would assume yes.
Amie Mac wrote:I changed them all to integers from doubles and the code runs fine.
Carey Brown wrote:Inventory - line 70 - just return stock * price. Don't store it.
Carey Brown wrote:
Amie Mac wrote:I changed them all to integers from doubles and the code runs fine.
Because monetary values usually contain a decimal portion, I would leave price as a double. You will have to make allowance for the fact that an integer multiplied by a double yields a double.
Carey Brown wrote:Your getItemStock() method returns a double; what should it return? Ditto for getItemNumber().
Inventory - line 95 - you are using %f in some places where you have an integer value.
Line 28 - you changed the sort method to be declared 'static', therefore to call it you shouldn't use an Inventory object (ie books[0]), instead use Inventory.sortInventory().
Line 102 - you need to pass in an Inventory[]. The Inventory class knows nothing about your array unless you pass it in. As you guessed, you'll need a loop to go through the array to sum up the inventory values.
Amie Mac wrote:
Carey Brown wrote:Your getItemStock() method returns a double; what should it return? Ditto for getItemNumber().
Inventory - line 95 - you are using %f in some places where you have an integer value.
Line 28 - you changed the sort method to be declared 'static', therefore to call it you shouldn't use an Inventory object (ie books[0]), instead use Inventory.sortInventory().
Line 102 - you need to pass in an Inventory[]. The Inventory class knows nothing about your array unless you pass it in. As you guessed, you'll need a loop to go through the array to sum up the inventory values.
- Changed the return values to int
- changed the %f to %i
Once I did this ^ then I was getting runtime illegal format conversion errors - changed them all back to doubles.
- calling the sort method with Inventory.sortInventory()
- still working on the total inventory value method. will that method look like the sort method with the Inventory[]?
Carey Brown wrote:
Amie Mac wrote:
Carey Brown wrote:Your getItemStock() method returns a double; what should it return? Ditto for getItemNumber().
Inventory - line 95 - you are using %f in some places where you have an integer value.
Line 28 - you changed the sort method to be declared 'static', therefore to call it you shouldn't use an Inventory object (ie books[0]), instead use Inventory.sortInventory().
Line 102 - you need to pass in an Inventory[]. The Inventory class knows nothing about your array unless you pass it in. As you guessed, you'll need a loop to go through the array to sum up the inventory values.
- Changed the return values to int
- changed the %f to %i
Once I did this ^ then I was getting runtime illegal format conversion errors - changed them all back to doubles.
- calling the sort method with Inventory.sortInventory()
- still working on the total inventory value method. will that method look like the sort method with the Inventory[]?
Integers are formatted with %d.
Inventory.sortInventory(books);
will that method look like the sort method with the Inventory[]? -- yes
Carey Brown wrote:Change
to
And forget the loop in Launch.
Carey Brown wrote:Replace
System.out.println("Total Inventory Value: " + theInventory);
With
System.out.println("Total Inventory Value: " + total );
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |