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.
- */
- /**
- *
- * @author BenjaminHallman
- */
- public class BiasedCoin {
- public final int HEADS = 0;
- public final int TAILS = 1;
- private double face = (double) (Math.random());
- private double bias = (double) (Math.random());
- private double biasValue = (double) bias * 100;
- public BiasedCoin() {
- flip();
- }
- public void flip() {
- if (face <= bias) {
- face = HEADS;
- }
- else {
- face = TAILS;
- }
- }
- public boolean isHeads() {
- return (face == HEADS);
- }
- public String biasToString() {
- String biasString = ("" + biasValue);
- return biasString;
- }
- public String faceToString() {
- String faceName;
- if (face == HEADS) {
- faceName = "Heads";
- } else {
- faceName = "Tails";
- }
- return faceName;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement