From 5d62bfe537d156bbb4b8f2797868e7d0475a481a Mon Sep 17 00:00:00 2001 From: Martin Kierkegaard Date: Mon, 3 Oct 2016 21:32:24 +0200 Subject: [PATCH] solution for the exercise --- DiceGame/DiceCup.cs | 24 ++++++++++++++++++------ DiceGame/InsertCodeHere.cs | 14 ++++++++++++++ 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/DiceGame/DiceCup.cs b/DiceGame/DiceCup.cs index cd9b6d0..2c03e4a 100644 --- a/DiceGame/DiceCup.cs +++ b/DiceGame/DiceCup.cs @@ -19,13 +19,25 @@ public DiceCup() die2 = new Die(); } - // You must create a method with the below header: - // public void RollDice() + // Step 2a: RollDice: Should roll both dices in the cup. No value is returned. + public void RollDice() + { + die1.RollDie(); + die2.RollDie(); + } - // You must create a method with the below header: - // public int GetTotalValue() + // Step 2b: GetTotalValue: Should return the total value of the two dice in the cup. + public int GetTotalValue() + { + return (die1.GetValue() + die2.GetValue()); + } - // You must create a method with the below header: - // public bool IsTotalValueLargerThan(int value) + // Step 2c: IsTotalValueLargerThan: This method should take one integer value as input, + // and return either true or false. The return value should be true if the total value + // of the two dice is larger than the input value; otherwise, it should return false. + public bool IsTotalValueLargerThan(int value) + { + return (GetTotalValue() > value); + } } } diff --git a/DiceGame/InsertCodeHere.cs b/DiceGame/InsertCodeHere.cs index 14149a9..5f5b07f 100644 --- a/DiceGame/InsertCodeHere.cs +++ b/DiceGame/InsertCodeHere.cs @@ -11,6 +11,20 @@ public void MyCode() { // The FIRST line of code should be BELOW this line + // Step 1 - testing the Die class + Die aDie = new Die(); + aDie.RollDie(); + Console.WriteLine("Die value is: {0}", aDie.GetValue()); + Console.WriteLine(); + + // Step 3 - testing the DiceCup class + DiceCup aCup = new DiceCup(); + aCup.RollDice(); + Console.WriteLine("Total value in dice cup is: {0}", aCup.GetTotalValue()); + Console.WriteLine(); + Console.WriteLine("Total value is larger than 7: {0}", aCup.IsTotalValueLargerThan(7)); + Console.WriteLine(); + // The LAST line of code should be ABOVE this line }