COP3502 Lab 7: Return of the Cow Solved

35.00 $

Category:
Click Category Button to View Your Next Assignment | Homework

You'll get a download link with a: zip solution files instantly, after Payment

Securely Powered by: Secure Checkout

Description

5/5 - (2 votes)

Overview

This lab’s purpose is to provide students with experience in file I/O. 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 add one new class – FileCow. The FileCow class should extend the Cow class. As before, HeiferGenerator.java is provided for you – but updated to handle the new FileCow class. (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 built-in Cow java cowsay -f COW MESSAGE          Prints out the MESSAGE using the specified file Cow

 

In addition, this version of the utility handles a special set of Cow-derived FileCow objects. The HeiferGenerator will automatically create FileCow objects (using the FileCow constructor) from files in the “cows” directory.

>java Cowsay -l

Regular cows available: heifer kitteh dragon ice-dragon File cows available: moose turkey turtle tux

 

 

 

Previous Work

The following classes, developed previously, are required for this lab to function.

 

Cow

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)

 

Dragon (extends Cow)

// Sets the image for this cow object to image

public Dragon(String name, String image)       // Constructor public boolean canBreatheFire()                 // Defaults to true

 

IceDragon (extends Dragon)

public IceDragon(String name, String image) // Constructor public boolean canBreatheFire()                 // Returns false

 

 

FileCow Class

The FileCow class must be derived from the Cow class. In addition, FileCow must add the following behavior:

public FileCow(String name, String filename)

Constructor; creates a new FileCow object with the given name and an image loaded from filename.

 

If the file cannot be loaded, it should throw a new RuntimeException with the message “MOOOOO!!!!!!” This should be the only public constructor for the FileCow class!

 

public void setImage()

Should immediately throw a new RuntimeException with the message “Cannot reset FileCow Image”.

 

 

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, FileCow.java, HeiferGenerator.java Method: Submit on Canvas

 

 

 

 

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

Regular cows available: heifer kitteh dragon ice-dragon

File cows available: moose turkey turtle tux

 

>java Cowsay -n ninja Hello world!

Could not find ninja cow!

 

>java Cowsay -f tux Do you have any herring?

 

Do you have any herring?         .–.

|o_o |

|:_/ |

//   \ \

(|     | )

/’\_   _/`\

\___)=(___/

 

 

>java Cowsay -f alien Earth is ours!

Could not find alien cow!

 

>java Cowsay -f kitteh MEOW!!!

Could not find kitteh cow!

 

>java Cowsay -n tux How about tuna? Could not find tux cow!

  • Lab07.zip