public DiceCupSolution() { // When we have instance fields of a class type, // we usually create actual objects in the constructor // that the instance fields can then point to. die1 = new Die(); die2 = new Die(); }
public DiceCup() { // VERY IMPORTANT! When we have instance fields of a class type, // we MUST remember to create actual objects in the constructor, // that the instance fields can then point to. die1 = new Die(); die2 = new Die(); }
public void MyMain() { // 1 Die d = new Die(); Console.WriteLine(d.GetValue()); d.RollDie(); Console.WriteLine(d.GetValue()); // 2a DiceCupSolution cup = new DiceCupSolution(); cup.RollDice(); // 2b Console.WriteLine(cup.GetTotalValue()); // 2c Console.WriteLine(cup.IsTotalValueLargerThan(5)); }