Results 1 to 17 of 17
Like Tree1Likes
  • 1 Post By shall

Thread: to print a letter grade for a numerical GPA

  1. #1
    4uAngelique is offline Member
    Join Date
    Apr 2012
    Posts
    13
    Rep Power
    0

    Default to print a letter grade for a numerical GPA

    to print a letter grade for a numerical GPA-doc-1.jpgto print a letter grade for a numerical GPA-doc-2.jpgto print a letter grade for a numerical GPA-doc-3.jpg
    Last edited by 4uAngelique; 04-14-2012 at 05:13 AM.

  2. #2
    SnakeDoc is offline Senior Member
    Join Date
    Apr 2012
    Posts
    129
    Rep Power
    0

    Default Re: to print a letter grade for a numerical GPA

    looks like homework to me ;-p

    you probably wont fine anyone here willing to do this for you.

    if you start working on this and post what code you have already, i'm sure lots of people would be willing to help you learn.

    just my 2 cents... ;-P

  3. #3
    4uAngelique is offline Member
    Join Date
    Apr 2012
    Posts
    13
    Rep Power
    0

    Default Re: to print a letter grade for a numerical GPA

    import java.util.Scanner;

    public class P1
    {
    public static void main( String args[] )
    {
    final int HI = 40;
    final int A = 37;
    final int B = 27;
    final int C = 17;
    final int D = 10;
    final int F = 00;

    char choice;
    int letter;
    int symbol;
    double num;
    int grade;
    Scanner scan = new Scanner(System.in);
    String inputStr = null;

    System.out.print( "Enter GPA (3.3): ");
    num = scan.nextDouble();

    while (num < 0)
    {
    System.out.print("ERROR: Enter a positive number);
    }
    while (num > 0)
    {
    System.out.printf
    ("Using if else, letter grade of GPA: %.1f is ", grade/10.0);

    int letter = console.nextInt();
    if (letter >= A) System.out.print("A");
    else if (letter >= B) System.out.print("B");
    else if (letter >= C) System.out.print("C");
    else if (letter >= D) System.out.print("D");
    else if (letter >= F) System.out.print("F");

    switch(grade/10.0)
    {
    case choice '40':
    System.out.println("++A");
    break;
    case choice '37 - 39':
    System.out.println("A-");
    break;
    case choice '33 - 36':
    System.out.println("B+");
    break;
    case choice '30 - 32':
    System.out.println("B");
    break;
    case choice '27 - 29':
    System.out.println("B-");
    break;
    case choice '23 - 28':
    System.out.println("C-");
    break;
    case choice '20 - 22':
    System.out.println("C");
    break;
    case choice '17 - 19':
    System.out.println("C-");
    break;
    case choice '10 - 16':
    System.out.println("D");
    break;
    case choice '00 - 09':
    System.out.println("F");
    break;
    }
    System.out.print("Want to calculate grades (y/n)? " );
    inputStr = scan.next();
    }
    while(choice ! = 'n' && choice != 'N');
    scan.close();
    System.exit(0);
    }

  4. #4
    4uAngelique is offline Member
    Join Date
    Apr 2012
    Posts
    13
    Rep Power
    0

    Default Re: to print a letter grade for a numerical GPA

    won't work at all and still working on it

  5. #5
    SnakeDoc is offline Senior Member
    Join Date
    Apr 2012
    Posts
    129
    Rep Power
    0

    Default Re: to print a letter grade for a numerical GPA

    and the problem your having? you must give some back story with whats going on and what you wish to accomplish... i'll just repeat... someone will not do this project for you to turn in. (trust me, i've asked before!!!!! lol)

    are you getting errors in compilation? will it not run? a logic problem? stuck someplace? whats going on?

    Thanks!

    EDIT: sorry, didn't see ur above post: ignore this one.

  6. #6
    4uAngelique is offline Member
    Join Date
    Apr 2012
    Posts
    13
    Rep Power
    0

    Default Re: to print a letter grade for a numerical GPA

    i am completely new do java and the error i have is basically the whole programming and i cannot even compile i started working on little chunks but still there will be errors

  7. #7
    SnakeDoc is offline Senior Member
    Join Date
    Apr 2012
    Posts
    129
    Rep Power
    0

    Default Re: to print a letter grade for a numerical GPA

    well... i'm pretty new too... so welcome to the club! :)

    For starters... when i attempt to compile ur program, i get a lot of errors related to ur

    Java Code:
    case choice '40':
    System.out.println("++A");
    break;
    case choice '37 - 39':
    System.out.println("A-");
    break;
    case choice '33 - 36':
    System.out.println("B+");
    break;
    case choice '30 - 32':
    System.out.println("B");
    break;
    case choice '27 - 29':
    System.out.println("B-");
    break;
    case choice '23 - 28':
    System.out.println("C-");
    break;
    case choice '20 - 22':
    System.out.println("C");
    break;
    case choice '17 - 19':
    System.out.println("C-");
    break;
    case choice '10 - 16':
    System.out.println("D");
    break;
    case choice '00 - 09':
    System.out.println("F");
    break;
    most of the errors state that java is expecting a ";" instead of a ":" at the end of ur "case choice" lines. dont knwo if that is what you intended or not... but may be a start.

    also, I do belive that java interprets a single ' differently than a double " ... so make sure u are using this correctly. I'm getting a lot of errors stating "error: unclosed character literal" which seems to me that java is attempting to read ur case choice line numnbers literly... isntead of into a string. (someone please correct me if i'm wrong).

    So maybe do this:

    Java Code:
    case choice "17 - 19";
    insted of

    Java Code:
    case choice '17 - 19':
    for example. mgiht be worth a try.

  8. #8
    4uAngelique is offline Member
    Join Date
    Apr 2012
    Posts
    13
    Rep Power
    0

    Default Re: to print a letter grade for a numerical GPA

    I tried doing it but it still gives the same error. I don't i have the template on the question so i am trying to follow the same all it want's is "if else" statement and then followed by "switch" statement to assign + and - sign to the grades. I completely created my own codes that doesn't even make sense and it's complete train wreck.
    I am still trying to solve the few chunks of it like first inserting the while loop and then moving on to if else statement.
    I am pretty sure the problem is in if else and switch commands.
    I really need someone who can guide my to connect the program correctly.
    My codes are completely wrong and I am working on complete new one again.

  9. #9
    shall is offline Senior Member
    Join Date
    Apr 2012
    Posts
    199
    Rep Power
    0

    Default Re: to print a letter grade for a numerical GPA

    I'm new to java also.

    Your switch case construct is incorrect. See The switch Statement (The Java™ Tutorials > Learning the Java Language > Language Basics).

    You should be using an if/if else/else construct instead of the switch/case construct:

    Java Code:
    computedGrade = grade/100.0
    
    if (computedGrade == 40.0)
    {
       System.out.println("++A");
    }
    else if (computedGrade >= 37 && computedGrade <= 39)
    {
       System.out.println("A-");
    }
    ...
    Also, change the while loop as follows:

    from

    Java Code:
    num = scan.nextDouble();
    
    while (num < 0)
    {
       System.out.print("ERROR: Enter a positive number);
    }
    to

    Java Code:
    do
    {
       num = scan.nextDouble();
    
       System.out.print("ERROR: Enter a positive number);
    } while (num < 0);
    Do the same type of thing for the other while loop

    Also, should the variable letter be grade?

    You'll want to divide grade by 100.0 and not 10.0
    sunde887 likes this.

  10. #10
    shall is offline Senior Member
    Join Date
    Apr 2012
    Posts
    199
    Rep Power
    0

    Default Re: to print a letter grade for a numerical GPA

    Sorry I made a mistake on do while loop.

    use instead:

    Java Code:
    num = scan.nextDouble();
     
    while (num < 0)
    {
       System.out.print("ERROR: Enter a positive number);
    
       num = scan.nextDouble();
    }

  11. #11
    4uAngelique is offline Member
    Join Date
    Apr 2012
    Posts
    13
    Rep Power
    0

    Default Re: to print a letter grade for a numerical GPA

    The reason i am dividing by 10 is because we trying to grade gpa for 0.0 to 4.0 and then assign '+' and '-' sign through "switch" statement

    Thank you shall, the grading assignment can be done by just if else but you also have to use switch statement which makes it harder.
    grading assignment can be done that way but you have to use switch statement in order to assign + and - sign to your grade

    she has one of the template given the template is pretty good only thing it is missing is if else and switch and i'm trying to figure out i tried couple of cases but i couldn't link it and you run into infinite loop all the time.

    Thank you again for your help

  12. #12
    4uAngelique is offline Member
    Join Date
    Apr 2012
    Posts
    13
    Rep Power
    0

    Default Re: to print a letter grade for a numerical GPA

    public class P1Test
    {
    public static void main( String args[] )
    {
    final int HI = 40;
    final int A = 37;
    final int B = 27;
    final int C = 17;
    final int D = 10;
    final int F = 00;

    char choice;
    int letter;
    int symbol;
    double num;
    int grade;
    Scanner scan = new Scanner(System.in);
    String inputStr = null;

    System.out.print( "Enter GPA (3.3): ");
    num = scan.nextDouble();

    while (num < 0)
    {
    System.out.print("ERROR: Enter a positive number");

    num = scan.nextDouble();
    }
    while (num > 0)
    {
    System.out.printf
    ("Using if else, letter grade of GPA: %.1f is ", grade/10.0);
    grade = (int)(num*10);
    if (letter >= HI) System.out.print("++A");
    else if (letter >= A) System.out.print("A");
    else if (letter >= B) System.out.print("B");
    else if (letter >= C) System.out.print("C");
    else if (letter >= D) System.out.print("D");
    else if (letter >= F) System.out.print("F");

    String letterString;
    switch(letter)
    {
    case '1':
    System.out.println("++A");
    break;
    case '7':
    case '8':
    case '9':
    System.out.println("-");
    break;
    case '3':
    case '4':
    case '5':
    case '6':
    System.out.println("+");
    break;
    }
    System.out.print("Want to calculate grades (y/n)? " );
    inputStr = scan.next();
    }
    while(choice != 'n' && choice != 'N');
    scan.close();
    System.exit(0);
    }
    }

  13. #13
    4uAngelique is offline Member
    Join Date
    Apr 2012
    Posts
    13
    Rep Power
    0

    Default Re: to print a letter grade for a numerical GPA

    the better version but i still have this 3 error

    P1Test.java:39: variable grade might not have been initialized
    ("Using if else, letter grade of GPA: %.1f is ", grade/10.0);
    ^
    P1Test.java:41: variable letter might not have been initialized
    if (letter >= HI) System.out.print("++A");
    ^
    P1Test.java:69: variable choice might not have been initialized
    while(choice != 'n' && choice != 'N');
    ^
    3 errors

  14. #14
    shall is offline Senior Member
    Join Date
    Apr 2012
    Posts
    199
    Rep Power
    0

    Default Re: to print a letter grade for a numerical GPA

    Just Initialize the variables:

    Java Code:
            char choice = 0;
            int letter = 0;
            int symbol;
            double num;
            int grade = 0;
    You might want to install and start using NetBeans (http://netbeans.org/downloads/). On that webpage, just select download from the all column. it can automatically correct some of these errors for you.

  15. #15
    4uAngelique is offline Member
    Join Date
    Apr 2012
    Posts
    13
    Rep Power
    0

    Default Re: to print a letter grade for a numerical GPA

    I just did the same thing the program run but do not give you the desire output.

    Thank you very much though
    Last edited by 4uAngelique; 04-14-2012 at 08:36 AM.

  16. #16
    shall is offline Senior Member
    Join Date
    Apr 2012
    Posts
    199
    Rep Power
    0

    Default Re: to print a letter grade for a numerical GPA

    Does your program have to follow the teacher's template?

    change your while loop and add a for loop as follows:

    Java Code:
            while (num < 0)
            {
                System.out.println("ERROR: Enter a positive number!");
                System.out.println("");
                System.out.println("Enter GPA (3.3): ");
    
                num = scan.nextDouble();
            }
    
            for (;;)
            {
                num /= 10;
                if (num <= 4.0)
                {
                    break;
                }
            }

  17. #17
    4uAngelique is offline Member
    Join Date
    Apr 2012
    Posts
    13
    Rep Power
    0

    Default Re: to print a letter grade for a numerical GPA

    teachers template is a working template; it's her way of doing it but you can use the same if you want

Similar Threads

  1. Allow only numerical input on JTextField
    By patriotsfan in forum AWT / Swing
    Replies: 3
    Last Post: 05-31-2011, 01:39 PM
  2. Defining numerical set in java
    By veronique in forum New To Java
    Replies: 8
    Last Post: 05-04-2011, 09:08 AM
  3. Replies: 0
    Last Post: 03-05-2011, 09:06 AM
  4. Replies: 1
    Last Post: 02-22-2011, 02:40 PM
  5. Reading Numerical Data
    By tyang in forum New To Java
    Replies: 1
    Last Post: 02-05-2010, 04:19 AM

Posting Permissions

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