This lab’s purpose is to provide students with experience in inheritance of classes and working with multiple
classes. It is recommended that students use command line tools and editors for this lab (though it is not strictly
speaking required). This lab will require students to build on their previous lab experience, in which a version of
the cowsay utility was created.Students will update the driver program file (cowsay.py) and also create two new classes – Dragon and
IceDragon. The Dragon class should extend the Cow class, and IceDragon must be derived from Dragon. As
before, heifer_generator.py is provided for you – but updated to handle the new Dragon class and its subtypes.(Please refer to specification for previous lab for a refresher.) Students may implement private attributes and
methods if they choose to do so. This is not required – it is purely optional. No public attributes / methods
should be added to the specification!
cowsay.py (Program Driver)Your program must accept command line arguments as follows:
python3 cowsay.py -l Lists the available cows
python3 cowsay.py MESSAGE Prints out the MESSAGE using the default COW
python3 cowsay.py -n COW MESSAGE Prints out the MESSAGE using the specified COW
In addition, this version of the utility handles a special set of Cow-derived Dragon class (and its
subclasses). Whenever a dragon-type cow is selected, the display of the message must be followed by a line
stating whether or not the dragon is fire-breathing:Cow Class
The Cow class must have all of the same methods as previously required (though students may add private
methods). The methods are repeated here, briefly, for reference.
__init__(self, name) // Constructor
get_name(self) // Returns name of this cow object
get_image(self) // Return image for this cow object
set_image(self, image) // Sets the image for this cow object to imageDragon Class
The Dragon class must be derived from the Cow class and must make all of its methods available. In addition,
Dragon must provide the following methods:
__init__(self, name, image)
Constructor; creates a new Dragon object with the given name and image.
can_breathe_fire()
This method should exist in every Dragon class. For the default Dragon type, it should always return True.IceDragon Class
The IceDragon class must be derived from the Dragon class and must make all of its methods available:
__init__(self, name, image)
Constructor; creates a new IceDragon object with the given name and image.
can_breathe_fire()
For the IceDragon type, this method should always return False.Submissions
NOTE: Your output must match the example output *exactly*.
Files:
Method:
cowsay.py, cow.py, dragon.py, ice_dragon.py
Submit on CanvasSample Output
>python3 cowsay.py Hello World!
Hello World!
^__^
(oo)_______
(__) )/
||—-w |
|| ||
>python3 cowsay.py -n kitteh Moew-Moew!
Moew-Moew!
(“`-‘ ‘-/”) .___..–‘ ‘ “`-._
` *_ * ) `-. ( ) .`-.__. `)
(_Y_.) ‘ ._ ) `._` ; “ -. .-‘
_.. `–‘_..-_/ /–‘ _ .’ ,4
( i l ),-” ( l i),’ ( ( ! .-‘
>python3 cowsay.py -lCows available: heifer kitteh dragon ice-dragon
>python3 cowsay.py -n ninja Hello world!
Could not find ninja cow!
>python3 cowsay.py -n dragon Firey RAWR
Fiery RAWR
|___/| / //|\
/0 0 __ / // |
/ / /_ / // |
_^_’/ /_ // |
//_^_/ /_ // |
( //) | // |
( / /) _|_ / ) // | _
( // /) ‘/,_ _ _/ ( ; -. | _ _.-~ .-~~~^-.
(( / / )) ,-{ _ `.|.-~-. .~ `.
(( // / )) ‘/ / ~-. _.-~ .-~^-.
(( /// )) `. { } /
(( / )) .—-~-. -‘ .~ `. __
///.—-..> _ -~ `. ^-`
///-._ _ _ _ _ _ _}^ – – – – ~ `—–‘
This dragon can breathe fire.>python3 cowsay.py -n ice-dragon Ice-cold RAWR
Ice-cold RAWR
|___/| / //|\
/0 0 __ / // |
/ / /_ / // |
_^_’/ /_ // |
//_^_/ /_ // |
( //) | // |
( / /) _|_ / ) // | _
( // /) ‘/,_ _ _/ ( ; -. | _ _.-~ .-~~~^-.
(( / / )) ,-{ _ `.|.-~-. .~ `.
(( // / )) ‘/ / ~-. _.-~ .-~^-.
(( /// )) `. { } /
(( / )) .—-~-. -‘ .~ `. __
///.—-..> _ -~ `. ^-`
///-._ _ _ _ _ _ _}^ – – – – ~ `—–‘
This dragon cannot breathe fire.
Reviews
There are no reviews yet.