Ok, this is really frustrating. According to the api, I can use the toString method to convert chars to strings so I can use the equals method to compare the strings. Problem code:
(inside a loop)
if (tempGrade.equals(validGrades[z])) {
found = true;
tempGrade and validGrades[] both contain chars, and I want to compare them.
I get this compile error when it's run like this:
src/java192/project3/GradePoint.java:46: char cannot be dereferenced
if (tempGrade.equals(validGrades[z])) {
^
If I try to use the toString method I get these errors with this code:
String tempGradeString = toString(tempGrade);
String validGradesString = toString(validGrades[z]);
if (tempGradeString.equals(validGradesString)) {
found = true;
src/java192/project3/GradePoint.java:44: toString() in java.lang.Object cannot b
e applied to (char)
String tempGradeString = toString(tempGrade);
^
src/java192/project3/GradePoint.java:45: toString() in java.lang.Object cannot b
e applied to (char)
String validGradesString = toString(validGrades[z]);
^
2 errors
Why can't Java just have a standard set of conversions to go between types?
Short of an answer to that, how can I get this comparison to work?
Aaron Parker
(inside a loop)
if (tempGrade.equals(validGrades[z])) {
found = true;
tempGrade and validGrades[] both contain chars, and I want to compare them.
I get this compile error when it's run like this:
src/java192/project3/GradePoint.java:46: char cannot be dereferenced
if (tempGrade.equals(validGrades[z])) {
^
If I try to use the toString method I get these errors with this code:
String tempGradeString = toString(tempGrade);
String validGradesString = toString(validGrades[z]);
if (tempGradeString.equals(validGradesString)) {
found = true;
src/java192/project3/GradePoint.java:44: toString() in java.lang.Object cannot b
e applied to (char)
String tempGradeString = toString(tempGrade);
^
src/java192/project3/GradePoint.java:45: toString() in java.lang.Object cannot b
e applied to (char)
String validGradesString = toString(validGrades[z]);
^
2 errors
Why can't Java just have a standard set of conversions to go between types?
Short of an answer to that, how can I get this comparison to work?
Aaron Parker