Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package cisy103.kweismantel;
- import java.util.Random;
- import java.util.Scanner;
- import static java.lang.System.in;
- import static java.lang.System.out;
- /**
- *
- * @author Kyle Weismantel
- *
- */
- public class CoinTossing
- {
- public static String sideUp;
- public static int number;
- public void run()
- {
- try( Scanner input = new Scanner(in) )
- {
- out.print("Enter how many times you would like to flip the coin");
- out.print("if you enter 0 the program quits");
- int number = input.nextInt();
- }
- }
- private static void coin()
- {
- Random rand = new Random();
- int sideup = rand.nextInt(2);
- if (sideup == 0)
- {
- sideUp = "heads";
- }
- else
- {
- sideUp = "tails";
- }
- }
- public static String getsideup()
- {
- out.println(sideUp);
- return sideUp;
- }
- public static void main(String[] args)
- {
- int hcount = 0;
- int tcount = 0;
- Scanner sc = new Scanner(System.in);
- out.println("How many coin flips do you want?");
- int number = sc.nextInt();
- for (int i = 1; i <= number; i++)
- {
- coin();
- if (getsideup().equals("heads"))
- {
- hcount++;
- }
- else
- {
- tcount++;
- }
- }
- out.println("total heads = " + hcount + " total tails = " + tcount);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement