Advertisement
dimipan80

C#Exams 4. Poker Straight (on Java Code)

Aug 25th, 2014
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.50 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class _4_PokerStraight {
  4.  
  5.     public static void main(String[] args) {
  6.         // TODO Auto-generated method stub
  7.         Scanner scan = new Scanner(System.in);
  8.         int givenWeight = scan.nextInt();
  9.  
  10.         int countStraightHands = 0;
  11.         if (givenWeight >= 555 && givenWeight <= 1920) {
  12.             countStraightHands = getTheCountOfStraightHandsWithGivenWeight(givenWeight);
  13.         }
  14.  
  15.         System.out.println(countStraightHands);
  16.     }
  17.  
  18.     private static int getTheCountOfStraightHandsWithGivenWeight(int weight) {
  19.         // TODO Auto-generated method stub
  20.         int countStraights = 0;
  21.         int face, currentWeight;
  22.         int suit1, suit2, suit3, suit4, suit5;
  23.         for (face = 1; face <= 10; face++) {
  24.             for (suit1 = 1; suit1 <= 4; suit1++) {
  25.                 for (suit2 = 1; suit2 <= 4; suit2++) {
  26.                     for (suit3 = 1; suit3 <= 4; suit3++) {
  27.                         for (suit4 = 1; suit4 <= 4; suit4++) {
  28.                             for (suit5 = 1; suit5 <= 4; suit5++) {
  29.                                 currentWeight = calculateTheWeightOfCurrentStraight(
  30.                                         face, suit1, suit2, suit3, suit4, suit5);
  31.                                 if (currentWeight == weight) {
  32.                                     countStraights++;
  33.                                 }
  34.                             }
  35.                         }
  36.                     }
  37.                 }
  38.             }
  39.         }
  40.  
  41.         return countStraights;
  42.     }
  43.  
  44.     private static int calculateTheWeightOfCurrentStraight(int face, int s1,
  45.             int s2, int s3, int s4, int s5) {
  46.         // TODO Auto-generated method stub
  47.         int totalWeight = (10 * face) + (20 * (face + 1)) + (30 * (face + 2))
  48.                 + (40 * (face + 3)) + (50 * (face + 4));
  49.         totalWeight += s1 + s2 + s3 + s4 + s5;
  50.  
  51.         return totalWeight;
  52.     }
  53.  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement