| | |
illegal start of expression
![]() |
•
•
Join Date: Jun 2006
Posts: 4
Reputation:
Solved Threads: 0
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
here is the full program:
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
Java Syntax (Toggle Plain Text)
public static overallNumGrade(int quiz1, int quiz2, int quiz3)
here is the full program:
Java Syntax (Toggle Plain Text)
import java.util.scanner; public class Jungmichel3 { public static void main(String[] args) { int quizzes; int midterm; int finalTestGrade; int finalNumGrade; char letterGrade; public static overallNumGrade(int quiz1, int quiz2, int quiz3) { System.out.println("Please enter grade from quiz 1:"); System.out.println("Please enter grade from quiz 2:"); System.out.println("Please enter grade from quiz 3:"); Scanner keyboard = new Scanner(System.in); quiz1 = keyboard.nextInt(); quiz2 = keyboard.nextInt(); quiz3 = keyboard.nextInt(); quizzes = (quiz1*.833 + qui2*.833 + quiz3*.833); System.out.println(); System.out.println("Please enter the midterm grade:"); midterm = keyboard.nextInt(); System.out.println(); System.out.println("Please enter the final grade:"); finalTestGrade = keyboard.nextInt(); finalNumGrade = (quizzes*.25) + (midterm*.35) + (finalTestGrade*.40); System.out.println("The final numerical grade is " + finalNumGrade); } public static letterGrade(char A, char B, char C, char D) { if ( (finalNumGrade <= 100) && (finalNumGrade >= 90) ) { System.out.println("The letter grade is an A"); lettergrade = A; } else if ( (finalNumGrade <= 89) && (finalNumGrade >= 80) ) { System.out.println("The letter grade is a B"); lettergrade = B; } else if ( (finalNumGrade <= 79) && (finalNumGrade >= 70) ) { System.out.println("The letter grade is a C"); lettergrade = C; } else if ( (finalNumGrade <= 89) && (finalNumGrade >= 80) ) { System.out.println("The letter grade is a D"); lettergrade = D; } else { System.out.println("ERROR: The number grade does not compute."); } }; } }
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
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.
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
----------------------------------------------
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
•
•
Join Date: Jun 2006
Posts: 4
Reputation:
Solved Threads: 0
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
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
This should be a quick fix (I have not tried to compile):
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 Syntax (Toggle Plain Text)
import java.util.scanner; public class Jungmichel3 { int quizzes; int midterm; int finalTestGrade; int finalNumGrade; char letterGrade; public void overallNumGrade() { System.out.println("Please enter grade from quiz 1:"); System.out.println("Please enter grade from quiz 2:"); System.out.println("Please enter grade from quiz 3:"); Scanner keyboard = new Scanner(System.in); int quiz1 = keyboard.nextInt(); int quiz2 = keyboard.nextInt(); int quiz3 = keyboard.nextInt(); quizzes = (quiz1*.833 + qui2*.833 + quiz3*.833); System.out.println(); System.out.println("Please enter the midterm grade:"); midterm = keyboard.nextInt(); System.out.println(); System.out.println("Please enter the final grade:"); finalTestGrade = keyboard.nextInt(); finalNumGrade = (quizzes*.25) + (midterm*.35) + (finalTestGrade*.40); System.out.println("The final numerical grade is " + finalNumGrade); } public void letterGrade() { if ( (finalNumGrade <= 100) && (finalNumGrade >= 90) ) { System.out.println("The letter grade is an A"); lettergrade = 'A'; } else if ( (finalNumGrade <= 89) && (finalNumGrade >= 80) ) { System.out.println("The letter grade is a B"); lettergrade = 'B'; } else if ( (finalNumGrade <= 79) && (finalNumGrade >= 70) ) { System.out.println("The letter grade is a C"); lettergrade = 'C'; } else if ( (finalNumGrade <= 89) && (finalNumGrade >= 80) ) { System.out.println("The letter grade is a D"); lettergrade = 'D'; } else { System.out.println("ERROR: The number grade does not compute."); } } public static void main(String[] args) { Jungmichel3 a = new Jungmichel3(); a.overallNumGrade(); a.letterGrade(); } }
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
----------------------------------------------
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
•
•
Join Date: May 2006
Posts: 25
Reputation:
Solved Threads: 2
•
•
•
•
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.
•
•
Join Date: Jun 2006
Posts: 4
Reputation:
Solved Threads: 0
ok that works! thanks! but now i'm getting an error message that says
i can't seem to find any missing parenthases or semicolons or anything...
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
Java Syntax (Toggle Plain Text)
E:\Java\week 2\Jungmichel3.java:70: '.class' expected a.overallNumGrade (int quiz1, int quiz2, int quiz3); ^ E:\Java\week 2\Jungmichel3.java:70: ')' expected a.overallNumGrade (int quiz1, int quiz2, int quiz3); ^
Java Syntax (Toggle Plain Text)
import java.util.Scanner; public class Jungmichel3 { double quizzes; int midterm; int finalTestGrade; int finalNumGrade; char letterGrade; public int overallNumGrade(int quiz1, int quiz2, int quiz3) { System.out.println("Please enter grade from quiz 1:"); System.out.println("Please enter grade from quiz 2:"); System.out.println("Please enter grade from quiz 3:"); Scanner keyboard = new Scanner(System.in); quiz1 = keyboard.nextInt(); quiz2 = keyboard.nextInt(); quiz3 = keyboard.nextInt(); quizzes = ((quiz1*10)*.0833)+((quiz2*10)*.0833)+((quiz3*10)*.0833); System.out.println(); System.out.println("Please enter the midterm grade:"); midterm = keyboard.nextInt(); System.out.println(); System.out.println("Please enter the final grade:"); finalTestGrade = keyboard.nextInt(); finalNumGrade = (quizzes*.25) + (midterm*.35) + (finalTestGrade*.40); System.out.println("The final numerical grade is " + finalNumGrade); } public char letterGrade() { if ( (finalNumGrade <= 100) && (finalNumGrade >= 90) ) { System.out.println("The letter grade is an A"); } else if ( (finalNumGrade <= 89) && (finalNumGrade >= 80) ) { System.out.println("The letter grade is a B"); } else if ( (finalNumGrade <= 79) && (finalNumGrade >= 70) ) { System.out.println("The letter grade is a C"); } else if ( (finalNumGrade <= 89) && (finalNumGrade >= 80) ) { System.out.println("The letter grade is a D"); } else { System.out.println("ERROR: The number grade does not compute."); } } public void main(String[] args) { Jungmichel3 a = new Jungmichel3(); a.overallNumGrade(int quiz1, int quiz2, int quiz3); a.letterGrade(); } }
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 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
----------------------------------------------
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
![]() |
Similar Threads
- illegal start of expression (Java)
- JAVA Illegal Start of Expression Error (Java)
- Fibonacci Recursion - Illegal Start of expression! (Java)
- Why illegal start of expression error? (Java)
- illegal start of expression (Java)
- Help on error message, illegal start an ';' expected (Java)
Other Threads in the Java Forum
- Previous Thread: Struts / Database connection
- Next Thread: hi
| Thread Tools | Search this Thread |
-xlint actionlistener android api applet application array arrays automation bi binary blackberry block bluetooth character class client code compile compiler component consumer database desktop developmenthelp eclipse error fractal freeze ftp game gameprogramming givemetehcodez graphics gui health html ide image integer j2me j2seprojects java javac javaee javaprojects jetbrains jni jpanel jtable julia learningresources lego linked linux list login loops mac main map method methods mobile netbeans notdisplaying number online printf problem program project properties qt recursion researchinmotion rotatetext rsa scanner screen server set singleton sms sort sql string swing system textfields threads time title tree tutorial-sample update variablebinding windows working xor






