Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Coin {
- private int c;
- private Random rand;
- private int h;
- private int t;
- private ArrayList<Integer> history;
- public Coin(){
- this.rand = new Random();
- history = new ArrayList<Integer>();
- }
- public String flip(){
- c = rand.nextInt(2);
- history.add(c);
- if(c==0){
- return "H";
- }
- else{
- return "T";
- }
- }
- public int getNumHeads(){
- for (int i = 0; i < history.size(); i++){
- if(history.get(i)==0){
- h = (h + 1);
- }
- }
- return h;
- }
- public int getNumTails(){
- for (int j = 0; j< history.size(); j++){
- if(history.get(j)==1){
- t = (t + 1);
- }
- }
- return t;
- }
- public void reset(){
- history.clear();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement