Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class CoinFlip {
- public static void main(String[] args) {
- int bank = 500;
- int headsCount=0;
- int tailsCount=0;
- int winCounter=0;
- int lossCounter=0;
- String[] flipResults = new String[100];
- ComputerPlayer randomPlayer = new ComputerPlayer();
- Coin coin = new Coin();
- for (int i = 0; i < 100; i++) {
- randomPlayer.placeRandomBet();
- flipResults[i] = coin.flip();
- if(flipResults[i].equals("heads")){
- headsCount += 1;
- }
- else{
- tailsCount +=1;
- }
- if(flipResults[i].equals(randomPlayer.placeRandomBet())){
- bank += 50;
- winCounter+=1;
- }
- if(!flipResults[i].equals(randomPlayer.placeRandomBet())){
- bank -=50;
- lossCounter+=1;
- }
- }
- }
- public static class ComputerPlayer{
- int Bank = 500;
- double bet;
- String heads = "heads";
- String tails = "tails";
- public ComputerPlayer(){}
- public String placeRandomBet(){
- bet = Math.random();
- if(bet < .5){
- return heads;
- }
- else return tails;
- }
- public static String placeLearnedBet(int wins; int losses){
- //not sure where to start
- }
- }
- public static class Coin {
- double coin;
- String heads = "heads";
- String tails = "tails";
- public String flip() {
- if (Math.random() < .9) {
- return heads;
- } else {
- return tails;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement