I know this is probably really simple to fix... but I'm lost..
Bryan Peach wrote:Please help. I have to create a class Dog and then implement a driver for that class. I have done both and am now trying to test both but when i go to compile the driver I get this message :cannot find symbol class Dog. I am not sure how to delcare another class, or how to import the class Dog or whatever it is i have to do. Please Help. here is the code...
Since Dog and DogDriver are both part of the Pet package, you do need an import statement for Dog in the DogDriver class. Based on what I am seeing in the sample code you posted, you should not be getting the particular error -- cannot find symbol class Dog -- that you are getting. There are some other issues looming, but lets get you past this one first.
Are both your Dog.java and DogDriver.java files saved in a directory named Dog?
If not, they both need to be in that directory. If that is okay, can you post the command that you are using to compile along with the directory you in when you try to compile.
That being said, I'll see what I can do to help. Maybe someone else that knows JBuilder can jump in as well.
Have you tried compiling your code using the command line to see what happens?
What do yo mean by "when i try to move DogDriver into the Dog file"? I'm not understanding why you are trying to "move" DogDriver into the Dog file. By move, do you mean dragging the DogDriver file into the Dog file? The two classes should be in separate files. While you could put them in the same file under certain circumstances, doing such is a little beyond where you are I believe in your programming experience.
Sorry, I was tying my reply to your first reply when yo posted your second. I'll answer that one now.
Bryan Peach wrote:yeah i got that figured out and working now... but now at my date constructor it is saying that its an invalid method declaration.... but its not even a method declaration... do you see whats wrong with it? Constructors really boggle my mind
A constructor is for constructing, or creating a new instance of, a particular class. The constructor exists within the same class and is named the same thing as the class. So your Dog class has Dog constructors, and can only have Dog constructors. Anything else in the class is a method. You cannot have a Date constructor in your Dog class. And there is no reason you ever should. What does a Dog know about creating a Date? A Dog can only know how to create himself. A Cat only knows how to create, or construct, a Cat, not a Dog. So a Cat cannot have a Dog constructor. And a Date only knows how to create a Date.
Now if a Dog needs to use a Date, the Dog class calls the Dog class' constructor. The Dog class goes not declare a Date constructor, it calls the Date constructor that resides in the Date class. That call can occur in a number of places, such as in the Dog's constructor itself, or in a method within the Dog class. Unfortunately, creating dates is a little more complex that if you want to create a Date other than today, you create a date trough a Calendar.
Do you really need a Date, with a day, month, and year? or do you just need the age (an int)? I ask since I see your Dog constructor is taking an int, which can be used to represent the Dog's age, but not a date.
Bryan Peach wrote:I have to create this Dog class and then two Sub-classes called WorkingDog and PetDog... How do i link them? just by having them in the same package?
No, sinply putting them in the same package will not result in them being subclasses. Think about it logically... how would the compiler know that PetDog is a subclass of Dog and not the other way around? There is nothing telling the compiler of such a relationship. The keyword extends is used to create a subclass:
Bryan Peach wrote:
And the idea is if its a working dog i have to get certain information, but if its a pret dog i need different information... where would i make the distinction to branch off into either of the two subclasses and how do i make the distinction?
Anything that is common to all Dogs goes in the Dog class. Since a PetDog extends Dog, it knows everything a Dog knows (there's a bit more detail involved in this, but for know, you can work off that statement.) Anything specific only to a pet dog goes in the PetDog class. And anything specific to a working dog class goes into the WorkingDog class.
Bryan Peach wrote:
hahaha ok stupid me... i got the errors figured out. Now this is the last thing... I promise... in my driver is it saying that: cannot find symbol constructor Dog()... Whats that all about?
In your Dog class, you only have a constructor Dog(String, Double, String, int) but in your DogDriver class you are trying to call the no-arg (i.e. no argument) constructor Dog(). So you either need to call the correct constructor in your DogDriver class (the one that takes all the information needed to construct a dog) or you need to add a no argument constructor to the Dog class. I think, based on what I am seeing in your code, you want to do the first thing.
See how the types line up in the signature I posted?
When you call the constructor, you need to pass in actual values: