944,142 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 2957
  • Java RSS
Jun 26th, 2006
0

illegal start of expression

Expand Post »
ive been searching through at least 5 different forums on various sites (including this one) and i still cant understand why i'm getting the error message illegal start of expression at

Java Syntax (Toggle Plain Text)
  1. public static overallNumGrade(int quiz1, int quiz2, int quiz3)

here is the full program:
Java Syntax (Toggle Plain Text)
  1. import java.util.scanner;
  2. public class Jungmichel3
  3. {
  4. public static void main(String[] args)
  5. {
  6. int quizzes;
  7. int midterm;
  8. int finalTestGrade;
  9. int finalNumGrade;
  10. char letterGrade;
  11.  
  12. public static overallNumGrade(int quiz1, int quiz2, int quiz3)
  13. {
  14. System.out.println("Please enter grade from quiz 1:");
  15. System.out.println("Please enter grade from quiz 2:");
  16. System.out.println("Please enter grade from quiz 3:");
  17. Scanner keyboard = new Scanner(System.in);
  18. quiz1 = keyboard.nextInt();
  19. quiz2 = keyboard.nextInt();
  20. quiz3 = keyboard.nextInt();
  21. quizzes = (quiz1*.833 + qui2*.833 + quiz3*.833);
  22.  
  23. System.out.println();
  24. System.out.println("Please enter the midterm grade:");
  25. midterm = keyboard.nextInt();
  26. System.out.println();
  27. System.out.println("Please enter the final grade:");
  28. finalTestGrade = keyboard.nextInt();
  29. finalNumGrade = (quizzes*.25) + (midterm*.35) + (finalTestGrade*.40);
  30. System.out.println("The final numerical grade is " + finalNumGrade);
  31. }
  32. public static letterGrade(char A, char B, char C, char D)
  33. {
  34. if ( (finalNumGrade <= 100) && (finalNumGrade >= 90) )
  35. {
  36. System.out.println("The letter grade is an A");
  37. lettergrade = A;
  38. }
  39. else if ( (finalNumGrade <= 89) && (finalNumGrade >= 80) )
  40. {
  41. System.out.println("The letter grade is a B");
  42. lettergrade = B;
  43. }
  44. else if ( (finalNumGrade <= 79) && (finalNumGrade >= 70) )
  45. {
  46. System.out.println("The letter grade is a C");
  47. lettergrade = C;
  48. }
  49. else if ( (finalNumGrade <= 89) && (finalNumGrade >= 80) )
  50. {
  51. System.out.println("The letter grade is a D");
  52. lettergrade = D;
  53. }
  54. else
  55. {
  56. System.out.println("ERROR: The number grade does not compute.");
  57. }
  58. };
  59. }
  60. }

i know it has something to do with nesting a method inside another method... but im really confused. could someone help me and explain it to me in laymen's terms? thanks ahead of time!

-lauren
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ljungmichel is offline Offline
4 posts
since Jun 2006
Jun 27th, 2006
0

Re: illegal start of expression

you don't have a closing brace at the end of your main method, or
you are trying to declare that method within your main method, which you cannot do.
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006
Jun 27th, 2006
0

Re: illegal start of expression

hey there..

i think u typed a semicolon at the end of the letterGrade class..

plz check it out..if it solves the issue!!
Reputation Points: 10
Solved Threads: 1
Newbie Poster
psodhi is offline Offline
11 posts
since Mar 2006
Jun 27th, 2006
0

Re: illegal start of expression

im pretty sure i have that closing brace after my main method... unless i need to place it literally right after the main method instead of at the end of the program. and as for declaring the method inside the other method... i know thats my problem, i just dont know how to fix it... since i need both of those methods. which is why im so confused.

no i actually typed that semicolon on purpose... it seems to take away an error message that i get when it isnt there. it tells me that im missing a semicolon on that line for some reason. but thanks
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ljungmichel is offline Offline
4 posts
since Jun 2006
Jun 27th, 2006
0

Re: illegal start of expression

This should be a quick fix (I have not tried to compile):
Java Syntax (Toggle Plain Text)
  1. import java.util.scanner;
  2. public class Jungmichel3
  3. {
  4. int quizzes;
  5. int midterm;
  6. int finalTestGrade;
  7. int finalNumGrade;
  8. char letterGrade;
  9.  
  10. public void overallNumGrade()
  11. {
  12. System.out.println("Please enter grade from quiz 1:");
  13. System.out.println("Please enter grade from quiz 2:");
  14. System.out.println("Please enter grade from quiz 3:");
  15. Scanner keyboard = new Scanner(System.in);
  16. int quiz1 = keyboard.nextInt();
  17. int quiz2 = keyboard.nextInt();
  18. int quiz3 = keyboard.nextInt();
  19. quizzes = (quiz1*.833 + qui2*.833 + quiz3*.833);
  20.  
  21. System.out.println();
  22. System.out.println("Please enter the midterm grade:");
  23. midterm = keyboard.nextInt();
  24. System.out.println();
  25. System.out.println("Please enter the final grade:");
  26. finalTestGrade = keyboard.nextInt();
  27. finalNumGrade = (quizzes*.25) + (midterm*.35) + (finalTestGrade*.40);
  28. System.out.println("The final numerical grade is " + finalNumGrade);
  29. }
  30. public void letterGrade()
  31. {
  32. if ( (finalNumGrade <= 100) && (finalNumGrade >= 90) )
  33. {
  34. System.out.println("The letter grade is an A");
  35. lettergrade = 'A';
  36. }
  37. else if ( (finalNumGrade <= 89) && (finalNumGrade >= 80) )
  38. {
  39. System.out.println("The letter grade is a B");
  40. lettergrade = 'B';
  41. }
  42. else if ( (finalNumGrade <= 79) && (finalNumGrade >= 70) )
  43. {
  44. System.out.println("The letter grade is a C");
  45. lettergrade = 'C';
  46. }
  47. else if ( (finalNumGrade <= 89) && (finalNumGrade >= 80) )
  48. {
  49. System.out.println("The letter grade is a D");
  50. lettergrade = 'D';
  51. }
  52. else
  53. {
  54. System.out.println("ERROR: The number grade does not compute.");
  55. }
  56. }
  57. public static void main(String[] args)
  58. {
  59. Jungmichel3 a = new Jungmichel3();
  60. a.overallNumGrade();
  61. a.letterGrade();
  62. }
  63. }
Pay attention to the differences. These are the main points in a simple
class that you should pay attention to. It should not, however, rely on
class variables as it does, though. There are other ways to fix the
program, but this was the quickest. P.S. I did not truely pay attention to
what was going on inside the methods, so this is not necessarily a
functional program, but the problem you are currently having, should be
fixed.
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006
Jun 27th, 2006
0

Re: illegal start of expression

Quote originally posted by ljungmichel ...
im pretty sure i have that closing brace after my main method... unless i need to place it literally right after the main method instead of at the end of the program. and as for declaring the method inside the other method... i know thats my problem, i just dont know how to fix it... since i need both of those methods. which is why im so confused.

close the main method as suggested. It's Java law. Now call the method you need from the main method. Remember, It's a static method so it doesn't require an object reference to the class to be called.

no i actually typed that semicolon on purpose... it seems to take away an error message that i get when it isnt there. it tells me that im missing a semicolon on that line for some reason. but thanks

I believe the compiler thinks you are trying to use an anoymous class with your main method. That is why it is asking for the semicolon.
good luck!!!
Reputation Points: 10
Solved Threads: 2
Light Poster
DaSogo is offline Offline
25 posts
since May 2006
Jun 27th, 2006
0

Re: illegal start of expression

ok that works! thanks! but now i'm getting an error message that says
Java Syntax (Toggle Plain Text)
  1. E:\Java\week 2\Jungmichel3.java:70: '.class' expected
  2. a.overallNumGrade (int quiz1, int quiz2, int quiz3);
  3. ^
  4. E:\Java\week 2\Jungmichel3.java:70: ')' expected
  5. a.overallNumGrade (int quiz1, int quiz2, int quiz3);
  6. ^
i can't seem to find any missing parenthases or semicolons or anything...

Java Syntax (Toggle Plain Text)
  1. import java.util.Scanner;
  2.  
  3. public class Jungmichel3
  4. {
  5.  
  6. double quizzes;
  7. int midterm;
  8. int finalTestGrade;
  9. int finalNumGrade;
  10. char letterGrade;
  11.  
  12.  
  13. public int overallNumGrade(int quiz1, int quiz2, int quiz3)
  14. {
  15. System.out.println("Please enter grade from quiz 1:");
  16. System.out.println("Please enter grade from quiz 2:");
  17. System.out.println("Please enter grade from quiz 3:");
  18. Scanner keyboard = new Scanner(System.in);
  19. quiz1 = keyboard.nextInt();
  20. quiz2 = keyboard.nextInt();
  21. quiz3 = keyboard.nextInt();
  22. quizzes = ((quiz1*10)*.0833)+((quiz2*10)*.0833)+((quiz3*10)*.0833);
  23.  
  24.  
  25. System.out.println();
  26. System.out.println("Please enter the midterm grade:");
  27. midterm = keyboard.nextInt();
  28.  
  29. System.out.println();
  30. System.out.println("Please enter the final grade:");
  31. finalTestGrade = keyboard.nextInt();
  32.  
  33. finalNumGrade = (quizzes*.25) + (midterm*.35) + (finalTestGrade*.40);
  34.  
  35. System.out.println("The final numerical grade is " + finalNumGrade);
  36. }
  37.  
  38. public char letterGrade()
  39. {
  40.  
  41. if ( (finalNumGrade <= 100) && (finalNumGrade >= 90) )
  42. {
  43. System.out.println("The letter grade is an A");
  44.  
  45. }
  46. else if ( (finalNumGrade <= 89) && (finalNumGrade >= 80) )
  47. {
  48. System.out.println("The letter grade is a B");
  49.  
  50. }
  51. else if ( (finalNumGrade <= 79) && (finalNumGrade >= 70) )
  52. {
  53. System.out.println("The letter grade is a C");
  54.  
  55. }
  56. else if ( (finalNumGrade <= 89) && (finalNumGrade >= 80) )
  57. {
  58. System.out.println("The letter grade is a D");
  59.  
  60. }
  61. else
  62. {
  63. System.out.println("ERROR: The number grade does not compute.");
  64. }
  65. }
  66.  
  67. public void main(String[] args)
  68. {
  69. Jungmichel3 a = new Jungmichel3();
  70. a.overallNumGrade(int quiz1, int quiz2, int quiz3);
  71. a.letterGrade();
  72. }
  73. }
i already had to turn this prorgam in, so i know for a fact i didnt do well on it but i would still appreciate any help on resolving my issue. im trying so incredibly hard to understand java but i cant seem to get it. it takes up allllll of my free time! lol
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ljungmichel is offline Offline
4 posts
since Jun 2006
Jun 28th, 2006
0

Re: illegal start of expression

Look back at the code I posted again. I had "played around" with these quiz variables a little. Also, when calling a method, you provide only defined variables as parameters without a type declaration preceeding them. It is in a method declaration that variable types and names are provided.
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006
Jun 30th, 2006
0

Re: illegal start of expression

ok thanks! i think i understand now
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ljungmichel is offline Offline
4 posts
since Jun 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Struts / Database connection
Next Thread in Java Forum Timeline: hi





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC