• Post Reply Bookmark Topic Watch Topic
  • New Topic

Issue with cannot find symbol  RSS feed

 
Ryan Gordon
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I am having trouble with my test class, I am able to get the fastest runner in my array to print but when I try to get their last name it gives me an error, or when I change my code around it print the last name as null. I need to be able to print their first and last name, their home address and completion time in minutes on separate lines. Any help would be appreciated. Thank you.










the error is as follows


 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
should be
because it is a method not a variable.
 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What strange names for your classes. You don't have an address book there, you have a name and address. That is different. Address books contain names and addresses, so they are related.
Then it makes no sense for a marathon runner to say he IS‑An address book. It probably does make sense however to say that a marathon runner IS‑A person. I suggest you have a look at the names and consider changing your inheritance hierarchy.
 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another thing I didn't notice earlier: if the marathon runner class extends the other class, how are you going to get a phone number out of the marathon runner class? If you can't get a phone number out of it, how can you say the marathon runner class extends the other class?
 
Ryan Gordon
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok thank you for the advice what can I do to correct this?
 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't know; I think you may have to go back to your initial design, I am afraid.
 
Ryan Gordon
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shouldn't I be able to retrieve information in the parent class? Sorry I'm pretty new and don't understand.
 
Ryan Gordon
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never mind I figured it out, thank you.
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Start off by renaming AddressBook to something like Contact. Create a  real AddressBook that manages a collection of Contacts and has an add() method which adds the Contact if not found or returns a found Contact using first/middle/last as the key.

I agree that it is tempting to consider that a Runner IS-A person but I think it  would be more appropriate in your case to say that a Runner HAS-A Contact.
Now the Runner constructor would look like this.
So, this is one possible approach.
 
Ryan Gordon
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is you have to follow a specific API for the question. Thank you for the help though I appreciate it. I put the () and it's correct now
 
salvin francis
Bartender
Posts: 1664
37
Eclipse IDE Google Web Toolkit Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ryan Gordon wrote:Shouldn't I be able to retrieve information in the parent class? Sorry I'm pretty new and don't understand.

Avoid using parent-child and refer to them as Base class and Sub class instead.

Object oriented softwares have two types of relationship paradigms between objects: IS-A relationship and a HAS-A relationship. Creating the right type of relationship is crucial to your design. In real life, you cannot say a "Car" is a "Door", you would say a "Car" has a "Door". Similarly a "Car" has a "Windshield". In programming terms, this would translate as :
This is a HAS-A relationship.

Similarly, if you are making an Animal class, you can say a Tiger IS-An Animal. Here, a Tiger is a Specialized Sub-class of Animal. The class construct would look like:

This is IS-A relationship.

Next, when you name your class. It should be an intuitive to read and be understandable to all who read your code. The below code looks absurd:


Similarly, if you name a class AddressBook, you have implied it is a book of addresses. It would be intuitive to see a code like:
 
Ryan Gordon
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for that information it makes a lot of sense, can you explain the <> in doors? What is he purpose of using <>?
 
salvin francis
Bartender
Posts: 1664
37
Eclipse IDE Google Web Toolkit Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ryan Gordon wrote:... can you explain the <> in doors? What is he purpose of using <>?

That's Generics. You can read about it here : https://docs.oracle.com/javase/tutorial/java/generics/index.html. In a nutshell,
means that you are defining a List which accepts only objects of type Carrots.

 
Ryan Gordon
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, Im having an issue with returning an average value from an array, how can I calculate the average value? From my understanding an array is an object so I cant calculate that by a primitive type like double. How can I fix this?






Thank you.
 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Doesn't the error message tell you what is wrong?

I like Carey's solution to the inheritance problem: search for “favour composition over inheritance”.

What do you mean by this?
The problem is you have to follow a specific API for the question.
Please explain more. Are you telling us you are required to use poor‑quality code to anser that question?
 
Ryan Gordon
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I mean I have to use a specific method in my case getting the average of the runners completion times using an array, I only know how to do that without using an array, when I try doing it with an array I'm not sure what to do...
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sum = sum + runners[i];
runners[i] returns a BanffMarathonRunner object. You can't add that to sum. However you can add the runner's time to sum.
sum = sum + runners[i].getTime()
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!