illegal start of expression

Reply

Join Date: Jun 2006
Posts: 4
Reputation: ljungmichel is an unknown quantity at this point 
Solved Threads: 0
ljungmichel ljungmichel is offline Offline
Newbie Poster

illegal start of expression

 
0
  #1
Jun 26th, 2006
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

  1. public static overallNumGrade(int quiz1, int quiz2, int quiz3)

here is the full program:
  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
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,341
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 250
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: illegal start of expression

 
0
  #2
Jun 27th, 2006
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.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 11
Reputation: psodhi is an unknown quantity at this point 
Solved Threads: 1
psodhi psodhi is offline Offline
Newbie Poster

Re: illegal start of expression

 
0
  #3
Jun 27th, 2006
hey there..

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

plz check it out..if it solves the issue!!
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 4
Reputation: ljungmichel is an unknown quantity at this point 
Solved Threads: 0
ljungmichel ljungmichel is offline Offline
Newbie Poster

Re: illegal start of expression

 
0
  #4
Jun 27th, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,341
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 250
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: illegal start of expression

 
0
  #5
Jun 27th, 2006
This should be a quick fix (I have not tried to compile):
  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.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 25
Reputation: DaSogo is an unknown quantity at this point 
Solved Threads: 2
DaSogo DaSogo is offline Offline
Light Poster

Re: illegal start of expression

 
0
  #6
Jun 27th, 2006
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!!!
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 4
Reputation: ljungmichel is an unknown quantity at this point 
Solved Threads: 0
ljungmichel ljungmichel is offline Offline
Newbie Poster

Re: illegal start of expression

 
0
  #7
Jun 27th, 2006
ok that works! thanks! but now i'm getting an error message that says
  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...

  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
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,341
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 250
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: illegal start of expression

 
0
  #8
Jun 28th, 2006
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.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 4
Reputation: ljungmichel is an unknown quantity at this point 
Solved Threads: 0
ljungmichel ljungmichel is offline Offline
Newbie Poster

Re: illegal start of expression

 
0
  #9
Jun 30th, 2006
ok thanks! i think i understand now
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC