Advertisement
Monty374

Coin 1

Nov 13th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. package flip.coin;
  2.  
  3.  
  4. public class FlipCoin {
  5.  
  6. public static class Coin {
  7. private boolean flip;
  8.  
  9. public void setFlip() {
  10. flip = ((int)(Math.random()*2)==1);
  11. }
  12.  
  13. public boolean getFlip() {
  14. return flip;
  15. }
  16.  
  17. public String toString() {
  18. if (flip) {
  19. return"Heads";
  20.  
  21. } else {
  22. return"Tails";
  23.  
  24. }
  25. }
  26. }
  27.  
  28. public static void main(String[] args) {
  29. Coin nickel = new Coin();
  30. nickel.setFlip();
  31. System.out.println(nickel);
  32.  
  33. }
  34.  
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement