• 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

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

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!

 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.




 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).

 
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
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
    Posts: 109
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator



    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
    Posts: 6
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
    Posts: 109
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
     
    Consider Paul's rocket mass heater.
    reply
      Bookmark Topic Watch Topic
    • New Topic