Having problems getting array program to compile

Inventory 2 Program

Posted 15 August 2007 - 03:45 PM

Hello guys and gals. I am having a hard time with this assignment. It’s called “Inventory Program Part 2”
I must create a product class the hold and item #, Name, # of units, and price of each unit. It must then display all this information plus the results of the stock multiplied by the price. I must also use an array to store multiple items and display them one product at a time and the value of the entire inventory.
I haven’t gotten to the display portion of my assignment yet, because I’m still having problems getting the array to work.
I have been looking through “bigbluesky’s” post and I still can’t figure it out.
Could someone please help?

Because you access an element of an array with the construct: arrayname[index]
And an array is declared by Type[] name

And so on, everytime you want to access an element of myproduct, you must do it with myproduct[elementindex] .
Actually, it would be better to call myproduct myproducts, so it shows that it represents (usually) multiple elements.

Because you access an element of an array with the construct: arrayname[index]
And an array is declared by Type[] name

And so on, everytime you want to access an element of myproduct, you must do it with myproduct[elementindex] .
Actually, it would be better to call myproduct myproducts, so it shows that it represents (usually) multiple elements.

Thank You, my instructor told me that I could "Hard Code" the objects in the array. So now I think im on the right track.

Re: Inventory 2 Program

Posted 16 August 2007 - 02:50 PM

Thank You,
I changed all of the products to "P", and it still will not compile. Does this file depend on another file to compile successfully before it will compile. I have three files and so far only my product files is compiling. I am not even sure I need them all, but I noticed to other members taking the same class that I am have three so I went with it.

Re: Inventory 2 Program

Posted 16 August 2007 - 04:19 PM

Yeah I didn't mean that capitalizing your "P" in product would solve all your problems, but it was just one of a few errors. As for your question about the files yeah you will need three. One to define your product class, one to define your extended class (in your case Movie which extends from Product) and one for your main inventory class to manage all the products/movies.

Your product class is right, your movie class is right and will compile and the only change you need to do in your Inventory class is change how you define your product array. Remember it is an array of type "Product" not of type int. You should also provide an array name to go with that. I have chosen "Products" notice the "s" on the end.

This class above should compile just fine. You will need to make one more slight change. Where you have Item Value there, remember you have to call the product's overridden function to add that restocking fee. Right now it is just recalculating the stock * price. Remember your movie function's getValue() function?

Re: Inventory 2 Program

Posted 16 August 2007 - 04:34 PM

Yeah I didn't mean that capitalizing your "P" in product would solve all your problems, but it was just one of a few errors. As for your question about the files yeah you will need three. One to define your product class, one to define your extended class (in your case Movie which extends from Product) and one for your main inventory class to manage all the products/movies.

Your product class is right, your movie class is right and will compile and the only change you need to do in your Inventory class is change how you define your product array. Remember it is an array of type "Product" not of type int. You should also provide an array name to go with that. I have chosen "Products" notice the "s" on the end.

This class above should compile just fine. You will need to make one more slight change. Where you have Item Value there, remember you have to call the product's overridden function to add that restocking fee. Right now it is just recalculating the stock * price. Remember your movie function's getValue() function?

Enjoy!

Yeah I didn't mean that capitalizing your "P" in product would solve all your problems, but it was just one of a few errors. As for your question about the files yeah you will need three. One to define your product class, one to define your extended class (in your case Movie which extends from Product) and one for your main inventory class to manage all the products/movies.

Your product class is right, your movie class is right and will compile and the only change you need to do in your Inventory class is change how you define your product array. Remember it is an array of type "Product" not of type int. You should also provide an array name to go with that. I have chosen "Products" notice the "s" on the end.

This class above should compile just fine. You will need to make one more slight change. Where you have Item Value there, remember you have to call the product's overridden function to add that restocking fee. Right now it is just recalculating the stock * price. Remember your movie function's getValue() function?

Re: Inventory 2 Program

Posted 16 August 2007 - 08:01 PM

Well if you really want to learn Java thoroughly and have tons of examples, questions, in code highlighting etc I would recommend a book called Java - How to Program by Deitel. The book is a monster, but covers everything. Some of the topics they even overkill by explaining it three different ways. So if you got it the first time you may find some subjects dry. But hey, at least you learn it!