0

Before I make any of the conditions for my app, I need to be able to let the switch statement run under the while loop. Its saying that it is unable to work under any compiler under 1.7. JRE. I don't know what that means and I also do not know how to change the variables to enum types.

package PokerApp;
import java.util.Scanner;
public class PokerApp {

    public static void main(String[] args) {

int card1 = 0;
int card2 = 0;
int play;
String fc1 = "", fc2 ="";
String answer = "";

Scanner scan = new Scanner(System.in);

//**************************************
//              Card1
//**************************************
System.out.println("Press 1 to evalaute your cards: ");
play = scan.nextInt();
while (play != 0){

System.out.println("First Card: ");
if (scan.hasNextInt())
{
    card1 = scan.nextInt(9)+2;
}
else{
    fc1 = scan.next();
    switch(fc1)
    {
    case "A":
        card1 = 14;
        break;
    case "K":
        card1 = 13;
        break;
    case "Q":
        card1 = 12;
        break;
    case "J":
        card1 = 11;
        break;
        default:System.out.println("Incvalid entry");
    }
//***************************************
//              Card2
//***************************************

System.out.println("Second card: ");
if (scan.hasNextInt())
{
    card2 = scan.nextInt(9) +2;
}
else{
    fc2 = scan.next();
    switch (fc2)
    {
    case "A":
        card2 = 14;
        break;
    case "K":
        card2 = 13;
        break;
    case "Q":
        card2 = 12;
        break;
    case "J":
        card2 = 11;
        break;
    default:System.out.println("Invalid entry.");
    }

    }
}

    }

}
}
MGL94
  • 15
  • 2

2 Answers2

2

Allowing Strings in switch statements was new in Java 1.7. Upgrade your Java to 1.7+ and use it in Eclipse, or if you can't, then you must convert your cases into if-else statements.

rgettman
  • 176,041
  • 30
  • 275
  • 357
  • But when i switch it to 1.7 all of my "systems" get errors like for my System.out.println's – MGL94 Dec 04 '13 at 01:22
  • The errors are probably due to the fact that you don't have a version 7 JDK installed and/or configured within your IDE. – Giulio Franco Dec 04 '13 at 01:32
0

Strings were not able to be used as part of switch statements in JDK versions prior to 1.7. You need to install JDK 1.7 and set Eclipse to use this version of the JDK.

See this video that details how to switch your JRE/JDK version.

Kevin Bowersox
  • 93,289
  • 19
  • 159
  • 189