Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * The class <b>Statistics</b> accumulates information about a series of games:
- * <ol>
- * <li>Number of game played</li>
- * <li>Number of times the switching strategy was successful</li>
- * <li>Number of times the switching strategy was not successful</li>
- * <li>Number of times each door has the prize behind it</li>
- * <li>Number of times each door was chosen by the player</li>
- * <li>Number of times each door was open by the host</li>
- * </ol>
- *
- * @author gvj (gvj@eecs.uottawa.ca)
- *
- */
- public class Statistics {
- private int numberOfGames;
- private int switchWins;
- private int switchLose;
- private int doorSelectedA;
- private int doorSelectedB;
- private int doorSelectedC;
- private int hostDoorA;
- private int hostDoorB;
- private int hostDoorC;
- private int prizeDoorA;
- private int prizeDoorB;
- private int prizeDoorC;
- private int doorNumber;
- private int[] selectedDoors;
- private int[] prizeDoors;
- private int[] openDoors;
- private Door prizeDoorVariable;
- private Door selectedDoorVariable;
- // ADD HERE YOUR MEMBER VARIABLES
- /**
- * Initializes the statistics.
- *
- * @param numberOfDoors the number of doors used
- */
- public Statistics(int numberOfDoors){
- openDoors = new int[numberOfDoors];
- prizeDoors = new int[numberOfDoors];
- selectedDoors = new int[numberOfDoors];
- for(int i = 0; i < numberOfDoors; i++){
- prizeDoors[i] = 0;
- selectedDoors[i]=0;
- openDoors[i]=0;
- }
- numberOfGames = 0;
- switchWins = 0;
- switchLose = 0;
- doorNumber = numberOfDoors;
- selectedDoors = new int[numberOfDoors];
- }
- /**
- * Updates statistics after one game.
- * @param doorArry the list of Doors used during the game
- */
- public void updateStatistics(Door[] doorArray){
- // REPLACE THE BODY OF THIS METHOD WITH YOUR OWN IMPLEMENTATION
- for(int i = 0; i<doorNumber;i++){
- if(doorArray[i].hasPrize()){
- prizeDoors[i] = prizeDoors[i]++;
- }
- else if (doorArray[i].hasPrize()){
- prizeDoorVariable=doorArray[i];
- }
- else if(doorArray[i].isOpen()){
- openDoors[i]=openDoors[i]++;
- }
- else if(doorArray[i].isChosen()){
- selectedDoors[i] = selectedDoors[i]++;
- }
- else if(doorArray[i].isChosen()){
- selectedDoorVariable = doorArray[i];
- }
- }
- numberOfGames = numberOfGames++;
- if(selectedDoorVariable == prizeDoorVariable){
- switchWins = switchWins++;
- }
- else{
- switchLose = switchLose++;
- }
- }
- /**
- * @return Returns the complete statistics information
- */
- public String toString(){
- // REPLACE THE BODY OF THIS METHOD WITH YOUR OWN IMPLEMENTATION
- String string = "";
- string = "Number of games played: " + numberOfGames + "\nStaying strategy won " + switchLose + " games (" + 100*switchLose/numberOfGames + "%)\nSwitching stragety won " + switchWins + " games (" + 100*switchWins/numberOfGames + "%)\nSelected doors:\n";
- for(int i = 0;i<doorNumber;i++){
- string = string + "door" + (i+1) + ": " + selectedDoors[i] + " (" + 100*selectedDoors[i]/numberOfGames + "%)" + "\r\n";
- }
- string = string + "Winning Doors: " + "\r\n";
- for(int i = 0; i < doorNumber; i++){
- string = string + "door " + (i+1) + ": " + prizeDoors[i] + " (" + 100*prizeDoors[i]/numberOfGames + "%)" + "\r\n";
- }
- string = string + "Opened doors: " + "\r\n";
- for(int i = 0; i<doorNumber; i++){
- string = string + "door " + (i+1) + ": " + openDoors[i] + " (" + 100*openDoors[i]/numberOfGames + "%)" + "\r\n";
- }
- return string;
- }
- /**
- * @return Returns the complete statistics information in CSV format
- */
- public String toCSV(){
- String stringCSV = "";
- stringCSV = "Number of games, " + numberOfGames + "\nNumber of doors,3 \n,Win,Loss\nStaying strategy, " +switchLose + "," + switchWins + "\nSwitching strategy, " + switchWins + "," + switchLose +"\nSelected doors,Winning doors,Open doors" + "\r\n";
- for(int i = 0; i<doorNumber; i++){
- stringCSV = stringCSV + "Door" + (1+i) + " ," + selectedDoors[i] + "," + prizeDoors[i] + "," + openDoors[i] + "\r\n";
- }
- return stringCSV;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement