Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class DanielCoinTester
- {
- public static void main(String[] args)
- {
- Scanner in = new Scanner(System.in);
- //create coin obj
- DanielCoin c1 = new DanielCoin();
- //Print out the side that is facing up
- System.out.println(c1);
- //get the number of tosses
- System.out.println("How many times do you want to toss your coin");
- int toss = 0;
- boolean inputMismatch = true;
- do
- {
- try
- {
- // Get number of toss to perform
- toss = in.nextInt();
- inputMismatch = false;
- }
- //inform user to enter integer value
- catch (InputMismatchException ime)
- {
- System.out.println("Enter an integer value:");
- }
- in.nextLine();
- }
- while (inputMismatch);
- }
- int numhead = 0;
- int numTail = 0;
- for(int i = 0; i < toss; i++)
- {
- //toss coin
- c1.toss();
- if(c1.getSideUp().equalsIgnoreCase("heads"))
- {
- //check if heads up is facing up
- numHead = numHead + 1;
- }
- else if(c1.getSideUp().equalsIgnoreCase("tails"))
- {
- //check if tails is facing up
- numTail = numTail + 1;
- }
- System.out.println(c1);
- System.out.println("You got " + numHead + " Heads and " + numTail + " Tails");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement