the host opened door Switching strategy would have wor A detailed description of
ID: 3665573 • Letter: T
Question
the host opened door Switching strategy would have wor A detailed description of the class can be found here: MontyHall jav Implemest both classes and make sare that your peogram works correcity Q2: Simulating a series of games (25 marks) Simulating one game at a time does not tell mach about the best strategy. You are going to change the class Monty Hall to imulate a large number of games. The results we going to be accumulated in an ohject of a class Statisatics and displayed at he end of the rus. The actual number of games to simulate is going to be a runtime input parameler An object of the class Statistics accunalates information about the results of each game. In addition to track the successes and failures of each strategy. it also keeps track of several other information (how often a door has the prize e is selected by the player etc.) These additional information are not important for the main question of which stralegy is the best, but it will provide some reassurance thut your program worls properly s behind it, how ofien A detailed description of the class cam be found here JavaDoc Documentation The class MontyHall mast be updated to take as input dhe number of games to simulale, and to run these games while accu mulating statistics. The input can by provided from the command line, in which case the output will be displayed on the standard outpot. If no conumand line input is provided, then the wser will be prompted for one (using JOptionPane.showInputDialog. and the output will also be provided in a dialog box (using JOption Pane.show MessageDialog)i An updated description of the class can be found here JavaDoc Documenlation MonlyHalljaa Here is a sample rua, with the input provided from the command line. > java MontyHall Nunber of ganes played: Staying strategy won 2 games (40%) Switching strategy won 3 ganes (60 Selected dootss door 1: door 2: door 31 (208) (60%) (20%) 1 1 Winning doorss door l: 1 (20) door 21 1 (20%) door 3: 3 460 Open doors i door 1: 2 (40%) door 2: 2 (40 door 31 1 t205) Implement classes and le your code Simulate an anaeasang number of games and see if you can see a tread which aralegy seems to work best? Can you understand why now Check that all of the statistics seem to make sense, and correct your program if you see anything weong Q3: Generating a CSV output to use in a spreadsheet (5 marks) ln order to visealiae your statistics, you can geserale a comma-sepatated valus ouspat, which you can then iport into a prcadsheet such as Microsoft Excel or Googke doc. Once in a specadsheet, you can use its buik-in tools to obain varioauExplanation / Answer
import java.util.Random; public class diceGame { public static void main (String args[]) { Random randomGenerator = new Random (); int a;//first face of die a = randomGenerator.nextInt((5)+1); System.out.println(a); int b;//second face of die b = randomGenerator.nextInt((5)+1); Random randomGenerator2 = new Random (); System.out.println(b); int c;//third face of die c = randomGenerator.nextInt((5)+1); Random randomGenerator3 = new Random (); System.out.println(c); ... } ... } import java.util.Random; public class DiceGame { private class DiceRoll { private static Random rng = new Random(); private int a, b, c; // rolls public DiceRoll() { this.a = rng.nextInt(6); this.b = rng.nextInt(6); this.c = rng.nextInt(6); } public int getScore() { if (a == 6 && b == 6 && c == 6) return 500; ... // other cases } public String toString() { return String.format("Rolled a %d, %d, and %d", a, b, c); } } public static void main (String args[]) { DiceRoll d; while (true) { d = new DiceRoll(); d.getScore(); // gives you how much to change the player score } // finish client } }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.