0

I'm sure I'm missing something very basic, but I can't see what it is. The following is an excerpt from a larger program that deals hands of cards and determines their rank in poker. This function turns the first letter in a card string into an integer so that it can be compared. So, "king of spades" would send the "k" to this function and it should return 13, "6 of hearts" sends the "6" and gets back 6, etc. It considers a, k, q, j, and 1 as special cases and then uses Integer.parseInt() on all other inputs.

But, for some reason, it is not ever evaluating the special cases, it is running the else statement every time and crashing on parseInt() when it gets a letter. All help is appreciated, thank you.

    package testSpace;

 import java.util.Scanner;

 public class main {

 public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);  
       System.out.println("Enter a single digit or an a, k, q, or j"); 
       String thisRank = sc.next();
       System.out.print(parseRank(thisRank));
}      
       public static int parseRank(String thisRank){
        if(thisRank=="a"){
            return 14;
        }
        else if(thisRank=="j"){
            return 11;
        }
        else if(thisRank=="q"){
            return 12;
        }
        else if(thisRank=="k"){
            return 13;
        }
        else if(thisRank=="1"){
            return 10;
        }
        else{
            return Integer.parseInt(thisRank);
        }
       }    

}
IAntoniazzi
  • 137
  • 5

0 Answers0