Advertisement
Guest User

Untitled

a guest
Nov 30th, 2015
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 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.  
  7. /**
  8. *
  9. * @author BenjaminHallman
  10. */
  11. public class BiasedCoin {
  12.  
  13. public final int HEADS = 0;
  14. public final int TAILS = 1;
  15.  
  16. private double face = (double) (Math.random());
  17. private double bias = (double) (Math.random());
  18. private double biasValue = (double) bias * 100;
  19.  
  20. public BiasedCoin() {
  21. flip();
  22. }
  23.  
  24. public void flip() {
  25. if (face <= bias) {
  26. face = HEADS;
  27. }
  28. else {
  29. face = TAILS;
  30. }
  31. }
  32.  
  33. public boolean isHeads() {
  34. return (face == HEADS);
  35. }
  36.  
  37. public String biasToString() {
  38. String biasString = ("" + biasValue);
  39.  
  40. return biasString;
  41. }
  42.  
  43. public String faceToString() {
  44. String faceName;
  45.  
  46. if (face == HEADS) {
  47. faceName = "Heads";
  48. } else {
  49. faceName = "Tails";
  50. }
  51.  
  52. return faceName;
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement