COP3502 Lab 6: The Cow Strikes Back Solution

35.00 $

Category:

Description

5/5 - (1 vote)

Overview

This lab’s purpose is to provide students with experience in inheritance of classes and working with multiplace 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.

 

Specification

Students will update the driver program class (Cowsay) and also create two new classes – Dragon and IceDragon. The Dragon class just extend the Cow class, and IceDragon must be derived from Dragon. As before, HeiferGenerator.java 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 protected attributes and methods if they chose to do so. This is not required – it is purely optional. No public attributes / methods should be added to the specification!

 

Cowsay Class (Program Driver)

Your program must accept command line arguments as follows:

 

java cowsay -l                                Lists the available cows

java cowsay MESSAGE Prints out the MESSAGE using the default COW java cowsay -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 classes (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:

>java Cowsay -n dragon Fiery RAWR

 

Fiery RAWR

\

\

\

|\___/|       /\  //|\\

/0  0  \__   /  \// | \ \

/     /  \/_ /   //  |  \  \

\_^_\’/   \/_   //   |   \   \

//_^_/     \/_ //    |    \    \

( //) |        \ //     |     \     \

( / /) _|_ /   )   //     |      \     _\

( // /) ‘/,_ _ _/  ( ; -.   |    _ _\.-~       .-~~~^-.

(( / / )) ,-{        _      `.|.-~-.          .~         `.

(( // / ))  ‘/\      /                ~-. _.-~      .-~^-.  \

(( /// ))      `.   {            }                 /      \  \

(( / ))     .—-~-.\        \-‘               .~         \  `.   __

///.—-..>        \            _ -~            `.  ^-`  \               ///-._ _ _ _ _ _ _}^ – – – – ~                   `—–‘

This dragon can breathe fire.

  >java Cowsay -n ice-dragon Ice-cold RAWR

 

Ice-cold RAWR

\

\

\

|\___/|       /\  //|\\

/0  0  \__   /  \// | \ \

/     /  \/_ /   //  |  \  \

\_^_\’/   \/_   //   |   \   \

//_^_/     \/_ //    |    \    \

( //) |        \ //     |     \     \

( / /) _|_ /   )   //     |      \     _\    ( // /) ‘/,_ _ _/  ( ; -.   |    _ _\.-~

(( / / )) ,-{        _      `.|.-~-.

(( // / ))  ‘/\      /                ~-. _.-~

(( /// ))      `.   {            }

(( / ))     .—-~-.\        \-‘

///.—-..>        \            _

///-._ _ _ _ _ _ _}^ – – – – ~

 

This dragon cannot breathe fire.

Cow Class

The Cow class must have all of the same methods as previously required, though students may add protected and private methods.) The methods are repeated here, briefly, for reference.

 

public Cow(String name) // Constructor
public String getName() // Returns name of this cow object
public String getImage() // Return image for this cow object
public void setImage(String image) // Sets the image for this cow object to image

 

Dragon 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:

public Dragon(String name, String image)

Constructor; creates a new Dragon object with the given name and image. This should be the only public constructor for the Dragon class!

 

public boolean canBreatheFire()

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:

public Dragon(String name, String image)

Constructor; creates a new IceDragon object with the given name and image. This should be the only public constructor for the IceDragon class!

 

public boolean canBreatheFire()

For the IceDragon type, this method should always return false.

 

Submissions

NOTE: Your output must match the example output *exactly*. If it does not, you will not receive full credit for your submission!

 

Files:  Cowsay.java, Cow.java, Dragon.java, IceDragon.java, HeiferGenerator.java Method: Submit on ZyLabs

Sample Output

 

>javac Cowsay.java

>java Cowsay Hello World!

 

Hello World!

\

\

\

^__^

(oo)\_______

(__)\       )\/\

||—-w |

||     ||

 

>java Cowsay -n kitteh Moew-Moew!

Moew-Moew!

\

\

\

(“`-‘  ‘-/”) .___..–‘ ‘ “`-._

` *_ *  )    `-.   (      ) .`-.__. `)

(_Y_.) ‘ ._   )   `._` ;  “ -. .-‘

_.. `–‘_..-_/   /–‘ _ .’ ,4

( i l ),-”  ( l i),’  ( ( ! .-‘

 

>java Cowsay -l

Cows available: heifer kitteh dragon ice-dragon

 

>java Cowsay -n ninja Hello world!

Could not find ninja cow!

 

>java Cowsay -n dragon Firey RAWR

 

Fiery RAWR

\

\

\

|\___/|       /\  //|\\

/0  0  \__   /  \// | \ \

/     /  \/_ /   //  |  \  \

\_^_\’/   \/_   //   |   \   \

//_^_/     \/_ //    |    \    \

( //) |        \ //     |     \     \

( / /) _|_ /   )   //     |      \     _\

( // /) ‘/,_ _ _/  ( ; -.   |    _ _\.-~       .-~~~^-.

(( / / )) ,-{        _      `.|.-~-.          .~         `.

(( // / ))  ‘/\      /                ~-. _.-~      .-~^-.  \

(( /// ))      `.   {            }                 /      \  \

(( / ))     .—-~-.\        \-‘               .~         \  `.   __

///.—-..>        \            _ -~            `.  ^-`  \

///-._ _ _ _ _ _ _}^ – – – – ~                   `—–‘

 

This dragon can breathe fire.

 

>java Cowsay -n ice-dragon Ice-cold RAWR

 

Ice-cold RAWR

\

\

\

|\___/|       /\  //|\\

/0  0  \__   /  \// | \ \

/     /  \/_ /   //  |  \  \

\_^_\’/   \/_   //   |   \   \

//_^_/     \/_ //    |    \    \

( //) |        \ //     |     \     \

( / /) _|_ /   )   //     |      \     _\

( // /) ‘/,_ _ _/  ( ; -.   |    _ _\.-~       .-~~~^-.

(( / / )) ,-{        _      `.|.-~-.          .~         `.

(( // / ))  ‘/\      /                ~-. _.-~      .-~^-.  \

(( /// ))      `.   {            }                 /      \  \

(( / ))     .—-~-.\        \-‘               .~         \  `.   __

///.—-..>        \            _ -~            `.  ^-`  \

///-._ _ _ _ _ _ _}^ – – – – ~                   `—–‘

 

This dragon cannot breathe fire.