aspose file tools*
The moose likes Beginning Java and the fly likes Having Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Having "Cannot find symbol" and "Class, Interface, Enum Expected" Errors still" Watch "Having "Cannot find symbol" and "Class, Interface, Enum Expected" Errors still" New topic
Author

Having "Cannot find symbol" and "Class, Interface, Enum Expected" Errors still

Lucas Stelljes
Greenhorn

Joined: Jan 31, 2011
Posts: 6
Greetings,

I am new to Java SE. In my previous CompSci experience I used Python. I have writing a program currently that requires my to calculate a GPA given the user's input for Grades in 5 classes. On top of this, I must calculate and print if their GPA is sufficient enough to award them making the President's List, Dean's List, or Academic Probation.

I am not allowed to use a loop to ask the User to input their class/grade 5 times, so I am unsure how to ask the user for their inputs without a loop. Also, I must include the line of code: "private static double gpaPts(String grade) {" and am unsure where to include this, much-less what its function is.

I am having issues in lines 34-59 with "Cannot find symbol, identifier expected, and Illegal start of type." I know this is alot wrong, but any help at all would help me on my way to writing this program fully. If any more details are required, please do ask. I am new to programming and don't always know how much is needed to fix something.

Thanks!

sri ramvaithiyanathan
Ranch Hand

Joined: Nov 20, 2010
Posts: 109
Lucas Stelljes wrote:


Hi Lucas,
Welcome to coderanch.
In quotes you can see the mistakes you did.

1) In for loop given condition,whether counter <=5 or <5.what is the condition for counter
If you use counter=5,Type mismatch error will occur.
2)what is the datatype of average and gradecounter in your program.
whether its string or int or boolean.Straight away you used in your program.you should not do like that
It will throw error.
3)Inside gpaPts method everything you did is wrong.what is tat A,B,C,A-
If you want to check the outcome of grade==A.
use this way grade.equals("A") or if you think the grade may be A or a.
Then use this way grade.equalsIgnoreCase("A");

P.S: Sorry to say this Read Java first.

Regards,
Sriram.V


For java examples,ebooks,interview questions,visit this blog
http://periodicupdates.blogspot.com/
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36598
    
  16
Welcome to the Ranch

Don't write so much code. Write 5 lines, compile them and look for errors. It is much easier to find an error in 5 lines than in 62.
Lucas Stelljes
Greenhorn

Joined: Jan 31, 2011
Posts: 6
Okay, I made corrections that both of you recommended. Thank you.

I have resolved many of the issues but am still having a few errors.

In the lines where I try to calculate the "double totalGradeX" it tells me "Cannot find symbol (method gpaPts(java.lang.String)." I am confused because I thought my gpaPts method outside the "Main() {" function should be called to solve these "double totalGradeX" statements.

My "private static String finalGrades(double gpaPts){" is missing a return statement, but I am unsure of what to place afterwards as an appropriate return.

Lastly, my "private static double gpaPts(String grade){" claims there is a "Class, Interface, or Enum Expected" error. I have looked up how to solve this and reviewed notes I have on this topic, but I don't understand the solution. What am I supposed to type earlier in the program to make this method recognize the code?

Again, let me know if I can clarify anything.
Thanks.




Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

Check your brackets. If you fix those some exceptions will make more sence. Some statements miss a semicolon. So they won't compile.
You have written the methods so you must have an reason why you declared it to return a String/double and what the meaning of that String/double is.
Also you have a lot of duplicate code. Try to create a method and call it with different parameters (and maybe use a loop).


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36598
    
  16
A "class enum or interface expected error" usually means one of two things
  • If it appears to be at the beginning of the class, you have misspelt the keyword, eg Class for class or publicclass
  • If it appears at the end of the class, most likely you have too many } for the number of {

  • Missing a return means that the last line of the method (with a few exceptions) must start return, followed by something in the format specified by the method's return type. So your gpaPtas method must have return s; as its last line where "s" is a String.

    You can usually find the cause of unmatched {} if you indent your code correctly; I would agree with the suggestions here. If your {} are correctly indented, they will be paired vertically like thisor this. . . and you can easily see which braces are incorrectly paired.
    sri ramvaithiyanathan
    Ranch Hand

    Joined: Nov 20, 2010
    Posts: 109


    You have missed close brace in gpaPts method.




    And i will tell you one thing if you put close brace also its not going to work,because no return type found for above mentioned method.
    Dont think i'm discouraging you,do simple program first then only you will get idea and you will become king in Java.
    So try to do programming from small java programs.
    All the best dude....

    Regards,
    Sriram.V
    Lucas Stelljes
    Greenhorn

    Joined: Jan 31, 2011
    Posts: 6
    I appreciate all the help guys.

    I would LOVE to start at a more simplistic approach to Java. However, being in a college course doesn't really allow that

    I configured the program to work perfectly, alot of which came from the help provided here. I will definitely try to contribute things I learn and also seek advice when needed.

    Thank you,
    -Lucas
    sri ramvaithiyanathan
    Ranch Hand

    Joined: Nov 20, 2010
    Posts: 109
    Lucas you are always welcome.
    we are happy to help.
    If you have passion in java you will learn java in your college duration itself.
    All the best...

    Regards,
    Sriram.V
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Having "Cannot find symbol" and "Class, Interface, Enum Expected" Errors still
     
    Similar Threads
    Error in calculation
    Noob java assigment
    try...catch blocks giving <identifier> expected error
    Help with GPA calculator program
    I dont get the "get and set" method for my homework