Advertisement
Guest User

Untitled

a guest
Nov 17th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package cisy103.kweismantel;
  7.  
  8. import java.util.Random;
  9. import java.util.Scanner;
  10. import static java.lang.System.in;
  11. import static java.lang.System.out;
  12. /**
  13. *
  14. * @author Kyle Weismantel
  15. *
  16. */
  17. public class CoinTossing
  18. {
  19. public static String sideUp;
  20. public static int number;
  21.  
  22. public void run()
  23. {
  24. try( Scanner input = new Scanner(in) )
  25. {
  26. out.print("Enter how many times you would like to flip the coin");
  27. out.print("if you enter 0 the program quits");
  28. int number = input.nextInt();
  29. }
  30. }
  31.  
  32.  
  33. private static void coin()
  34. {
  35. Random rand = new Random();
  36. int sideup = rand.nextInt(2);
  37. if (sideup == 0)
  38. {
  39. sideUp = "heads";
  40. }
  41. else
  42. {
  43. sideUp = "tails";
  44. }
  45. }
  46.  
  47. public static String getsideup()
  48. {
  49. out.println(sideUp);
  50. return sideUp;
  51. }
  52.  
  53.  
  54.  
  55. public static void main(String[] args)
  56. {
  57. int hcount = 0;
  58. int tcount = 0;
  59. Scanner sc = new Scanner(System.in);
  60. out.println("How many coin flips do you want?");
  61. int number = sc.nextInt();
  62. for (int i = 1; i <= number; i++)
  63. {
  64. coin();
  65. if (getsideup().equals("heads"))
  66. {
  67. hcount++;
  68. }
  69. else
  70. {
  71. tcount++;
  72. }
  73. }
  74. out.println("total heads = " + hcount + " total tails = " + tcount);
  75. }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement