CS 201: Data Structures (Winter 2017)

HW03: Zoo displayer

Due: Wednesday, 01/18 at 22:00

This is a pair programming assignment. If you are on a team, this means that you and your partner should be doing the entirety of this assignment side-by-side, on a single computer, where one person is "driving" and the other is "navigating." Take turns every so often who is driving; you should each spend approximately 50% of the time driving.

Review the style guide. Starting from this assignment, you will be graded on coding style.

1. Goals

To build a non-trivial program with Java that includes both text and images, and work with the List ADT.

2. Setup

The code that you write for this assignment will build on top of the List ADT and one of the implementations of List that we've seen in class. The code will also use one additional class that is not part of the Java library:

You should not make any changes to this file. The Javadoc for this class is at:

You can get all of the files plus a sample zoo with image files here.

It may be useful to refer to the code from class and labs. The appendices of our book may also be useful. The official Java API documentation will likely be helpful for choosing what implementation of a List you'll use, and for seeing what methods are available.

3. Specification

For this assignment, you will write a program that reads from a text file with one line for each animal in a zoo. Your program will need to represent each animal as an instance of a class ZooAnimal. It will need to convert the text file data into a List<ZooAnimal>, sort the list, and print the list with the animals sorted alphabetically in one of two forms: as a display of animal images or as a text list. This will give you practice working with the List ADT, String, File, Scanner, loops, and simple classes. It will also let you see how you can display images, moving closer to more complicated applications.

The input file format

The input file is a text file that contains 0 or more lines of animals. Each line of the input file will represent a single animal via a comma-delimited list, like so:

animal-name,animal-species,birth-day,image-file-location

For example:

Lola,lemur,2005,zooPics/lemur.jpg Leanne,koala,2000,zooPics/koala2.jpg Sophie,giraffe,2010,zooPics/giraffe.jpg Kevin,koala,2007,zooPics/koala.jpg Ozzie,loris,2008,zooPics/loris.jpg Tapan,giraffe,1996,zooPics/giraffe2.jpg Leanne,koala,2011,zooPics/koala3.jpg

The command-line syntax

Your main method should be structured so that the program expects two command-line arguments: the first specifies the path of the input file and the second specifies the display method (either "picture" or "text"). Thus, if I had a properly formatted text file called ZooExample.txt in the same directory as ZooDisplayer.java and wanted to show a picture of the zoo, I would type:

java ZooDisplayer ZooExample.txt picture

If ZooExample.txt was in a subdirectory called data and I wanted to show a text output of the zoo, I would type:

java ZooDisplayer data/ZooExample.txt text

(Note: there's nothing special you have to do to handle ZooExample.txt versus data/ZooExample.txt. File will do the right thing in both without you having to think about it.)

The expected output

Your program should produce output based on whether "picture" or "text" was chosen:

Sorted order for zoo animals is alphabetized by animal species, then name in case of identical species, and then year of birth in case of identical names (with older animals appearing before younger animals). Like a previous homework, I want you to write your own sort. You'll learn some additional sorting methods later this term; for now, you can try looking in your book for a sorting method if you don't remember one. However, please make sure you're not copying code directly out of the book (you should be able to explain any code you submit!), and if you rely heavily on a book example, please make sure to cite it in comments. You should not use any built-in Java sorting methods.

For example, if text display was chosen for the zoo above, the output should be:

Sophie giraffe 7 Tapan giraffe 21 Kevin koala 10 Leanne koala 17 Leanne koala 6 Lola lemur 12 Ozzie loris 9

If picture display was chosen, this zoo would look like this:

For the purposes of this assignment, you may consider an animal's age to be the number of years back from 2017 that the animal was born. For example, an animal born in 2015 would be 2.

4. Code notes

5. Submission and grading

Your program must consist of at least the files ZooDisplayer.java and ZooAnimal.java, but you may write others. You have a lot of freedom to design your solution here. Please make sure that every file you submit has your name and your partner's name at the top.

Submit all of the Java source files that you wrote that are necessary to make your program work. Do not submit any .class files for the classes that you write, and also do not submit the EzImage.java file that was provided.

To submit your files, prepare a zip (or tar) archive. Name the file [yourUsername]-[yourPartner'sUsername] (without the square brackets; this makes it easier for the grader). Double-check your zip file: copy it to somewhere else, unzip it, copy over the files that I provided to you, and try to compile and run your code. Also, make sure to not include extraneous files or directories (e.g., I don't need your image files; exception: if you want to include a screenshot of your favorite zoo display, please include it in your submission or post it to share with your classmates on Moodle!). When you're satisfied that your submission is ready, one of you should upload the zip file to Moodle.

Assignment requirements

This is a partial list of the things that we'll be looking for when evaluating your work:

Grading

This assignment modified from one designed by Anna Rafferty.

Start early, have fun, and discuss questions on Moodle.