Advertisement
Guest User

Untitled

a guest
Dec 17th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. /**
  2. * Ninety Nine
  3. *
  4. * @author Dylan Keskinyan
  5. * @version 12/14/17
  6. */
  7. import java.util.Arrays;
  8. import java.io.*;
  9. public class NinetyNine
  10. {
  11. private static int totalValue;
  12. private static final String MAP = "123456789TJQKA";
  13. private static String input;
  14. private static String[] numbers;
  15. private static int[] playersCards = new int[3];
  16. public static String whomstWon()
  17. {
  18. String winner;
  19. int added,i;
  20. totalValue = Integer.parseInt(numbers[0]);
  21. for(i=3;totalValue<=99;i++)
  22. {
  23. Arrays.sort(playersCards);
  24. if(i%2==1)
  25. {
  26. added = MAP.indexOf(playersCards[2])+1;
  27. }
  28. else
  29. {
  30. added = MAP.indexOf(numbers[i])+1;
  31. }
  32.  
  33. if(added!=9 && added!=10 && added!=14)
  34. {
  35. totalValue += added;
  36. }
  37. else if(added==10)
  38. {
  39. totalValue -= 10;
  40. }
  41. else if(added==14 && totalValue+14<100)
  42. {
  43. totalValue += 14;
  44. }
  45. else if(added!=9)
  46. {
  47. totalValue += 1;
  48. }
  49.  
  50. if(i%2==1 && i<8)
  51. {
  52. playersCards[2] = MAP.indexOf(numbers[i]);
  53. Arrays.sort(playersCards);
  54. }
  55. }
  56.  
  57. if(i%2==1)
  58. {
  59. winner = "dealer";
  60. }
  61. else
  62. {
  63. winner = "player";
  64. }
  65.  
  66. return totalValue + ", " + winner;
  67. }
  68.  
  69. public static void main(String[] args)
  70. {
  71. try
  72. {
  73. BufferedReader br=new BufferedReader(new FileReader("input.txt"));
  74. for(int j=0; j<5; j++)
  75. {
  76. input = br.readLine();
  77. numbers = input.split(", ");
  78. playersCards[0] = MAP.indexOf(numbers[1]);
  79. playersCards[1] = MAP.indexOf(numbers[2]);
  80. playersCards[2] = MAP.indexOf(numbers[3]);
  81. System.out.println(whomstWon());
  82. }
  83. }
  84. catch(IOException e){}
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement