IT 210 Programming Assignment 6 solution

$24.99

Original Work ?
Category: You will Instantly receive a download link for .ZIP solution file upon Payment

Description

5/5 - (2 votes)

In this programming assignment you will create the DooDad and DooDadX classes. These
are classes of fictitious objects whose behavior is defined below. Each DooDad object has a
color, weight, value, and serialNumber. Serial numbers are assigned sequentially starting
with a base value of 1000. Getters should be provided for each of the four instance
attributes. No setters are to be provided. Only the colors “red”, “green”, and “blue” are
possible. The weight and value are floating point values.
When two DooDads are combined with an arithmetic operator, the resulting new DooDad
has the following characteristics:
+ operator: if the two serial numbers differ by one, multiply the two values to get the new
value, otherwise add the values. The new DooDad has the color of the left Doodad and the
maximum of the two weights.
– operator: the new DooDad should use the color of the left Doodad, the weight of the right
DooDad and the minimum of the two values.
* operator: use the maximum of the two weights, the average of the two values and the
color selected by the following rule: if the colors are the same, use that color, otherwise
choose the color that is different than either.
/ operator: the same as * except use the minimum of the two weights.
% operator: create a new DooDad whose color is “red”, with a weight that is the sum of
both weights and whose value is the weight of the right DooDad
It is recommended that you used a “private” method (one whose name begins with an
underscore character ) as a helper method to do the color selection for * and / operations.
DooDads should provide a __repr__ to provide the string format in the example below.
The DooDadX class inherits from the DooDad class and differs from it in the following
ways:
• serial numbers are negative integers (see output below).
• The % operator (when the left operand is a DooDadX) will produce a green
DooDadX whose weight is the maximum of the two weights. Value is computed the
same as for the % operator in the DooDad class
• The fact that this is a DooDadX instead of a DooDad is noted when you print a
DooDadX
The following testing code is provided on D2L and should be included at the bottom of the
PA6.py file that you submit. Don’t change this code because I will likely also import your
classes from another program and they must be named and work as specified.
if __name__ == “__main__”:
doodads = [] # will hold both DooDad’s and DooDadX’s
doodads.append(DooDad(“red”,5,10))
doodads.append(DooDad(“red”,8,9))
doodads.append(DooDad(“blue”,20,15))
doodads.append(DooDad(“green”,2,5))
doodads.append(DooDadX(“blue”,10,12))
doodads.append(doodads[0] + doodads[1])
doodads.append(doodads[2] + doodads[0])
doodads.append(doodads[3] – doodads[1])
doodads.append(doodads[1] – doodads[3])
doodads.append(doodads[0] * doodads[1])
doodads.append(doodads[0] * doodads[2])
doodads.append(doodads[0] / doodads[3])
doodads.append(doodads[2] % doodads[4])
doodads.append(doodads[4] % doodads[2])
for doodad in doodads:
print(doodad)
Output from the above:
red DooDad weighing 5 grams. Value = 10 points. S/N=1001
red DooDad weighing 8 grams. Value = 9 points. S/N=1002
blue DooDad weighing 20 grams. Value = 15 points. S/N=1003
green DooDad weighing 2 grams. Value = 5 points. S/N=1004
blue DooDadX weighing 10 grams. Value = 12 points. S/N=-1005
red DooDad weighing 8 grams. Value = 90 points. S/N=1006
blue DooDad weighing 20 grams. Value = 25 points. S/N=1007
green DooDad weighing 8 grams. Value = 5 points. S/N=1008
red DooDad weighing 2 grams. Value = 5 points. S/N=1009
red DooDad weighing 8 grams. Value = 9.5 points. S/N=1010
green DooDad weighing 20 grams. Value = 12.5 points. S/N=1011
blue DooDad weighing 2 grams. Value = 7.5 points. S/N=1012
red DooDad weighing 30 grams. Value = 10 points. S/N=1013
green DooDadX weighing 20 grams. Value = 20 points. S/N=-1014
Submit your program to the designated D2L dropbox. Your program should be named
PA6.py Remember that early submissions gain a bonus percent: 1 day early à 10%; 3 or
more days early à 20%.