Forums Register Login

Java Inventory

+Pie Number of slices to send: Send
I realy need some help. My teacher said,"Inventory_Program has myInventory instantiated as an array and then is instantiated again as a non-array object. The next 2 errors on that class are related to the first error. (3 errors)." What does this mean? I will be honest, I just want to get this class done. I haven't had problems in any class but this one. I am two weeks from craduation, and I need someone to tell me what I am doing wrong. Please?



1
+Pie Number of slices to send: Send
Please cut/past the exact text of the error messages including line numbers.
1
+Pie Number of slices to send: Send
I think your teacher is trying to point out that myInventory = new DVD_Inventory(); doesn't compile because myInventory is an array.
+Pie Number of slices to send: Send
Lines 30, 35, 36, The while statement on line 57 says "Empty statement after while", Lines 59 and 61 all on the Inventory_Program.java.

@Jeanne Boyarsky If it's an array, do I get rid of myInventory = new DVD_Inventory(); ??? I don't really get this like I said, I'm sorry, It's embarrassing really. I have read and read, and I can't get this. It's this type of class I wish I didn't do online. :-(
+Pie Number of slices to send: Send
When I Debug on Netbean this is what I get:

debug:
Welcome!


Item Name | # | Stock | Price | Value
---------------------------------------
+Pie Number of slices to send: Send
 

Ofelia Stewart wrote:@Jeanne Boyarsky If it's an array, do I get rid of myInventory = new DVD_Inventory(); ??? I don't really get this like I said, I'm sorry, It's embarrassing really. I have read and read, and I can't get this. It's this type of class I wish I didn't do online. :-(


What is the purpose of that line? Is it to create a single DVD? To create a single DVD and add it to the array? Something else? Try to explain it in English first.
+Pie Number of slices to send: Send
This is what I was asked to do for this assignment.

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.

I need the items stored in the array, and I need to be able to output information ones at a time. At the end of the program, I need to output and display the value of all/ the entire, inventory value. Does this help? The program I compiled last week is what I used to modify to create what I have created here, this week.
1
+Pie Number of slices to send: Send
On line 21 of your Inventory_Program class you initialize the myInventory variable as an Array of DVD_Inventory objects. On line 30 you then reassign the myInventory variable to a single DVD_Inventory object thus losing the Array.



I believe this is what your teacher was talking about. I think what you might need to do is instead of assigning the new DVD_Inventory object to the variable, you want to assign the object to a location in the array like this:



You will also need to modify line 35 and 36 to reflect the myInventory as an Array with the square brackets [].

Hope this helps you get started on debugging the rest.
+Pie Number of slices to send: Send
Thank you so much! It helped straighten out some of the errors and I also found some { and} that did not belong, I have issues now with :

Lines 36 and 37 say "Can not find Symbols.

Line 61 says illegal start to expression

and Line 58 (The while statement) says "Empty statement after While"

Other than that, ! got many errors fixed. When I compile, It looks like this.
+Pie Number of slices to send: Send
Sorry, looks like this:

debug:
Welcome!


Item Name | # | Stock | Price | Value
---------------------------------------
+Pie Number of slices to send: Send
OOOPPPPssss, lol sorry, I modified lines 35 and 36 like you said! Your a super angel. I would have never ever thought of those [] brackets. I've been looking at this all day trying to get it and didn't see that! Thank you beyond words!
+Pie Number of slices to send: Send
Okay, so I removed the ; semicolon after the while statement and I removed a couple of other things. Now I have this last issue.

Line 61
+Pie Number of slices to send: Send
illegal start to expression line 61 ... sorry didn't clarify that.

Debugger console says:

Listening on javadebug
User program running
Debugger stopped on uncompilable source code.
Debugger stopped on uncompilable source code.
Debugger stopped on uncompilable source code.
Thread main stopped at Inventory_Program.java:29.
1
+Pie Number of slices to send: Send
It looks like you are missing the closing curly brace } after the end of the While(run) statement.

You need a closing curly brace to close the main() method before the calcValue() method.
+Pie Number of slices to send: Send
Thank you, This was one of the things I fixed. This is what I am getting now. I'm having difficulty with the last part from line 63 illegal start to expression.






This is what the compile looks like:

debug:
Welcome!


Item Name | # | Stock | Price | Value
---------------------------------------
REUMWK | 1 | 192 | $11.47 | $2,201.65
---------------------------------------
Total value of DVD inventory is: $2201.65

Sort this list?
Enter 'Y' or 'N'
y
Item Name | # | Stock | Price | Value
---------------------------------------
| 0 | 0 | $0.00 | $0.00
---------------------------------------
| 0 | 0 | $0.00 | $0.00
---------------------------------------
| 0 | 0 | $0.00 | $0.00
---------------------------------------
| 0 | 0 | $0.00 | $0.00
---------------------------------------
REUMWK | 1 | 192 | $11.47 | $2,201.65
---------------------------------------
Would you like to continue?
Enter 'Y' or 'N'
y

FYWTFC | 2 | 409 | $10.29 | $4,206.85
---------------------------------------
Total value of DVD inventory is: $6408.49

Sort this list?
Enter 'Y' or 'N'
y
Item Name | # | Stock | Price | Value
---------------------------------------
| 0 | 0 | $0.00 | $0.00
---------------------------------------
| 0 | 0 | $0.00 | $0.00
---------------------------------------
| 0 | 0 | $0.00 | $0.00
---------------------------------------
FYWTFC | 2 | 409 | $10.29 | $4,206.85
---------------------------------------
REUMWK | 1 | 192 | $11.47 | $2,201.65
---------------------------------------
Would you like to continue?
Enter 'Y' or 'N'
y

IMAIVB | 3 | 151 | $10.20 | $1,540.03
---------------------------------------
Total value of DVD inventory is: $7948.53

Sort this list?
Enter 'Y' or 'N'
y
Item Name | # | Stock | Price | Value
---------------------------------------
| 0 | 0 | $0.00 | $0.00
---------------------------------------
| 0 | 0 | $0.00 | $0.00
---------------------------------------
FYWTFC | 2 | 409 | $10.29 | $4,206.85
---------------------------------------
IMAIVB | 3 | 151 | $10.20 | $1,540.03
---------------------------------------
REUMWK | 1 | 192 | $11.47 | $2,201.65
---------------------------------------
Would you like to continue?
Enter 'Y' or 'N'
y

GHFBJDZFW | 4 | 386 | $19.67 | $7,591.73
---------------------------------------
Total value of DVD inventory is: $14000.22

Sort this list?
Enter 'Y' or 'N'
y
Item Name | # | Stock | Price | Value
---------------------------------------
| 0 | 0 | $0.00 | $0.00
---------------------------------------
| 0 | 0 | $0.00 | $0.00
---------------------------------------
FYWTFC | 2 | 409 | $10.29 | $4,206.85
---------------------------------------
GHFBJDZFW | 4 | 386 | $19.67 | $7,591.73
---------------------------------------
REUMWK | 1 | 192 | $11.47 | $2,201.65
---------------------------------------
Would you like to continue?
Enter 'Y' or 'N'
y

RBXCIKFD | 5 | 7 | $16.36 | $114.53
---------------------------------------
Total value of DVD inventory is: $11913.11

Sort this list?
Enter 'Y' or 'N'
y
Item Name | # | Stock | Price | Value
---------------------------------------
| 0 | 0 | $0.00 | $0.00
---------------------------------------
| 0 | 0 | $0.00 | $0.00
---------------------------------------
FYWTFC | 2 | 409 | $10.29 | $4,206.85
---------------------------------------
GHFBJDZFW | 4 | 386 | $19.67 | $7,591.73
---------------------------------------
RBXCIKFD | 5 | 7 | $16.36 | $114.53
---------------------------------------
Would you like to continue?
Enter 'Y' or 'N'
y

Thank you!
Thank you!
Thank you!
Thank you!
Thank you!
Thank you!
Thank you!
Thank you!
Thank you!
Thank you!
Thank you!
Thank you!
Thank you!
Thank you!
Thank you!
Thank you!
Thank you!
Thank you!
Thank you!
Thank you!
Thank you!
Thank you!
Thank you!
Thank you!
Thank you!
Thank you!
Thank you!
Thank you!
Thank you!
Thank you!
Thank you!
Thank you!


And it keeps going! ... oh man...
+Pie Number of slices to send: Send
The error is "Exporting non-public type through public API.".
+Pie Number of slices to send: Send
With regards to the illegal start of expression on line 63, you need to close your main() method before declaring your calValue() method as shown below:



Right now, the compiler thinks that on line 63 is supposed to be an expression rather then a method declaration because the main() method is still open.
+Pie Number of slices to send: Send
Regarding the endless loop of "Thank you", the While loop on line 60 is an infinite loop.



The "run" variable is set to True on line 20 but it is never set to false thus never breaking out of this loop. What is this loop being used for? If you only want "Thank you!" to be printed once at the very end they it does not need to be inside of a while loop.
+Pie Number of slices to send: Send
I know this may sound stupid... but where are you seeing this main method that I still have open? I'm still trying to find it after all this. Maybe my minds just tired of looking at this. I don't see it? I feel so dumb right now.
+Pie Number of slices to send: Send
I completely through out the While loop. I admit that I thought it was kind of cool since I never did that before.
+Pie Number of slices to send: Send
I have it compiling nicely except for the warning for calcValue on Line 63. I have a question, When I compile,it's not giving the sorted list for all five, it's only doing three in my debugger console, is this because of the issue on line 63 as well?
+Pie Number of slices to send: Send
Sorry this is what it looks like now.

debug:
Welcome!


Item Name | # | Stock | Price | Value
---------------------------------------
NNZUNK | 1 | 39 | $17.93 | $699.41
---------------------------------------
Total value of DVD inventory is: $699.41

Sort this list?
Enter 'Y' or 'N'
y


Item Name | # | Stock | Price | Value
---------------------------------------
| 0 | 0 | $0.00 | $0.00
---------------------------------------
| 0 | 0 | $0.00 | $0.00
---------------------------------------
| 0 | 0 | $0.00 | $0.00
---------------------------------------
| 0 | 0 | $0.00 | $0.00
---------------------------------------
NNZUNK | 1 | 39 | $17.93 | $699.41
---------------------------------------
Would you like to continue?
Enter 'Y' or 'N'
y



Thank you!
VVURM | 2 | 95 | $14.55 | $1,382.69
---------------------------------------
Total value of DVD inventory is: $2082.11

Sort this list?
Enter 'Y' or 'N'
y


Item Name | # | Stock | Price | Value
---------------------------------------
| 0 | 0 | $0.00 | $0.00
---------------------------------------
| 0 | 0 | $0.00 | $0.00
---------------------------------------
| 0 | 0 | $0.00 | $0.00
---------------------------------------
NNZUNK | 1 | 39 | $17.93 | $699.41
---------------------------------------
VVURM | 2 | 95 | $14.55 | $1,382.69
---------------------------------------
Would you like to continue?
Enter 'Y' or 'N'
y



Thank you!
ZPWMO | 3 | 385 | $12.20 | $4,695.93
---------------------------------------
Total value of DVD inventory is: $6778.04

Sort this list?
Enter 'Y' or 'N'
y


Item Name | # | Stock | Price | Value
---------------------------------------
| 0 | 0 | $0.00 | $0.00
---------------------------------------
| 0 | 0 | $0.00 | $0.00
---------------------------------------
NNZUNK | 1 | 39 | $17.93 | $699.41
---------------------------------------
VVURM | 2 | 95 | $14.55 | $1,382.69
---------------------------------------
ZPWMO | 3 | 385 | $12.20 | $4,695.93
---------------------------------------
Would you like to continue?
Enter 'Y' or 'N'
y



Thank you!
VWNBIG | 4 | 445 | $10.19 | $4,536.20
---------------------------------------
Total value of DVD inventory is: $9931.54

Sort this list?
Enter 'Y' or 'N'
y


Item Name | # | Stock | Price | Value
---------------------------------------
| 0 | 0 | $0.00 | $0.00
---------------------------------------
| 0 | 0 | $0.00 | $0.00
---------------------------------------
NNZUNK | 1 | 39 | $17.93 | $699.41
---------------------------------------
VWNBIG | 4 | 445 | $10.19 | $4,536.20
---------------------------------------
ZPWMO | 3 | 385 | $12.20 | $4,695.93
---------------------------------------
Would you like to continue?
Enter 'Y' or 'N'
y



Thank you!
EYZRDG | 5 | 130 | $15.78 | $2,051.81
---------------------------------------
Total value of DVD inventory is: $7287.42

Sort this list?
Enter 'Y' or 'N'
y


Item Name | # | Stock | Price | Value
---------------------------------------
| 0 | 0 | $0.00 | $0.00
---------------------------------------
| 0 | 0 | $0.00 | $0.00
---------------------------------------
EYZRDG | 5 | 130 | $15.78 | $2,051.81
---------------------------------------
NNZUNK | 1 | 39 | $17.93 | $699.41
---------------------------------------
VWNBIG | 4 | 445 | $10.19 | $4,536.20
---------------------------------------
Would you like to continue?
Enter 'Y' or 'N'
y

Thank you!
BUILD SUCCESSFUL (total time: 10 seconds)
+Pie Number of slices to send: Send
Okay, I got no errors now, but I am wondering why when it compiles the list and it's suppose to be sorted, it only gives out 3 and not all 5. I'm trying to figure out where I did this at? This is what I get as the last result.

Would you like to continue?
Enter 'Y' or 'N'
y
MKJBZDDV | 5 | 300 | $18.97 | $5,689.54
---------------------------------------
Total value of DVD inventory is: $14005.11

Sort this list?
Enter 'Y' or 'N'
y
Item Name | # | Stock | Price | Value
---------------------------------------
| 0 | 0 | $0.00 | $0.00
---------------------------------------
| 0 | 0 | $0.00 | $0.00

---------------------------------------
GUPCJO | 2 | 320 | $18.70 | $5,984.27
---------------------------------------
HFCOEE | 4 | 124 | $18.80 | $2,331.30
---------------------------------------
MKJBZDDV | 5 | 300 | $18.97 | $5,689.54
---------------------------------------
Would you like to continue?
Enter 'Y' or 'N'
y
BUILD SUCCESSFUL (total time: 48 seconds)
+Pie Number of slices to send: Send
 

Campbell Ritchie wrote:I have had to change a lot of // comments to /* … */ type because the long lines make the code difficult to read.



Sorry Campbell, I will be more mindful of my code comments.

@Ofelia
The Arrays.sort() seems to be causing the issue. I haven't used this method so I'm not sure why it is doing what it is doing, but by commenting out that line (line 49) all 5 DVD_Inventory items print out.
+Pie Number of slices to send: Send
Ok I think I am understanding what is going on now. Since Arrays.sort() is being called during each itteration of the loop, the order of the items in the array are being changed each time before a new item is added. When the new item gets added it will "overwrite" one of the existing items.

I'm not sure what order the output needs to be in but if you just loop through the array to output the items they will display in order of the array index. You shouldn't need to use the Arrays.sort() method unless you have a specific way you need the items sorted.
Live a little! The night is young! And we have umbrellas in our drinks! This umbrella has a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1544 times.
Similar Threads
Trouble with arrays / Validating user input
Unable to display data from an ArrayList
Sorting arrays
Need help with Car Inventory Program part 3
Displaying ArrayList data in a GUI's Text Fields - Part II
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 00:19:52.