Program One

The Die

Create a swift class that duplicates the functionality of the familiar Die java class.

Then create a main function in a seperate code file that creates two six sided Die, rolls them both 256 times, and reports the number of doubles as both an int and a percentage.

Die.java

/**
* Class that simulates a single die.
*   @author Dave Reed
*   @version 1/23/13
*/
public class Die {
 private int numSides;   // number of die sides
 private int numRolls;   // number of rolls so far

 /**
  * Constructs a default, 6-sided die object
  */
 public Die() {
   this(6);
 }

 /**
  * Constructs a die object
  *   @param sides number of die sides
  */
 public Die(int sides) {
   this.numSides = sides;
   this.numRolls = 0;
 }

 /**
  * Rolls the die, updating the number of rolls.
  *   @return random number between 1 and getNumSides()
  */
 public int roll() {
   this.numRolls = this.numRolls + 1;
   return (int)(Math.random()*this.numSides) + 1;
 }

 /**
  * Reports the number of sides on the die.
  *   @return number of die sides
  */
 public int getNumSides() {
   return this.numSides;
 }

 /**
  * Reports the number of times the die has been rolled.
  *   @return number of die rolls so far
  */
 public int getNumRolls() {
   return this.numRolls;
 }
}

Submission

Upload the result to blueline. You should upload a single compressed file for this assignment that contains the complete XCode project (not just src files).