CS 1112 Exercise 12

You have until Sunday, May 9, 11:00pm EDT to submit your solutions to Matlab Grader.

A dice game using class Die

Read Die.m and diceGame.m. Notice that a Die has private properties top and sides. public getter methods are provided in the class definition. Next consider the function diceGame(); it contains two errors that you need to correct. Start by calling diceGame() with a small number of trials. Read both the error message and the code in diceGame.m! Correct the function so that it behaves as specified.

Copy the body of your function diceGame() into the code box for Problem 1 in Matlab Grader. Test (and correct if necessary) your function.

A dice game with both Die and TrickDie

Make a copy of diceGame.m and call it diceGame2.m. Correspondingly, change the function name to be diceGame2. Now modify the function so that the first two elements of d are Dies while the third element of d is a TrickDie. All the dice should have 6 sides but you can choose the TrickDie’s other property values. Question to consider: Should d be a “simple” array or a cell array?

Try to solve this problem by making as little modification to the code as possible. If you are uncertain whether your solution is minimal, discuss with a classmate! Or ask one your discussion TA or consultants.

Copy the body of your function diceGame2() into the code box for Problem 2 in Matlab Grader. Matlab Grader checks only the types on this problem, not the computed values. Talk with a human staff member if you are at all uncertain about your answer!