Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Task 1: Domino class Create a Python file called domino.py. Inside this file, create and test a Domino class according to the description below. Note

Task 1: Domino class Create a Python file called domino.py. Inside this file, create and test a Domino class according to the description below. Note that the following methods form the public interface for this class you must complete them all as specified, and cannot add additional methods to the public interface. However, you can include additional private helper methods that are only called within this class, if you wish. Domino(dotsA, dotsB)creates a domino,where the number of dots on each end of the domino are described by the integers dotsA and dotsB. After asserting that the input parameters are valid, dotsA and dotsB should be used to initialize two private attributes: top and bottom. Both of these attributes are integers, and the top is the end with the most dots on it. A third private attribute, faceDown, should also be created which indicates if the tile is facing down (True) or facing up (False). A domino should be facing up when it is first created. setTop(dots) updates which end of the Domino is at the top, according to the dots parameter. The integer dots must match one of the existing ends of the Domino instance (otherwise an AssertionError is raised). Nothing is returned. turnOver() updates the Domino instance so that if it was facing up, it will now be facing down. Similarly, if it was facing down, it will now be facing up. Nothing is returned. getTop() returns the integer number of dots on the top end of the Domino instance. getBottom() returns the integer number of dots on the bottom end of the Domino instance. isFaceDown() returns the Boolean value indicating whether the Domino instance is facing down (True) or up (False). __str__() returns the string representation of the Domino instance. The format of this string should be '[bottom number of dots|top number of dots]' if it is facing up. For example, a domino with 3 dots on the bottom and 4 dots on top will return the string '[3|4]'. Any domino that is facing down will have question marks, '?', instead of the numbers: '[?|?]' Test your Domino class thoroughly before moving on. Place these tests under if __name__ == "__main__":in domino.py Task 2: DominoDeck class Create and test a DominoDeck class in domino.py, according to the description below. Note that the following methods form the public interface for this class you must complete them all as specified, and cannot add additional methods to the public interface. However, you can include additional private helper methods that are only called within this class, if you wish. DominoDeck() creates an empty deck of dominoes, capable of holding the 28 dominoes in a standard "double-six" set. Notice that this deck acts very much like a queue, where we deal the front domino and add new dominoes to the rear of the deck. In the __init__ method, create a single private attribute that is the most time-efficient queue with a maximum capacity that we covered in the lectures. You should import the queues.py (normal implementation of circular queue in python) populate(useFile) modifies the deck by adding new dominoes face up to the rear of the deck. Nothing is returned. If useFile is True, the user should be prompted to provide the name of an input text file. If any problem occurs when opening the file, an error message should be displayed and the user should be re-prompted to provide the name of another input text file, until the file can be opened successfully. (See output_testWin.txt.) The input text file should contain information about the dominoes that will be added to the deck, in the same order as indicated in the file. (i.e. The first line of the text file corresponds to the first domino that should be added to the deck.) Each valid line of the text file will contain an integer, followed by a forward slash ('/'), followed by another integer, where the integers represent the number of dots on each end of the domino. (See the sample testWin.txt provided.) You cannot assume that all lines in the file will be valid, and you cannot assume that there will be information for exactly 28 dominoes in the file. If there is invalid data in the file or not 28 dominoes, you should raise an Exception with the argument "Cannot populate deck: invalid data in xx" (where xx is replaced with the filename), ensure the deck is empty, and close the file before leaving this method. If there is information about exactly 28 valid dominoes in the file, you can assume that those dominoes will form a full "double-six" set which should be added to the deck, in the same order that they appear in the file. If useFile is False, a complete "double-six" set of dominoes should be created, shuffled, and used to populate the deck. If useFile is not True or False, an AssertionError should be raised with the argument "Cannot populate deck: invalid argument provided." Nothing should be added to the deck in this case. deal() modifies the deck by removing the domino from the front of the deck, and returns that front domino, face down. Raise an Exception if the deck is empty, with the argument 'Cannot deal domino from empty deck'. This method should have an O(1) time efficiency. isEmpty() returns a Boolean value indicating whether there are no dominoes in the deck (True) or if there is at least one domino in the deck (False). size() returns the integer number of dominoes currently in the deck. __str__() returns the string representation of all of the dominoes in the deck. You can decide how this string should be formatted, but make it clear which is the front domino and be sure to show the number of dots on each domino (i.e. do not just show all dominoes as face down)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Relational Model A Retrospective Review And Analysis

Authors: C. J. Date

1st Edition

0201612941, 978-0201612943

More Books

Students also viewed these Databases questions