Advertisement
Guest User

Untitled

a guest
Dec 14th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. /**Author:Paige Hill
  2. * s5060971
  3. * week 20 task3
  4. * this program is the craps game. The user runs the program and 2 dices will
  5. * generate a random number which will then be added together
  6. * once this has been done, the user will then win or lose depending on which number they receive.
  7. * a winning number is 7 or 11
  8. * a losing number is 2,3 or 12 and any other number will just keep the program running and offer the user a second go.
  9. */
  10. import java.util.Scanner;
  11.  
  12. public class Craps {
  13. Dice dice1 = new Dice();
  14. Dice dice2 = new Dice();
  15. int score;
  16.  
  17.  
  18. String userinput;
  19.  
  20. // throws two dice
  21. public void shoot(){
  22.  
  23. dice1.roll();
  24. dice2.roll();
  25. }
  26.  
  27. //calculate score
  28. public int calculateScore(){
  29. score = dice1.getFaceValue() + dice2.getFaceValue();
  30. return score;
  31. }
  32.  
  33. //display details
  34. public void displayDetails(){
  35. System.out.println("Dice 1 " + dice1.getFaceValue());
  36. System.out.println("Dice 2 " + dice2.getFaceValue());
  37. System.out.println("Score is " + score);
  38.  
  39. }
  40. public static void main(String [] ars){
  41. Craps craps = new Craps();
  42. Scanner scan = new Scanner(System.in);
  43.  
  44. int userChoice = 0;
  45. do {
  46. craps.shoot();
  47. craps.calculateScore();
  48. craps.displayDetails();
  49.  
  50. if ((craps.calculateScore() == 7) || (craps.calculateScore() == 11)){
  51. System.out.println("Winning Throw!");
  52. }
  53. else if ((craps.calculateScore() == 2) || (craps.calculateScore() == 3) || (craps.calculateScore() == 12)){
  54. System.out.println("Losing Throw:(");
  55. }
  56. System.out.println("press 0 to stop press 1 to continue ");
  57. userChoice = scan.nextInt();
  58.  
  59.  
  60. }while(userChoice != 0);
  61. scan.close();
  62. }
  63.  
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement