The program is designed to scan the user for the first two cards they receive and tell them what they have. Unfortunately, when it asks "Are the cards suited?: " it terminates before input can be taken. I also could learn how to organize the conditions in a switch statement rather than all these ugly if-else statements as well.
package Test;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
int card1 = 0;
int card2 = 0;
String fc1, fc2;
String answer;
Scanner scan = new Scanner (System.in);
System.out.println("First card: ");
if (scan.hasNextInt())
{
card1 = scan.nextInt();
}
else
{
fc1 = scan.next();
if (fc1 == "A")
{
card1 = 14;
}
else if(fc1 == "K")
{
card1 = 13;
}
else if (fc1 == "Q")
{
card1 = 12;
}
else if (fc1 == "J")
{
card1 = 11;
}
}
System.out.println("Second card: ");
if (scan.hasNextInt())
{
card2 = scan.nextInt();
}
else
{
fc2 = scan.next();
if (fc2 == "A")
{
card2 = 14;
}
else if (fc2 == "K")
{
card2 = 13;
}
else if (fc2 == "Q")
{
card2 = 12;
}
else if (fc2 == "J")
{
card2 = 11;
}
}
if (card1 == card2)
{
System.out.println("You have a pair.");
}
else
{
System.out.println("Are your cards suited?(y/n): ");
answer = scan.nextLine();
if (answer == "y")
{
if (card1 >12 && card2 > 12)
{
System.out.println("High value suited cards.");
}
else
if (card1 == card2++ || card1++ == card2)
{
System.out.println("Suited connectors.");
}
}
else
if(answer == "N")
{
if (card1 >=12 && card2 >= 12)
{
System.out.println("High value cards, hold.");
}
else
if(card1 > 5 && card2 > 5)
{
if(card1++ == card2 || card1 == card2++)
{
System.out.println("Connectors.");
}
else
{
System.out.println("Fold");
}
if (answer != "y" || answer != "n")
{
System.out.println("Invalid entry.");
}
}
}
}
}
}