Results 1 to 3 of 3
  1. #1
    jbinx is offline Member
    Join Date
    Oct 2015
    Posts
    2
    Rep Power
    0

    Default Using java to determine a letter grade with any given number 0-100

    Okay so I am trying to create a class that can determine your letter grade (a,b,c,d,f) with a given number between 0-100.
    The grade scale I am using is as follows:

    A is >= 90
    B is >= 80 and <90
    C is >= 75 and <80
    D is >= 70 and <75
    F is <70

    And here is what I have so far:
    Grade Class:
    Java Code:
    import static java.lang.System.*;
    
    public class Grade
    {
        private int GradeA;
        public Grade(int a, int b, int c, int d, int f)
        {
            GradeA=a;
            GradeB=b;
            GradeC=c;
            GradeD=d;
            GradeF=f;
        }
        public void setGrade (int a, int b, int c, int d, int f)
        {
            GradeA= 90
            GradeB= >=80, <90;
            GradeC= >=75, <80;
            GradeD= >=70, <75;
            GradeF= <70;
        }    
    }
    and the runner class:
    Java Code:
    import static java.lang.System.*;
    
    import java.util.Scanner;
    
    public class GradeRunner
    
    {
    
    public static void main( String[] args )
    
    {
    
    Scanner keyboard = new Scanner(System.in);
    
    out.print("Enter a number grade :: ");
    
    int grade = keyboard.nextInt();
    
    Grade theGrade = new Grade(grade);
    
    out.println(theGrade);
    
    out.print("Enter a number grade :: ");
    
    grade = keyboard.nextInt();
    
    theGrade.setGrade(grade);
    
    out.println(theGrade);
    
    out.print("Enter a number grade :: ");
    
    grade = keyboard.nextInt();
    
    theGrade.setGrade(grade);
    
    out.println(theGrade);
    
    out.print("Enter a number grade :: ");
    
    grade = keyboard.nextInt();
    
    theGrade.setGrade(grade);
    
    out.println(theGrade);
    
    }
    
    }
    So currently when compiled as is (and it is far from done) I get the error "illegal start of expression" in public void setGrade. I'm not to sure what to do next so any guidance and/or help on the matter would be greatly appreciated! Thanks!

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Using java to determine a letter grade with any given number 0-100

    Your expressions in lines 16-20 are not valid (in fact, I am not certain how you arrived at that syntax). Here is an example of how you might do it:

    Java Code:
    if (grade >= 80 && grade < 90) {
        letterGrade = "B";
    }
    You may want to review the tutorials in my signature.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    benji2505 is offline Senior Member
    Join Date
    Sep 2014
    Location
    MA, USA
    Posts
    399
    Rep Power
    6

    Default Re: Using java to determine a letter grade with any given number 0-100

    why do you pass 5 integers into the Grade constructor? how does that relate to the instantiation in your runner class? I also have a feeling that there are numerous variables that haven't been declared in your code. what happens to results of more than 90 points?

Similar Threads

  1. Replies: 6
    Last Post: 09-15-2014, 02:01 AM
  2. to print a letter grade for a numerical GPA
    By 4uAngelique in forum New To Java
    Replies: 16
    Last Post: 04-14-2012, 08:01 AM
  3. Replies: 1
    Last Post: 02-26-2012, 07:10 AM
  4. Replies: 2
    Last Post: 06-01-2010, 09:37 AM
  5. Replies: 10
    Last Post: 02-20-2010, 08:25 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •