Page 1 of 2 12 LastLast
Results 1 to 20 of 23
Like Tree1Likes

Thread: Calculate GPA

  1. #1
    thessler1 is offline Member
    Join Date
    Jun 2012
    Posts
    16
    Rep Power
    0

    Default Calculate GPA

    Having trouble with this problem:

    Create a program called CalculateGPA.java that asks the user to enter grades for each course of a given semester (such as A, B, C, D, F). Enter X to stop entering grades. The program should then calculate the GPA for the semester. Assume that each course has the same number of credit hours. Use the NumberFormat class to format the GPA to two decimal places. Use the Scanner class for input and the command window for output. Entering grades should be handled by one method and displaying the GPA by a different method. Use a switch statement to assign grade points for different grades.

    This is what I have so far followed by my error message when compiling.


    import java.util.Scanner;

    public class NetPay
    {
    public void GetGrades ( ) {
    TextReader console = new TextReader ( );
    gradetotal = 0;
    count = 0;

    System.out.print ("\n\nPlease enter your grades below, using"
    + " upper and/or lower case. Non-grade characters will"
    + " be disregarded and you should enter 'x' or 'X' to"
    + " exit.");
    System.out.print ("\nList of grades: ");
    grade = console.readChar ( );

    while (grade !='x' || grade!='X') {
    if (grade == 'A' || grade == 'a') {
    gradetotal += 4;
    count++;
    }
    if (grade == 'B' || grade == 'b') {
    gradetotal += 3;
    count++;
    }
    if (grade == 'C' || grade == 'c') {
    gradetotal += 2;
    count++;
    }
    if (grade == 'D' || grade == 'd') {
    gradetotal += 1;
    count++;
    }
    if (grade == 'F' || grade == 'f') {
    gradetotal += 0;
    count++;
    }
    if (grade == 'X' || grade == 'x')
    break;

    }
    }
    public double CalculateGPA ( )
    {
    return (gradetotal/(double)count);

    }

    ERROR MESSAGE:
    ----jGRASP exec: javac CalculateGPA.java

    CalculateGPA.java:53: error: reached end of file while parsing
    }
    ^
    1 error

    ----jGRASP wedge2: exit code for process is 1.
    ----jGRASP: operation complete.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: Calculate GPA

    Check that all the {s have a matching }
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    thessler1 is offline Member
    Join Date
    Jun 2012
    Posts
    16
    Rep Power
    0

    Default Re: Calculate GPA

    Not sure what I did, but now I'm getting all these errors and am not sure where to start.

    ----jGRASP exec: javac CalculateGPA.java

    CalculateGPA.java:13: error: cannot find symbol
    TextReader console = new TextReader ( );
    ^
    symbol: class TextReader
    location: class CalculateGPA
    CalculateGPA.java:13: error: cannot find symbol
    TextReader console = new TextReader ( );
    ^
    symbol: class TextReader
    location: class CalculateGPA
    CalculateGPA.java:14: error: cannot find symbol
    gradetotal = 0;
    ^
    symbol: variable gradetotal
    location: class CalculateGPA
    CalculateGPA.java:15: error: cannot find symbol
    count = 0;
    ^
    symbol: variable count
    location: class CalculateGPA
    CalculateGPA.java:22: error: cannot find symbol
    grade = console.readChar ( );
    ^
    symbol: variable grade
    location: class CalculateGPA
    CalculateGPA.java:24: error: cannot find symbol
    while (grade !='x' || grade!='X')
    ^
    symbol: variable grade
    location: class CalculateGPA
    CalculateGPA.java:24: error: cannot find symbol
    while (grade !='x' || grade!='X')
    ^
    symbol: variable grade
    location: class CalculateGPA
    CalculateGPA.java:26: error: cannot find symbol
    if (grade == 'A' || grade == 'a')
    ^
    symbol: variable grade
    location: class CalculateGPA
    CalculateGPA.java:26: error: cannot find symbol
    if (grade == 'A' || grade == 'a')
    ^
    symbol: variable grade
    location: class CalculateGPA
    CalculateGPA.java:28: error: cannot find symbol
    gradetotal += 4;
    ^
    symbol: variable gradetotal
    location: class CalculateGPA
    CalculateGPA.java:29: error: cannot find symbol
    count++;
    ^
    symbol: variable count
    location: class CalculateGPA
    CalculateGPA.java:31: error: cannot find symbol
    if (grade == 'B' || grade == 'b')
    ^
    symbol: variable grade
    location: class CalculateGPA
    CalculateGPA.java:31: error: cannot find symbol
    if (grade == 'B' || grade == 'b')
    ^
    symbol: variable grade
    location: class CalculateGPA
    CalculateGPA.java:33: error: cannot find symbol
    gradetotal += 3;
    ^
    symbol: variable gradetotal
    location: class CalculateGPA
    CalculateGPA.java:34: error: cannot find symbol
    count++;
    ^
    symbol: variable count
    location: class CalculateGPA
    CalculateGPA.java:36: error: cannot find symbol
    if (grade == 'C' || grade == 'c')
    ^
    symbol: variable grade
    location: class CalculateGPA
    CalculateGPA.java:36: error: cannot find symbol
    if (grade == 'C' || grade == 'c')
    ^
    symbol: variable grade
    location: class CalculateGPA
    CalculateGPA.java:38: error: cannot find symbol
    gradetotal += 2;
    ^
    symbol: variable gradetotal
    location: class CalculateGPA
    CalculateGPA.java:39: error: cannot find symbol
    count++;
    ^
    symbol: variable count
    location: class CalculateGPA
    CalculateGPA.java:41: error: cannot find symbol
    if (grade == 'D' || grade == 'd')
    ^
    symbol: variable grade
    location: class CalculateGPA
    CalculateGPA.java:41: error: cannot find symbol
    if (grade == 'D' || grade == 'd')
    ^
    symbol: variable grade
    location: class CalculateGPA
    CalculateGPA.java:43: error: cannot find symbol
    gradetotal += 1;
    ^
    symbol: variable gradetotal
    location: class CalculateGPA
    CalculateGPA.java:44: error: cannot find symbol
    count++;
    ^
    symbol: variable count
    location: class CalculateGPA
    CalculateGPA.java:46: error: cannot find symbol
    if (grade == 'F' || grade == 'f')
    ^
    symbol: variable grade
    location: class CalculateGPA
    CalculateGPA.java:46: error: cannot find symbol
    if (grade == 'F' || grade == 'f')
    ^
    symbol: variable grade
    location: class CalculateGPA
    CalculateGPA.java:48: error: cannot find symbol
    gradetotal += 0;
    ^
    symbol: variable gradetotal
    location: class CalculateGPA
    CalculateGPA.java:49: error: cannot find symbol
    count++;
    ^
    symbol: variable count
    location: class CalculateGPA
    CalculateGPA.java:51: error: cannot find symbol
    if (grade == 'X' || grade == 'x')
    ^
    symbol: variable grade
    location: class CalculateGPA
    CalculateGPA.java:51: error: cannot find symbol
    if (grade == 'X' || grade == 'x')
    ^
    symbol: variable grade
    location: class CalculateGPA
    CalculateGPA.java:58: error: cannot find symbol
    return (gradetotal/(double)count);
    ^
    symbol: variable gradetotal
    location: class CalculateGPA
    CalculateGPA.java:58: error: cannot find symbol
    return (gradetotal/(double)count);
    ^
    symbol: variable count
    location: class CalculateGPA
    31 errors

    ----jGRASP wedge2: exit code for process is 1.
    ----jGRASP: operation complete.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: Calculate GPA

    You'll have to post the new code that is causing the errors.
    Be sure to wrap the code in code tags:
    BB Code List - Java Programming Forum

    One thing I see: You need a definition for the TextReader class.

    Many of the other error messages are because the code does not define a variable.
    All variables used in a program must be defined so the compiler knows what datatype they are.
    Last edited by Norm; 06-25-2012 at 09:10 PM.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    thessler1 is offline Member
    Join Date
    Jun 2012
    Posts
    16
    Rep Power
    0

    Default Re: Calculate GPA

    import java.util.Scanner;

    public class CalculateGPA
    {
    public void GetGrades ( )
    {
    TextReader console = new TextReader ( );
    gradetotal = 0;
    count = 0;

    System.out.print ("\n\nPlease enter your grades below, using"
    + " upper and/or lower case. Non-grade characters will"
    + " be disregarded and you should enter 'x' or 'X' to"
    + " exit.");
    System.out.print ("\nList of grades: ");
    grade = console.readChar ( );

    while (grade !='x' || grade!='X')
    {
    if (grade == 'A' || grade == 'a')
    {
    gradetotal += 4;
    count++;
    }
    if (grade == 'B' || grade == 'b')
    {
    gradetotal += 3;
    count++;
    }
    if (grade == 'C' || grade == 'c')
    {
    gradetotal += 2;
    count++;
    }
    if (grade == 'D' || grade == 'd')
    {
    gradetotal += 1;
    count++;
    }
    if (grade == 'F' || grade == 'f')
    {
    gradetotal += 0;
    count++;
    }
    if (grade == 'X' || grade == 'x')
    break;

    }
    }
    public double CalculateGPA ( )
    {
    return (gradetotal/(double)count);
    }
    }

    ERROR:
    CalculateGPA.java:13: error: cannot find symbol
    TextReader console = new TextReader ( );
    ^
    symbol: class TextReader
    location: class CalculateGPA
    CalculateGPA.java:13: error: cannot find symbol
    TextReader console = new TextReader ( );
    ^
    symbol: class TextReader
    location: class CalculateGPA
    CalculateGPA.java:14: error: cannot find symbol
    gradetotal = 0;
    ^
    symbol: variable gradetotal
    location: class CalculateGPA
    CalculateGPA.java:15: error: cannot find symbol
    count = 0;
    ^
    symbol: variable count
    location: class CalculateGPA
    CalculateGPA.java:22: error: cannot find symbol
    grade = console.readChar ( );
    ^
    symbol: variable grade
    location: class CalculateGPA
    CalculateGPA.java:24: error: cannot find symbol
    while (grade !='x' || grade!='X')
    ^
    symbol: variable grade
    location: class CalculateGPA
    CalculateGPA.java:24: error: cannot find symbol
    while (grade !='x' || grade!='X')
    ^
    symbol: variable grade
    location: class CalculateGPA
    CalculateGPA.java:26: error: cannot find symbol
    if (grade == 'A' || grade == 'a')
    ^
    symbol: variable grade
    location: class CalculateGPA
    CalculateGPA.java:26: error: cannot find symbol
    if (grade == 'A' || grade == 'a')
    ^
    symbol: variable grade
    location: class CalculateGPA
    CalculateGPA.java:28: error: cannot find symbol
    gradetotal += 4;
    ^
    symbol: variable gradetotal
    location: class CalculateGPA
    CalculateGPA.java:29: error: cannot find symbol
    count++;
    ^
    symbol: variable count
    location: class CalculateGPA
    CalculateGPA.java:31: error: cannot find symbol
    if (grade == 'B' || grade == 'b')
    ^
    symbol: variable grade
    location: class CalculateGPA
    CalculateGPA.java:31: error: cannot find symbol
    if (grade == 'B' || grade == 'b')
    ^
    symbol: variable grade
    location: class CalculateGPA
    CalculateGPA.java:33: error: cannot find symbol
    gradetotal += 3;
    ^
    symbol: variable gradetotal
    location: class CalculateGPA
    CalculateGPA.java:34: error: cannot find symbol
    count++;
    ^
    symbol: variable count
    location: class CalculateGPA
    CalculateGPA.java:36: error: cannot find symbol
    if (grade == 'C' || grade == 'c')
    ^
    symbol: variable grade
    location: class CalculateGPA
    CalculateGPA.java:36: error: cannot find symbol
    if (grade == 'C' || grade == 'c')
    ^
    symbol: variable grade
    location: class CalculateGPA
    CalculateGPA.java:38: error: cannot find symbol
    gradetotal += 2;
    ^
    symbol: variable gradetotal
    location: class CalculateGPA
    CalculateGPA.java:39: error: cannot find symbol
    count++;
    ^
    symbol: variable count
    location: class CalculateGPA
    CalculateGPA.java:41: error: cannot find symbol
    if (grade == 'D' || grade == 'd')
    ^
    symbol: variable grade
    location: class CalculateGPA
    CalculateGPA.java:41: error: cannot find symbol
    if (grade == 'D' || grade == 'd')
    ^
    symbol: variable grade
    location: class CalculateGPA
    CalculateGPA.java:43: error: cannot find symbol
    gradetotal += 1;
    ^
    symbol: variable gradetotal
    location: class CalculateGPA
    CalculateGPA.java:44: error: cannot find symbol
    count++;
    ^
    symbol: variable count
    location: class CalculateGPA
    CalculateGPA.java:46: error: cannot find symbol
    if (grade == 'F' || grade == 'f')
    ^
    symbol: variable grade
    location: class CalculateGPA
    CalculateGPA.java:46: error: cannot find symbol
    if (grade == 'F' || grade == 'f')
    ^
    symbol: variable grade
    location: class CalculateGPA
    CalculateGPA.java:48: error: cannot find symbol
    gradetotal += 0;
    ^
    symbol: variable gradetotal
    location: class CalculateGPA
    CalculateGPA.java:49: error: cannot find symbol
    count++;
    ^
    symbol: variable count
    location: class CalculateGPA
    CalculateGPA.java:51: error: cannot find symbol
    if (grade == 'X' || grade == 'x')
    ^
    symbol: variable grade
    location: class CalculateGPA
    CalculateGPA.java:51: error: cannot find symbol
    if (grade == 'X' || grade == 'x')
    ^
    symbol: variable grade
    location: class CalculateGPA
    CalculateGPA.java:58: error: cannot find symbol
    return (gradetotal/(double)count);
    ^
    symbol: variable gradetotal
    location: class CalculateGPA
    CalculateGPA.java:58: error: cannot find symbol
    return (gradetotal/(double)count);
    ^
    symbol: variable count
    location: class CalculateGPA
    31 errors

    ----jGRASP wedge2: exit code for process is 1.
    ----jGRASP: operation complete.

  6. #6
    Yokomoko is offline Member
    Join Date
    Jun 2012
    Posts
    29
    Rep Power
    0

    Default Re: Calculate GPA

    I am currently working on the same problem. I believe you need to define your variables. I have started doing that and have gotten it down to 20 errors.

    Java Code:
    import java.util.Scanner;
    
    public class CalculateGPA
    {
    	public void GetGrades ( ) 
    	{
    	   String grade;
    	   TextReader console = new TextReader ( );
    	   Double gradetotal = 0, count = 0;
    
    	   System.out.print ("\n\nPlease enter your grades below, using"
    	   + " upper and/or lower case. Non-grade characters will"
    	   + " be disregarded and you should enter 'x' or 'X' to"
    	   + " exit.");
    	   System.out.print ("\nList of grades: ");
    	   grade = console.readChar ( );
    
    	   while (grade !='x' || grade!='X') {
    	   if (grade == 'A' || grade == 'a') {
    	   gradetotal += 4;
    	   count++;
    	   }
    	   if (grade == 'B' || grade == 'b') {
    	   gradetotal += 3;
    	   count++;
    	   }
    	   if (grade == 'C' || grade == 'c') {
    	   gradetotal += 2;
    	   count++;
    	   }
    	   if (grade == 'D' || grade == 'd') {
    	   gradetotal += 1;
    	   count++;
    	   }
    	   if (grade == 'F' || grade == 'f') {
    	   gradetotal += 0;
    	   count++;
    	   }
    	   if (grade == 'X' || grade == 'x')
    	   break;
    
    	   }
    	}
    	public double CalculateGPA ( )
    	{
    	return (gradetotal/(double)count);
    
    	}
    }

  7. #7
    Yokomoko is offline Member
    Join Date
    Jun 2012
    Posts
    29
    Rep Power
    0

    Default Re: Calculate GPA

    Let me know if you get this working. I too am at a loss as to what to do.

  8. #8
    thessler1 is offline Member
    Join Date
    Jun 2012
    Posts
    16
    Rep Power
    0

    Default Re: Calculate GPA

    I'm stuck too. I'll let you know thought.

  9. #9
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: Calculate GPA

    you need to define your variables
    Look at line 7 for an example of how to define a variable. It defines a variable of type String with a name of grade.

    Most of the "cannot find symbol" error messages are because the variable above the ^ is not defined.
    You need to add definitions for all those names with that error. Some are int and some are char. Look at how they are used to see which kind they are.
    If you don't understand my response, don't ignore it, ask a question.

  10. #10
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,371
    Blog Entries
    7
    Rep Power
    20

    Default Re: Calculate GPA

    Do you people actually try to read what the compiler has to say to you? If can't find a class TextReader and it can't find a couple of variables. The variables aren't declared anywhere and the TextReader class isn't imported anywhere.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  11. #11
    Yokomoko is offline Member
    Join Date
    Jun 2012
    Posts
    29
    Rep Power
    0

    Default Re: Calculate GPA

    Thessler, maybe instead of this:
    Java Code:
    if (grade == 'A' || grade == 'a') {
           gradetotal += 4;
           count++;
           }
    Use this for all the if statements:
    Java Code:
    	   if (grade.equals( "A" ) || grade.equals( "a" ) ) 
    	   {
    	   gradetotal += 4;
    	   count++;
    	   }
    That removes a lot of errors for me

  12. #12
    thessler1 is offline Member
    Join Date
    Jun 2012
    Posts
    16
    Rep Power
    0

    Default Re: Calculate GPA

    Thank you for the help. I have it down to 2 errors now.

  13. #13
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: Calculate GPA

    @Yokomoko You also could have changed the definition of grade to make it a char.
    If you don't understand my response, don't ignore it, ask a question.

  14. #14
    thessler1 is offline Member
    Join Date
    Jun 2012
    Posts
    16
    Rep Power
    0

    Default Re: Calculate GPA

    Remove all the { and } between the letter grade section. I'm down to 2 errors now.

  15. #15
    Yokomoko is offline Member
    Join Date
    Jun 2012
    Posts
    29
    Rep Power
    0

    Default Re: Calculate GPA

    I am still at 6. And when I changed grade to a char it jumped up to 16 errors.

  16. #16
    thessler1 is offline Member
    Join Date
    Jun 2012
    Posts
    16
    Rep Power
    0

    Default Re: Calculate GPA

    System.out.print ("\nList of grades: ");
    grade = console.readChar ( );
    while (grade !='x' || grade!='X')
    if (grade == 'A' || grade == 'a')
    gradetotal += 4;
    count++;

    if (grade == 'B' || grade == 'b')
    gradetotal += 3;
    count++;

    if (grade == 'C' || grade == 'c')
    gradetotal += 2;
    count++;

    if (grade == 'D' || grade == 'd')
    gradetotal += 1;
    count++;

    if (grade == 'F' || grade == 'f')
    gradetotal += 0;
    count++;

    if (grade == 'X' || grade == 'x')
    break;
    }

  17. #17
    thessler1 is offline Member
    Join Date
    Jun 2012
    Posts
    16
    Rep Power
    0

    Default Re: Calculate GPA

    This is what I have now. I have tried everything but can't get rid of the final error.
    import java.util.Scanner;
    public class CalculateGPA
    {
    public void GetGrades ( )
    {
    String grade;
    TextReader console = new TextReader ( );
    double gradetotal = 0, count = 0;
    System.out.print ("\n\nPlease enter your grades below, using"
    + " upper and/or lower case. Non-grade characters will"
    + " be disregarded and you should enter 'x' or 'X' to"
    + " exit.");
    System.out.print ("\nList of grades: ");
    grade = console.readChar ( );
    while (grade !='x' || grade!='X')
    if (grade == 'A' || grade == 'a')
    gradetotal += 4;
    count++;

    if (grade == 'B' || grade == 'b')
    gradetotal += 3;
    count++;

    if (grade == 'C' || grade == 'c')
    gradetotal += 2;
    count++;

    if (grade == 'D' || grade == 'd')
    gradetotal += 1;
    count++;

    if (grade == 'F' || grade == 'f')
    gradetotal += 0;
    count++;

    if (grade == 'X' || grade == 'x')
    break;
    }

    } //end main

    public double CalculateGPA ( )

    // end class

    ERROR:
    CalculateGPA.java:48: error: class, interface, or enum expected
    public double CalculateGPA ( )
    ^
    1 error

    ----jGRASP wedge2: exit code for process is 1.
    ----jGRASP: operation complete.

  18. #18
    Yokomoko is offline Member
    Join Date
    Jun 2012
    Posts
    29
    Rep Power
    0

    Default Re: Calculate GPA

    Yeah I can't get it to work either. I've tried changing it from double to class and nothing is working.

  19. #19
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: Calculate GPA

    Please edit you post and wrap the code in code tags:
    BB Code List - Java Programming Forum


    Check that the {}s are properly paired.

    What is this line for:
    Java Code:
    public double CalculateGPA ( )
    It looks like the start of a method definition but is missing the body that would be inside of a pair of {}s
    Last edited by Norm; 06-26-2012 at 01:06 AM.
    If you don't understand my response, don't ignore it, ask a question.

  20. #20
    Yokomoko is offline Member
    Join Date
    Jun 2012
    Posts
    29
    Rep Power
    0

    Default Re: Calculate GPA

    Quote Originally Posted by Norm View Post
    Please edit you post and wrap the code in code tags:
    BB Code List - Java Programming Forum


    Check that the {}s are properly paired.

    What is this line for:
    Java Code:
    public double CalculateGPA ( )
    It looks like the start of a method definition but is missing the body that would be inside of a pair of {}s
    I believe it is supposed to have this inside:
    Java Code:
    	    return (gradetotal/(double)count);

Page 1 of 2 12 LastLast

Similar Threads

  1. Need help to calculate avg
    By vavavoom1 in forum New To Java
    Replies: 2
    Last Post: 04-02-2011, 07:42 PM
  2. fastest way to calculate the sum of 1 to x
    By imorio in forum New To Java
    Replies: 5
    Last Post: 11-07-2010, 10:47 PM
  3. Calculate Interest
    By hacikho in forum New To Java
    Replies: 4
    Last Post: 10-09-2010, 04:15 AM
  4. calculate fft
    By ram.west in forum Advanced Java
    Replies: 2
    Last Post: 08-27-2008, 03:05 AM
  5. Calculate what e1 and e2 should be
    By Legoland in forum New To Java
    Replies: 11
    Last Post: 07-02-2007, 06:01 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
  •