Advertisement
Guest User

Untitled

a guest
Nov 25th, 2014
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. public class CoinFlip {
  2.  
  3. public static void main(String[] args) {
  4. int bank = 500;
  5. int headsCount=0;
  6. int tailsCount=0;
  7. int winCounter=0;
  8. int lossCounter=0;
  9. String[] flipResults = new String[100];
  10.  
  11. ComputerPlayer randomPlayer = new ComputerPlayer();
  12. Coin coin = new Coin();
  13.  
  14. for (int i = 0; i < 100; i++) {
  15. randomPlayer.placeRandomBet();
  16. flipResults[i] = coin.flip();
  17. if(flipResults[i].equals("heads")){
  18. headsCount += 1;
  19. }
  20. else{
  21. tailsCount +=1;
  22. }
  23. if(flipResults[i].equals(randomPlayer.placeRandomBet())){
  24. bank += 50;
  25. winCounter+=1;
  26. }
  27. if(!flipResults[i].equals(randomPlayer.placeRandomBet())){
  28. bank -=50;
  29. lossCounter+=1;
  30. }
  31. }
  32. }
  33.  
  34. public static class ComputerPlayer{
  35.  
  36. int Bank = 500;
  37. double bet;
  38. String heads = "heads";
  39. String tails = "tails";
  40.  
  41. public ComputerPlayer(){}
  42.  
  43. public String placeRandomBet(){
  44. bet = Math.random();
  45. if(bet < .5){
  46. return heads;
  47. }
  48. else return tails;
  49. }
  50.  
  51. public static String placeLearnedBet(int wins; int losses){
  52. //not sure where to start
  53. }
  54. }
  55.  
  56. public static class Coin {
  57.  
  58. double coin;
  59. String heads = "heads";
  60. String tails = "tails";
  61.  
  62. public String flip() {
  63. if (Math.random() < .9) {
  64. return heads;
  65. } else {
  66. return tails;
  67. }
  68. }
  69.  
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement