tags:

views:

74

answers:

2

Ok, I'm working on a simple statement code and it works fine as long as the input matches, ie Upper Case. I found it to.UpperCase and it looks simple enough, but still no dice. my code:

public static void main(String[] args) {
//public static char toUpperCase(char LG) // If I put this in, it gives me 'illegal start of expression'

char LG;  // Reads a value of type char.
char UC;  // Uppercase value of LG

TextIO.putln("Enter the letter grade do you want converted to point value?");
TextIO.putln();
TextIO.putln("A, B, C, D, or F");

LG = TextIO.getlnChar();
UC = LG.toUpperCase(); //this errors out 'char cannot be dereferenced'

switch ( LG ) {
case 'A':

Thanks for the direction.

A: 

change your switch statement to use UC instead of LG

switch(UC)
Ben Rowe
+2  A: 

The toUpperCase method is one belonging to (at a minimum) the String or Character classes, you cannot execute it on a primitive char type. Try:

LG = Character.toUpperCase(LG);

See here for the gory details. Note particularly the shortcomings with respect to full Unicode support. You may be better of using strings instead although you should be okay with that sample code since you only allow A, B, C, D and F. What happened to E by the way?

And, as Ben rightly mentioned in his answer, you should switch on the variable holding the uppercased character rather than the original. In my line above, that's still LG since I see little reason for keeping the original.

paxdiablo
You all rock. I'm defiantly a newbie to Java and while I am getting some of it, the Devil is certainly in the details.Program is for associating A to 4.0, B to 3.0 and so on. As to why there are F's, but no E's, I'm again at a loss. My guess is that E is for Endearing or maybe Endowed (positive things) and F is for Flunking (which doesn’t sound very pleasant), but my reasoning has let me down a time or to. LOL
jjason89
Another note: From http://math.hws.edu/javanotes/c3/s6.html 3.6.1:"A switch statement allows you to test the value of an expression and, depending on that value, to jump directly to some location within the switch statement. Only expressions of certain types can be used. The value of the expression can be one of the primitive integer types int, short, or byte. It can be the primitive char type. Or, as we will see later in this section, it can be an enumuerated type. In particular, the expression cannot be a String or a real number."Which is why I used char am I off base?
jjason89
No, you're right, you use the primitive integral types for switch statements.
paxdiablo