I'm getting an error that reads 56: error: cannot find symbol on line findWholeInventory(cameras); symbol: method findWholeInventory(Camera) location: class Inventory
I'm confused by this because I define this method in the class Camera:
and I have defined Camera in the Inventory class:
DigitalCamera is a subclass that extends Camera, could that be a problem? Everything compiles fine except the inventory class with the aforementioned error. Do I just need to change the syntax on the array that it reads from?
so i pulled your code and compiled it, and got this:
Inventory.java:60: cannot find symbol
symbol : method findWholeInventory(Camera)
location: class Inventory
This tells you that on line 60, the compiler couldn't resolve the method - it has NO idea where to find the definition of this method.
You defined in in the Camera class, so you have to tell it to look there:
However, that will give you a new error. See if you can figure out the problem with that...
Daniel Kavanaugh wrote:Also, would it be possible for me to display all the elements in these arrays within a GUI?
of course it would...but GUI code should be completely separate from the other code. you should get it to work from the command line first, and only then worry about the GUI.
No. Plain and simple: if you haven’t made some dreadful error in how you extended the Camera class, then that will not cause any problems. Fred R has already given you a heavy hint as to what the problem you noticed is.
Daniel Kavanaugh wrote: . . .
DigitalCamera is a subclass that extends Camera, could that be a problem? . . .
What Fred didn’t know, because he was writing the reply before you posted all your code, is that you have in fact made a dreadful error in subclassing the Camera class. An error which has to be corrected with generous use of three keys which will really have you cursing me. Ctrl-A delete.
Well, not quite. You have not actually subclassed the Camera class. You have written a new class which says it subclasses it, but you have added all sorts of new information. You have two names, two prices, etc., in the Digitalcamera class. One inherited from Camera, and the other hidden. Look at our FAQ; hiding applies to fields just as it does to methods.
Remove any constructors which don’t do what you want. You want to record make, pixels, price, for every camera. so make sure to get rid of constructors which don’t take all those data. You will probably only want one constructor. Get rid of all the others. Be ruthless. If you want your code to work, you want make pixels price recorded in every Camera object, so make d*mn sure all constructor calls give you that info. And you do that by making sure that is the only constructor tanybody can find.
By the way: are you recording how many Cameras there are in the Camera class? I don’t think that is really part of the Camera class. I think it is part of something else, maybe an Inventory class.
Remove every field from the DigitalCamera class which is repeated from the Camera class. You use the fields which are in the Camera class. They should have private access in Camera, but you can gain access if necessary via the getXXX methods. You may find the only field declared in the Digital class is pixels.
Remove every setXXX and getXXX method from the Digital class which appears to be repeated from Camera.
Remove every constructor which doesn’t set up all your fields. I suggest you change your constructor to use the this. idiom you had in Camera. It allows you to use better parameter names.
What you haven’t noticed yet, is how much smaller your digital class is becoming. One setter/getter pair, one field and one constructor. Your constructor will need to pass lots of information to the Camera class with the super(make, price...); call.
Now all you need to do is simplify that DigitalCamera#toString() method. Find out about super.toString(), which I shall not say any more about at this point.
Now, you have a class with subclasses Camera. And see how much simpler it is.
And I see Fred has already told you not to use a GUI. And have you worked out what the error you noticed was?
I've been attempting to correct this program so that it can be displayed in a gui (although all I need it to do is display the arrays in something that isn't the command prompt). Should I just continue, or are there things I absolutely need to fix before displaying the data? Right now, it displays all necessary data, except the result of the findWholeInventory method.
I did not change Camera.
You should throw all this code away, and start over, the right way.
The first think you do is start without a computer. Pencil, paper, and erasers. You start by writing down what you want your code to do. You think about real properties of things. For example, a camera has a make, a model, and price. A camera doesn't have a department, or an inventoryValue.
A Store might have departments, and departments might have inventories...or the Store might have a inventory...
For what it is worth...I have written tons of code that once I got into it, I realized it wasn't right and ditched it all. Most developers will tell you the same thing.