# Calculate GPA

Show 40 post(s) from this thread on one page
Page 1 of 2 12 Last
• 06-25-2012, 08:14 PM
thessler1
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 ( );
count = 0;

+ " 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: ");

if (grade == 'A' || grade == 'a') {
count++;
}
if (grade == 'B' || grade == 'b') {
count++;
}
if (grade == 'C' || grade == 'c') {
count++;
}
if (grade == 'D' || grade == 'd') {
count++;
}
if (grade == 'F' || grade == 'f') {
count++;
}
if (grade == 'X' || grade == 'x')
break;

}
}
public double CalculateGPA ( )
{

}

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.
• 06-25-2012, 08:45 PM
Norm
Re: Calculate GPA
Check that all the {s have a matching }
• 06-25-2012, 08:58 PM
thessler1
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 ( );
^
location: class CalculateGPA
CalculateGPA.java:13: error: cannot find symbol
TextReader console = new TextReader ( );
^
location: class CalculateGPA
CalculateGPA.java:14: error: cannot find symbol
^
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
^
location: class CalculateGPA
CalculateGPA.java:24: error: cannot find symbol
^
location: class CalculateGPA
CalculateGPA.java:24: error: cannot find symbol
^
location: class CalculateGPA
CalculateGPA.java:26: error: cannot find symbol
if (grade == 'A' || grade == 'a')
^
location: class CalculateGPA
CalculateGPA.java:26: error: cannot find symbol
if (grade == 'A' || grade == 'a')
^
location: class CalculateGPA
CalculateGPA.java:28: error: cannot find symbol
^
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')
^
location: class CalculateGPA
CalculateGPA.java:31: error: cannot find symbol
if (grade == 'B' || grade == 'b')
^
location: class CalculateGPA
CalculateGPA.java:33: error: cannot find symbol
^
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')
^
location: class CalculateGPA
CalculateGPA.java:36: error: cannot find symbol
if (grade == 'C' || grade == 'c')
^
location: class CalculateGPA
CalculateGPA.java:38: error: cannot find symbol
^
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')
^
location: class CalculateGPA
CalculateGPA.java:41: error: cannot find symbol
if (grade == 'D' || grade == 'd')
^
location: class CalculateGPA
CalculateGPA.java:43: error: cannot find symbol
^
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')
^
location: class CalculateGPA
CalculateGPA.java:46: error: cannot find symbol
if (grade == 'F' || grade == 'f')
^
location: class CalculateGPA
CalculateGPA.java:48: error: cannot find symbol
^
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')
^
location: class CalculateGPA
CalculateGPA.java:51: error: cannot find symbol
if (grade == 'X' || grade == 'x')
^
location: class CalculateGPA
CalculateGPA.java:58: error: cannot find symbol
^
location: class CalculateGPA
CalculateGPA.java:58: error: cannot find symbol
^
symbol: variable count
location: class CalculateGPA
31 errors

----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.
• 06-25-2012, 09:05 PM
Norm
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.
• 06-25-2012, 09:12 PM
thessler1
Re: Calculate GPA
import java.util.Scanner;

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

+ " 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: ");

{
if (grade == 'A' || grade == 'a')
{
count++;
}
if (grade == 'B' || grade == 'b')
{
count++;
}
if (grade == 'C' || grade == 'c')
{
count++;
}
if (grade == 'D' || grade == 'd')
{
count++;
}
if (grade == 'F' || grade == 'f')
{
count++;
}
if (grade == 'X' || grade == 'x')
break;

}
}
public double CalculateGPA ( )
{
}
}

ERROR:
CalculateGPA.java:13: error: cannot find symbol
TextReader console = new TextReader ( );
^
location: class CalculateGPA
CalculateGPA.java:13: error: cannot find symbol
TextReader console = new TextReader ( );
^
location: class CalculateGPA
CalculateGPA.java:14: error: cannot find symbol
^
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
^
location: class CalculateGPA
CalculateGPA.java:24: error: cannot find symbol
^
location: class CalculateGPA
CalculateGPA.java:24: error: cannot find symbol
^
location: class CalculateGPA
CalculateGPA.java:26: error: cannot find symbol
if (grade == 'A' || grade == 'a')
^
location: class CalculateGPA
CalculateGPA.java:26: error: cannot find symbol
if (grade == 'A' || grade == 'a')
^
location: class CalculateGPA
CalculateGPA.java:28: error: cannot find symbol
^
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')
^
location: class CalculateGPA
CalculateGPA.java:31: error: cannot find symbol
if (grade == 'B' || grade == 'b')
^
location: class CalculateGPA
CalculateGPA.java:33: error: cannot find symbol
^
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')
^
location: class CalculateGPA
CalculateGPA.java:36: error: cannot find symbol
if (grade == 'C' || grade == 'c')
^
location: class CalculateGPA
CalculateGPA.java:38: error: cannot find symbol
^
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')
^
location: class CalculateGPA
CalculateGPA.java:41: error: cannot find symbol
if (grade == 'D' || grade == 'd')
^
location: class CalculateGPA
CalculateGPA.java:43: error: cannot find symbol
^
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')
^
location: class CalculateGPA
CalculateGPA.java:46: error: cannot find symbol
if (grade == 'F' || grade == 'f')
^
location: class CalculateGPA
CalculateGPA.java:48: error: cannot find symbol
^
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')
^
location: class CalculateGPA
CalculateGPA.java:51: error: cannot find symbol
if (grade == 'X' || grade == 'x')
^
location: class CalculateGPA
CalculateGPA.java:58: error: cannot find symbol
^
location: class CalculateGPA
CalculateGPA.java:58: error: cannot find symbol
^
symbol: variable count
location: class CalculateGPA
31 errors

----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.
• 06-25-2012, 09:13 PM
Yokomoko
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.

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);         } }```
• 06-25-2012, 09:32 PM
Yokomoko
Re: Calculate GPA
Let me know if you get this working. I too am at a loss as to what to do.
• 06-25-2012, 09:40 PM
thessler1
Re: Calculate GPA
I'm stuck too. I'll let you know thought.
• 06-25-2012, 09:42 PM
Norm
Re: Calculate GPA
Quote:

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.
• 06-25-2012, 09:45 PM
JosAH
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
• 06-25-2012, 09:52 PM
Yokomoko
Re: Calculate GPA
Thessler, maybe instead of this:
Code:

```if (grade == 'A' || grade == 'a') {       gradetotal += 4;       count++;       }```
Use this for all the if statements:
Code:

```          if (grade.equals( "A" ) || grade.equals( "a" ) )           {           gradetotal += 4;           count++;           }```
That removes a lot of errors for me
• 06-25-2012, 09:55 PM
thessler1
Re: Calculate GPA
Thank you for the help. I have it down to 2 errors now.
• 06-25-2012, 09:56 PM
Norm
Re: Calculate GPA
@Yokomoko You also could have changed the definition of grade to make it a char.
• 06-25-2012, 09:57 PM
thessler1
Re: Calculate GPA
Remove all the { and } between the letter grade section. I'm down to 2 errors now.
• 06-25-2012, 10:03 PM
Yokomoko
Re: Calculate GPA
I am still at 6. And when I changed grade to a char it jumped up to 16 errors.
• 06-25-2012, 10:09 PM
thessler1
Re: Calculate GPA
System.out.print ("\nList of grades: ");
if (grade == 'A' || grade == 'a')
count++;

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

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

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

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

if (grade == 'X' || grade == 'x')
break;
}
• 06-25-2012, 11:03 PM
thessler1
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 ( )
{
TextReader console = new TextReader ( );
double gradetotal = 0, count = 0;
+ " 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: ");
if (grade == 'A' || grade == 'a')
count++;

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

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

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

if (grade == 'F' || grade == 'f')
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.
• 06-25-2012, 11:31 PM
Yokomoko
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.
• 06-26-2012, 01:04 AM
Norm
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:
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
• 06-26-2012, 03:07 AM
Yokomoko
Re: Calculate GPA
Quote:

Originally Posted by Norm
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:
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:
Code:

`            return (gradetotal/(double)count);`
Show 40 post(s) from this thread on one page
Page 1 of 2 12 Last