SHARE
TWEET

Untitled

a guest Dec 3rd, 2019 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. public class CoinRace {
  3.    
  4.     public static void main(String[] args) {
  5.         final int GOAL = 3;
  6.         int count1 = 0,count2 = 0;
  7.        
  8.         //count for each coin
  9.  
  10.         Coin coin1 = new Coin();
  11.         Coin coin2 = new Coin();
  12.        
  13.         while ((count1 < GOAL) && (count2 < GOAL)) {
  14.             coin1.flip();
  15.             coin2.flip();
  16.            
  17.             count1 = ((coin1.isHeads()) ? count1 + 1 : 0);
  18.             count2 = ((coin2.isHeads()) ? count2 + 1 : 0);
  19.            
  20.             System.out.println("Coin1 is :" + coin1.toString());
  21.             System.out.println("Coin2 is :" + coin2.toString());
  22.             System.out.println("");
  23.            
  24.            
  25.         }
  26.        
  27.         if (count1 == GOAL) {
  28.             System.out.println("Coin 2 WINS!\nIN " + coin2.getAttempt() + "ATTEMPTS");
  29.         } else {
  30.             if (count2 == GOAL) {
  31.                 System.out.println("Coin 1 WINS!\nIN  " + coin1.getAttempt()+ "  ATTEMPTS");
  32.             } else {
  33.                 System.out.println("Its a tie");
  34.             }
  35.         }
  36.     }
  37.  
  38.  
  39.    
  40.  
  41.  
  42.  
  43.  
  44. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top