• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

help with an old project for last semester class

 
Ranch Hand
Posts: 42
Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I know this is a long program, but I need help here. The final two weeks of my beginning java class and I get handed this project. Use another person's code and fill in the blanks with my own methods and driver code. The problem is that I never got finished with the project. I got stuck on the fourth case in the switch statement and couldn't get past it. Even now, I'm still unsure what I have done wrong. The compiler is telling me that it can't find symbol in the method clearedToGraduateMessage. What the devil am I missing here? I know it's something stupid and simple, but I'm stumped. Any help on this would be greatly appreciated. I would love to finish this project and understand what I did wrong on it and why before I start my second class this month.



Driver program:

 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Too much code to try to read and find a problem. What is the error message exactly (copy and paste it from the command window)? What is the line of code (use the code numbers int he code you posted so we can all see the location) which causes the error?

Generally, the "can't find symbol" error usually means that you are trying to use a variable which does not exist in the scope you are trying to use it in.
 
Marjorie Gyles
Ranch Hand
Posts: 42
Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, I forgot to include that. My bad.


Project5.java:115: error: cannot find symbol
strClearedToGraduateMessage = clearedToGraduateMessage(student1,
^
symbol: method clearedToGraduateMessage(Advisee,Advisee,Advisee)
location: class Project5
1 error




 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Take the str bit off. That is called Hungarian Notation and is frowned upon. Similarly blnResult is a poor name for any boolean. Those equals and equivalent methods are a mass of poorly‑formatted code, which is really difficult to read. The mutliple else blocks in the equals method make me suspicious there is something else wrong with that method.
The commonest reason for a cannot find symbol error is that there is a tiny spelling error in an identifier. Otherwise it might not have been declared, or have gone out of scope before you try to use it.

Look at the link about Hungarian notation, and also read the Joel Spolsky link they provide; Spolsky taks about something slightly different, however.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Lilith Durham wrote:

Project5.java:115: error: cannot find symbol
strClearedToGraduateMessage = clearedToGraduateMessage(student1,
^
symbol: method clearedToGraduateMessage(Advisee,Advisee,Advisee)
location: class Project5
1 error


Your Project5 class doesn't have a method called clearedToGraduateMessage(). It's defined in Advisee. I suspect if you called
defaultAdvisee.clearedToGraduateMessage(...
the message would disappear; however, I've absolutely no idea whether that's what you want.

Also (and I'm surprised that Campbell didn't spot this, because it's a pet peeve of his ), don't use '== true/false' when testing booleans; it's too easy to make a mistake, which is exactly what you've done on line 179 of your Advisee class; and the problem is that it may well compile but fail nastily at runtime, and the error may be difficult to work out.

Booleans should always be tested with:
if (booleanValue)
or
if (!booleanValue)

HIH

Winston
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Winston Gutkowski wrote: . . . Also (and I'm surprised that Campbell didn't spot this, because it's a pet peeve of his ), . . .

Not when you have a 138‑line main method. I didn’t even bother reading that much code.

By the way: a 138‑line method except for one that initialises a GUI is seriously wrong until proven otherwise, just because of its length.
 
Marjorie Gyles
Ranch Hand
Posts: 42
Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Take the str bit off. That is called Hungarian Notation and is frowned upon. Similarly blnResult is a poor name for any boolean. Those equals and equivalent methods are a mass of poorly‑formatted code, which is really difficult to read. The mutliple else blocks in the equals method make me suspicious there is something else wrong with that method.
The commonest reason for a cannot find symbol error is that there is a tiny spelling error in an identifier. Otherwise it might not have been declared, or have gone out of scope before you try to use it.

Look at the link about Hungarian notation, and also read the Joel Spolsky link they provide; Spolsky taks about something slightly different, however.




Thank you for letting me know this. Actually, my instructor demands we use Hungarian notation for all variable names. It's a pet peeve of his NOT to use it. He claims just the opposite: that it is frowned upon if you don't use it. Interesting article. Now I know what to call it.

I will take a closer look at the equals and equivalent methods, but I haven't really made it that far yet. I've checked the spelling several times and it matches, so I don't think that is the problem. Thank you for the help.
 
Marjorie Gyles
Ranch Hand
Posts: 42
Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Winston Gutkowski wrote:Your Project5 class doesn't have a method called clearedToGraduateMessage(). It's defined in Advisee. I suspect if you called
defaultAdvisee.clearedToGraduateMessage(...
the message would disappear; however, I've absolutely no idea whether that's what you want.



It needs to use each individual iteration of the Advisee class (student1, student2, or student3) in order to check the clearedToGraduateMessage assigned to each iteration to see if that particular student is cleared to graduate or not, then display the corresponding message. The defaultAdvisee was evidently only to test to see if we knew how to write a copy constructor or not.

Winston Gutkowski wrote:Also (and I'm surprised that Campbell didn't spot this, because it's a pet peeve of his ), don't use '== true/false' when testing booleans; it's too easy to make a mistake, which is exactly what you've done on line 179 of your Advisee class; and the problem is that it may well compile but fail nastily at runtime, and the error may be difficult to work out.

Booleans should always be tested with:
if (booleanValue)
or
if (!booleanValue)

HIH

Winston



I'm not sure I follow this one. I shouldn't say "if (booleanValue = true/false)"? How do I specify which booleanValue to test? And should the = sign on line 179 be a double in this situation? I'm a bit confused on this one. It's like learning punctuation all over again.
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You’re welcome
 
Marjorie Gyles
Ranch Hand
Posts: 42
Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:

Winston Gutkowski wrote: . . . Also (and I'm surprised that Campbell didn't spot this, because it's a pet peeve of his ), . . .

Not when you have a 138‑line main method. I didn’t even bother reading that much code.

By the way: a 138‑line method except for one that initialises a GUI is seriously wrong until proven otherwise, just because of its length.



Most of that I didn't write. It was the instructor who wrote most of it and a lot of it is white space and comments. However, just out of curiosity, how would you fix it?
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Lilith Durham wrote:Actually, my instructor demands we use Hungarian notation for all variable names...


Then you probably should, if only to keep him happy; but you can tell him from me that the thinking is 30 years out of date. I was taught it as one of the existing naming conventions back when I was learning COBOL, but that was in 1976.

My advice: forget it as soon as you leave his class.

Winston
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Lilith Durham wrote:It needs to use each individual iteration of the Advisee class (student1, student2, or student3) in order to...


Yes, but it also needs to be called on an Absentee object, because that's where it's defined. Right now you're doing unqualified calls, which means that the compiler will look for it in the current class (Project5).

I'm not sure I follow this one. I shouldn't say "if (booleanValue = true/false)"?


Correct.

How do I specify which booleanValue to test?


Exactly as I specified:
if (booleanValue) is equivalent to if (booleanValue == true)
and
if (!booleanValue) is equivalent to if (booleanValue == false)

and it avoids precisely the mistake that you made on line 179 (have a good look at it).

Also, as an added bonus, it saves you from early-onset CTS.

Winston
 
Steve Luke
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Lilith Durham wrote:And should the = sign on line 179 be a double in this situation? I'm a bit confused on this one. It's like learning punctuation all over again.


The single = is always an assignment operator in Java, never a comparison operator. The == is a comparison operator that checks for equality. When you want to compare one value to another you would use the ==.

What you are doing in line 179 by using = is assigning true to the graduationRequirements variable. The result of an assignment operator is always the value assigned so you are effectively
- changing the value of graduationRequirements to true
- always executing the code inside the if() {} clause because the result of that assignment will always be true.

It is a very common mistake, one that can only be made with booleans, and one that can be avoided by simply using the boolean instead of comparing it to a value (as Winston said) because if(graduationRequirements == true) will always give the same result as if(graduationRequirements) and if(graduationRequirements == false) always gives the same result as if(!graduationRequirements) (you can read that is 'if not graduationRequirements').
 
Marjorie Gyles
Ranch Hand
Posts: 42
Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Steve. That helps tremendously.

Now I have another question. I thought I understood this but apparently, I really didn't. The getAdviseeInfo method in the project5 class is using the variable "student". How does that work to copy the information to student1, student2, and student3? I don't understand how it knows to file the information in those variables.I'm the type of person who has to know why something happens, can you tell?
 
Steve Luke
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The variable student in the getAdviseeInfo() method is a reference variable - it is a reference to an Object. You originally create Advisee Objects, which you assign to variables student1, student2, and student3 in another method. Those variables are also reference variables - these ones are referring to the 3 specific Advisee instances you made. Then you pass these variables into the getAdviseeInfo() method by calling it like this:

This copies the reference from the calling code (student1) into the reference in the method (student). Since they are references, now both the method local variable student and the original variable student1 refer to the same Object so the changes you make in the method using the student reference are visible from the calling code using student1. The same happens for the other two student variables in the calling code, but at different times.
 
reply
    Bookmark Topic Watch Topic
  • New Topic