Error with if an if statement

I am creating a class that will represent a deck of cards. The rest of the program looks correct except the if statement. It says that there is an illegal start to the expression but i dont know how to fix it. Help would be appreciated.

public String getNumberorFace() {

//* This is an if statement

//* It is supposed to determine the value of the card

if (case == 1) {

return = "Ace";

} else if (case == 2) {

return = "2";

} else if (case == 3) {

return = "3";

} else if (case == 4) {

return = "4";

} else if (case == 5) {

return = "5";

} else if (case == 6) {

return = "6";

} else if (case == 7) {

return = "7";

} else if (case == 8) {

return = "8";

} else if (case == 9) {

return = "9";

} else if (case == 10) {

return = "10";

} else if (case == 11) {

return = "Jack";

} else if (case == 12) {

return = "Queen";

} else if (case == 13) {

return = "King";

} else {

return = "Card does not exist";

}

}

[1108 byte] By [student85a] at [2007-11-26 20:32:09]
# 1
Just stop there immediately and read this: http://java.sun.com/docs/books/tutorial/java/nutsandbolts/switch.html
Djaunla at 2007-7-10 1:22:31 > top of Java-index,Java Essentials,Java Programming...
# 2

1. case is a keyword. Did you really name a variable case?

2. One writes

return "string";

Not

return = "string";

You should read about Java: http://java.sun.com/docs/books/tutorial/java/index.html

DrLaszloJamfa at 2007-7-10 1:22:31 > top of Java-index,Java Essentials,Java Programming...
# 3
"case" is a reserved word in Java.~
yawmarka at 2007-7-10 1:22:31 > top of Java-index,Java Essentials,Java Programming...
# 4
> It says that there is an illegal> start to the expression but i dont know how to fix> it. what line does the error occur?
Bjava at 2007-7-10 1:22:31 > top of Java-index,Java Essentials,Java Programming...
# 5
> Just stop there immediately and read this:> > http://java.sun.com/docs/books/tutorial/java/nutsandbolts/switch.htmlI think in this case, an array of strings would be the least painful way to go...
DrLaszloJamfa at 2007-7-10 1:22:31 > top of Java-index,Java Essentials,Java Programming...
# 6

Wow as I edit my reply to point out the error in his return statements five people jump into the topic.

> > Just stop there immediately and read this:

> >

> >

> http://java.sun.com/docs/books/tutorial/java/nutsandbo

> lts/switch.html

>

> I think in this case, an array of strings would be

> the least painful way to go...

I would use an array as well, but I figured that would be too advanced for the OP at this point. Well, he can try. The switch statement just sucks imo.

Reading the tutorial would be the best way to go.

Djaunla at 2007-7-10 1:22:32 > top of Java-index,Java Essentials,Java Programming...
# 7

An array might be the way to go, but if not, at least eliminate the repetition where you can...

public String getFaceAsString() {

if (face > 1 && face < 11) {

return String.valueOf(face);

} else {

switch (face) {

case 1: return "Ace";

case 11: return "Jack";

case 12: return "Queen";

case 13: return "King";

default: return "Card does not exist";

}

}

}

~

yawmarka at 2007-7-10 1:22:32 > top of Java-index,Java Essentials,Java Programming...
# 8

public String getNumberorFace(int face) {

if (face == 1) {

return "Ace";

}

else if (face >= 2 && face <= 10) {

return String.valueOf(face);

}

else if (face == 11) {

return "Jack";

}

else if (face == 12) {

return "Queen";

}

else if (face == 13) {

return "King";

}

else {

return "Card does not exist";

}

}

I couldn't help it... :)

hunter9000a at 2007-7-10 1:22:32 > top of Java-index,Java Essentials,Java Programming...