Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Problem converting char from string to double

807598Oct 2 2006 — edited Oct 3 2006
I am trying to make a program where the user will enter in 4 letter grades, and then it will calculate your gpa, but the user is only prompted once to enter in all the letter grades.

this is what i have



import java.util.*;

public class assignment3b {
public static void main(String[ ] args) {
Scanner input = new Scanner(System.in);

System.out.println("Enter 4 letter grades with no spaces, and in UPPERCASE (ABCD)");
String x ;
x = input.next();


char A, B, C, D, F;
double gpa, grade1, grade2, grade3, grade4 ;

{
if (x.charAt(0).equals('A'))
grade1 = 4.0;
else
if (x.charAt(0).equals('B'))
grade1 = 3.0;

else if (x.charAt(0).equals('C'))
grade1 = 2.0;

else if (x.charAt(0).equals('D'))
grade1 = 1.0;

else if (x.charAt(0).equals('F'))
grade1 = 0.0;
else

System.out.println("grade not valid ");
}

gpa = ((grade1 + grade2 + grade3 + grade4) / 4);

System.out.println("Your grade point average is " + gpa);
}
}


i keep getting this error
assignment3b.java:19: char cannot be dereferenced
if (x.charAt(0).equals('A'))
^
assignment3b.java:22: char cannot be dereferenced
if (x.charAt(0).equals('B'))
^
assignment3b.java:25: char cannot be dereferenced
else if (x.charAt(0).equals('C'))
^
assignment3b.java:28: char cannot be dereferenced
else if (x.charAt(0).equals('D'))
^
assignment3b.java:31: char cannot be dereferenced
else if (x.charAt(0).equals('F'))
^
5 errors



if anyone can look at this i would really be grateful, im just so lost now
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 31 2006
Added on Oct 2 2006
9 comments
281 views