Results 1 to 20 of 23
Thread: Calculate GPA
- 06-25-2012, 08:14 PM #1
Member
- Join Date
- Jun 2012
- Posts
- 16
- Rep Power
- 0
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.
- 06-25-2012, 08:45 PM #2
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.
- 06-25-2012, 08:58 PM #3
Member
- Join Date
- Jun 2012
- Posts
- 16
- Rep Power
- 0
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.
- 06-25-2012, 09:05 PM #4
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.
- 06-25-2012, 09:12 PM #5
Member
- Join Date
- Jun 2012
- Posts
- 16
- Rep Power
- 0
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.
- 06-25-2012, 09:13 PM #6
Member
- Join Date
- Jun 2012
- Posts
- 29
- Rep Power
- 0
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); } }
- 06-25-2012, 09:32 PM #7
Member
- Join Date
- Jun 2012
- Posts
- 29
- Rep Power
- 0
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 #8
Member
- Join Date
- Jun 2012
- Posts
- 16
- Rep Power
- 0
Re: Calculate GPA
I'm stuck too. I'll let you know thought.
- 06-25-2012, 09:42 PM #9
Re: Calculate GPA
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.you need to define your variables
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.
- 06-25-2012, 09:45 PM #10
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,400
- Blog Entries
- 7
- Rep Power
- 17
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,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 06-25-2012, 09:52 PM #11
Member
- Join Date
- Jun 2012
- Posts
- 29
- Rep Power
- 0
Re: Calculate GPA
Thessler, maybe instead of this:
Use this for all the if statements:Java Code:if (grade == 'A' || grade == 'a') { gradetotal += 4; count++; }
That removes a lot of errors for meJava Code:if (grade.equals( "A" ) || grade.equals( "a" ) ) { gradetotal += 4; count++; }
- 06-25-2012, 09:55 PM #12
Member
- Join Date
- Jun 2012
- Posts
- 16
- Rep Power
- 0
Re: Calculate GPA
Thank you for the help. I have it down to 2 errors now.
- 06-25-2012, 09:56 PM #13
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.
- 06-25-2012, 09:57 PM #14
Member
- Join Date
- Jun 2012
- Posts
- 16
- Rep Power
- 0
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 #15
Member
- Join Date
- Jun 2012
- Posts
- 29
- Rep Power
- 0
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 #16
Member
- Join Date
- Jun 2012
- Posts
- 16
- Rep Power
- 0
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;
}
- 06-25-2012, 11:03 PM #17
Member
- Join Date
- Jun 2012
- Posts
- 16
- Rep Power
- 0
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.
- 06-25-2012, 11:31 PM #18
Member
- Join Date
- Jun 2012
- Posts
- 29
- Rep Power
- 0
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 #19
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:It looks like the start of a method definition but is missing the body that would be inside of a pair of {}sJava Code:public double CalculateGPA ( )
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.
- 06-26-2012, 03:07 AM #20
Member
- Join Date
- Jun 2012
- Posts
- 29
- Rep Power
- 0
Similar Threads
-
Need help to calculate avg
By vavavoom1 in forum New To JavaReplies: 2Last Post: 04-02-2011, 07:42 PM -
fastest way to calculate the sum of 1 to x
By imorio in forum New To JavaReplies: 5Last Post: 11-07-2010, 10:47 PM -
Calculate Interest
By hacikho in forum New To JavaReplies: 4Last Post: 10-09-2010, 04:15 AM -
calculate fft
By ram.west in forum Advanced JavaReplies: 2Last Post: 08-27-2008, 03:05 AM -
Calculate what e1 and e2 should be
By Legoland in forum New To JavaReplies: 11Last Post: 07-02-2007, 06:01 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks