Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class DanielCoinTester
  4. {
  5. public static void main(String[] args)
  6. {
  7. Scanner in = new Scanner(System.in);
  8.  
  9. //create coin obj
  10. DanielCoin c1 = new DanielCoin();
  11.  
  12. //Print out the side that is facing up
  13. System.out.println(c1);
  14.  
  15. //get the number of tosses
  16. System.out.println("How many times do you want to toss your coin");
  17. int toss = 0;
  18. boolean inputMismatch = true;
  19. do
  20. {
  21. try
  22. {
  23. // Get number of toss to perform
  24. toss = in.nextInt();
  25. inputMismatch = false;
  26. }
  27. //inform user to enter integer value
  28. catch (InputMismatchException ime)
  29. {
  30. System.out.println("Enter an integer value:");
  31. }
  32. in.nextLine();
  33. }
  34. while (inputMismatch);
  35. }
  36. int numhead = 0;
  37. int numTail = 0;
  38.  
  39. for(int i = 0; i < toss; i++)
  40. {
  41. //toss coin
  42. c1.toss();
  43.  
  44. if(c1.getSideUp().equalsIgnoreCase("heads"))
  45. {
  46. //check if heads up is facing up
  47. numHead = numHead + 1;
  48. }
  49. else if(c1.getSideUp().equalsIgnoreCase("tails"))
  50. {
  51. //check if tails is facing up
  52. numTail = numTail + 1;
  53. }
  54. System.out.println(c1);
  55.  
  56. System.out.println("You got " + numHead + " Heads and " + numTail + " Tails");
  57. }
  58.  
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement