cs102 lab6
http://www.maths.nuigalway.ie/~gettrick/teach/cs102/labs/l6.html
-
For this lab you must submit all source code (python
files), and, if applicable, the result(s) of running the program on (a few)
test cases. This should be sent in via BLACKBOARD (not directly by email).
The source code must
be well presented (indenting, spaces, reasonable variable/function names,
etc.) and must include comments (as a rough guideline - aim to have nearly as
many comments as lines of code). Any questions asked should be answered by
typing into a plain text (.txt) file which should also
be uploaded via blackboard.
-
This material should be uploaded
before
the deadline of 5pm
Friday March 19th, 2010. You will lose 20% for each day
(or part of day) the lab is late.
-
Plagiarism (the unattributed copying of work from other sources
(internet, fellow students,....)) will not be tolerated. Please see
http://www.nuigalway.ie/engineering/documents/plagiarism_guide_students
_v4.pdf. You risk getting zero for your lab if it is found to be
plagiarized.
Write a class in python to model an 8-sided dice. The dice has one number and
one letter on each face, and each face is colored, as follows:
{1/A/orange, 2/A/yellow, 3/A/green, 4/B/blue, 1/A/white, 2/B/black, 3/C/purple, 4/B/brown}.
Write the following methods in your class:
-
A fairToss() method that tosses the dice fairly.
-
A getNumber() method that prints out the current number.
-
A getLetter() method that prints out the current letter.
-
A getColor() method that prints out the current color.
-
A getDice() method that prints out all three parameters (this method can call
the other methods getNumber, getLetter, getColor if you want).
-
A getParity() method that returns EVEN if the number is even and ODD if it is
odd.
-
An unfairToss() method that gives twice as high a chance of getting black or white
as a result, compared to getting any of the other colors (i.e. the probability for
getting black or white is 0.2 each, and the probability for any other individual
color is 0.1).
You should test your methods well (by calling them from the main program), to make
sure they work as planned.
You may use the DICE class covered in lectures as a starting point
(see http://www.maths.nuigalway.ie/~gettrick/teach/cs102/progs/).
©
NUI, Galway