Guest User

Untitled

a guest
Jul 21st, 2018
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1.  
  2. public class Baccarat {
  3. public static void main(String[] args) {
  4. //We create Player, Banker and the pack
  5. Pack pack = new Pack();
  6. BaccaratHand player = new BaccaratHand();
  7. BaccaratHand banker = new BaccaratHand();
  8.  
  9. //First card is dealt to Player and Banker
  10. player.addCard(pack.dealCard());
  11. banker.addCard(pack.dealCard());
  12. //Second card is dealt to Player and Banker
  13. player.addCard(pack.dealCard());
  14. banker.addCard(pack.dealCard());
  15.  
  16.  
  17.  
  18. if(player.isNatural()){
  19. System.out.println("The Player Wins due to the Natural Hand");
  20. }else if(banker.isNatural()){
  21. System.out.println("The Banker Wins due to the Natural Hand");
  22. }else{
  23. //Player asks for cards following its strategy
  24. while(player.totalPoints()<=5){
  25. System.out.println("Player asks for an extra card");
  26. player.addCard(pack.dealCard());
  27. }
  28. //Banker stays if Player's hand total is greater than 9; otherwise he asks for cards
  29. if(player.totalPoints()<=9){ //Player does not exceed 9
  30. while(banker.totalPoints()<9 && banker.totalPoints()<player.totalPoints()){
  31. System.out.println("Banker asks for an extra card");
  32. banker.addCard(pack.dealCard());
  33. }
  34. }
  35. //Final score is computed and the winner is announced
  36. double pointsP = player.totalPoints();
  37. double pointsB = banker.totalPoints();
  38.  
  39. if(pointsP<=9 && (pointsB>9 || pointsP>pointsB)){
  40. System.out.println("Player wins with "+player+" ("+ pointsP+" points). Banker has "+ banker+" ("+pointsB+" points)");
  41. }else if (pointsB<=9){
  42. System.out.println("Banker wins with "+banker+" ("+ pointsB+" points). Player has "+ player+" ("+pointsP+" points)");
  43. }else{
  44. System.out.println("Nobody wins: Player "+ player+" ("+pointsP+" points) and Banker "+ banker +" ("+pointsB+" points) exceed 7.5");
  45. }
  46. }
  47. }
  48. }
Add Comment
Please, Sign In to add comment