Advertisement
dimipan80

Exam 4. Straight Flush

Sep 10th, 2014
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.37 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Arrays;
  3. import java.util.Scanner;
  4.  
  5. public class _4_StraightFlush {
  6.  
  7.     private static String[] faces = { "2", "3", "4", "5", "6", "7", "8", "9",
  8.             "10", "J", "Q", "K", "A" };
  9.  
  10.     public static void main(String[] args) {
  11.         // TODO Auto-generated method stub
  12.         Scanner scan = new Scanner(System.in);
  13.         String[] cards = scan.nextLine().split("[, ]+");
  14.         boolean isFoundStraightFlush = false;
  15.         if (cards.length >= 5) {
  16.             ArrayList<String> cardList = new ArrayList<>();
  17.             cardList.addAll(Arrays.asList(cards));
  18.             for (String firstCard : cards) {
  19.                 String cardFace = firstCard
  20.                         .substring(0, firstCard.length() - 1);
  21.                 String cardSuit = firstCard.substring(firstCard.length() - 1);
  22.                 String[] straightFive = new String[5];
  23.                 for (int i = 0; i < straightFive.length; i++) {
  24.                     straightFive[i] = (cardFace + cardSuit);
  25.                     cardFace = getNextCard(cardFace);
  26.                 }
  27.  
  28.                 if (cardList.containsAll(Arrays.asList(straightFive))) {
  29.                     isFoundStraightFlush = true;
  30.                     System.out.println(Arrays.toString(straightFive));
  31.                 }
  32.             }
  33.         }
  34.  
  35.         if (!isFoundStraightFlush) {
  36.             System.out.println("No Straight Flushes");
  37.         }
  38.     }
  39.  
  40.     private static String getNextCard(String cardFace) {
  41.         for (int i = 1; i < faces.length; i++) {
  42.             if (faces[i - 1].equals(cardFace)) {
  43.                 return faces[i];
  44.             }
  45.         }
  46.  
  47.         return null;
  48.     }
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement