Question: (java) Using your PairOfDice class write an application that simulates 100 pass-line bets and output the results of each bet to an output file. Also,

(java) Using your PairOfDice class write an application that simulates 100 pass-line bets and output the results of each bet to an output file. Also, keep a running total of how many wins and losses. Output those totals at the end of your run. (not sure on how to implement file IO to output a separate text file, that will display how many wins and losses as well as the outputs from each roll)

pairofdice.java

import java.util.Random;

public class PairOfDice { private int die1; private int die2; public PairOfDice() { } public void roll() { Random d1 = new Random(); Random d2 = new Random(); die1 = d1.nextInt(6) + 1; die2 = d2.nextInt(6) + 1; } public int getDie1() { return die1; } public int getDie2() { return die2; } public int getTotalValue() { return die1 + die2; } @Override public String toString() { return die1 + "+" + die2 + " =" + getTotalValue(); } } craps.java

import java.io.*;

public class Craps { private static int losses = 0; private static int wins = 0; static PairOfDice dice = new PairOfDice(); public static int win() { wins++; return wins; } public static int lose() { losses++; return losses; } public static void play() { for(int i = 1; i <=10; i++) { dice.roll(); switch (dice.getTotalValue()) { case 2: case 3: System.out.println(dice); System.out.println("Sorry you lose."); lose(); break; case 12: System.out.println(dice); System.out.println("Sorry you lose."); lose(); break; case 7: case 11: System.out.println(dice); System.out.println("You Win!"); win(); break; case 4: case 5: System.out.println(dice); reroll(); break; case 6: case 8: System.out.println(dice); reroll(); break; case 9: System.out.println(dice); case 10: reroll(); break; default: break; } } } public static void reroll() { dice.roll(); if(dice.getTotalValue() == 4 || dice.getTotalValue() == 5) { System.out.println(dice); System.out.println("You Win!"); win(); reroll(); } if(dice.getTotalValue() == 6 || dice.getTotalValue() == 8) { System.out.println(dice); System.out.println("You Win!"); win(); reroll(); } if(dice.getTotalValue() == 9 || dice.getTotalValue() == 10) { System.out.println(dice); System.out.println("You Win!"); win(); reroll(); } else { System.out.println(dice); System.out.println("Sorry you lose."); lose(); } } public static void gameOver() { System.out.println("Game Over!"); System.out.println("You Won: " + wins + " times!"); System.out.println("You Lost: " + losses + " times!"); } public static void main(String args[]) { System.out.println("Good Luck!"); play(); gameOver(); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!