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

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

here is the full program:

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

Recommended Answers

All 8 Replies

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.

hey there..

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

plz check it out..if it solves the issue!!

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 :)

This should be a quick fix (I have not tried to compile):

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();
    }
}

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.

Member Avatar for DaSogo

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!!!

ok that works! thanks! but now i'm getting an error message that says

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);
                                                                                          ^

i can't seem to find any missing parenthases or semicolons or anything...

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();
                }
}

i already had to turn this prorgam in, so i know for a fact i didnt do well on it :sad: 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.

ok thanks! i think i understand now

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.