Back to notes -- Keyboard shortcut: 'u'              Slide program -- Keyboard shortcut: 't'    The class Die - aspects visible to clients emphasized.Lecture 3 - slide 8 : 29
Program 1
using System;

public class Die {
  private int numberOfEyes;                
  private Random randomNumberSupplier;     
  private const int maxNumberOfEyes = 6;   

  public Die(){  
    randomNumberSupplier = new Random(unchecked((int)DateTime.Now.Ticks));
    numberOfEyes = NewTossHowManyEyes();
  }   
    
  public void Toss(){  
    numberOfEyes = NewTossHowManyEyes();
  }

  private int NewTossHowManyEyes (){  
    return randomNumberSupplier.Next(1,maxNumberOfEyes + 1);
  }

  public int NumberOfEyes() {  
    return numberOfEyes;       
  }

  public override String ToString(){   
    return String.Format("[{0}]", numberOfEyes);   
  }
}