Computer Science 252
Problem Solving with Java

Spring 2016, The College of Saint Rose

Lab 12: ArrayList Practice
Due: 11:59 PM, Sunday, April 17, 2016

In this fairly short lab, you will gain experience using ArrayLists by completing two programs: one graphical and one text-based.

Both programs will be graded as practice programs.

You may work alone or with a partner on this lab. Only one submission per group is needed.

Getting Set Up

Since a substantial part of each program is provided for you, begin by downloading the starter BlueJ projects is provided.

Working solutions to all programs can be downloaded here for the number drag game and here for the word counter.

The Number Drag Game

In the NumberDragGame folder of the starter, you will find 4 classes that work together to form a partial implementation of a simple numbers game. When the program starts up, a simple GUI is created, and a set of 5 boxes, or "target areas," are created on the Objectdraw canvas. Each box has two numbers: the top is the box's current value, and the bottom is a goal value for the box. When the "Start" button is pressed, numbers begin to appear on the canvas, and the goal is to drag those numbers to the boxes to adjust each box's value to match its goal value. If the current value of the box is below the goal, new numbers dragged in will be added. If the current valus is above the goal, new numbers dragged in will be subtracted. The object of the game is to drag the fewest number of these numbers into the boxes, and in the shortest amount of time, to get all of the boxes to have their values match their goals.

Again, much of this functionality is provided. The main thing missing here is that only the most recently-created number is draggable. Your task is to add code to the NumberDragGame class that allows the user to drag any of the numbers into the target boxes. Hopefully, given the title of this lab, you will realize that this involves introducing an ArrayList to this program.

A Word Frequency Counter

The second program is in the WordCount folder in the starter. This program in the WordCount class simply reads a file, word by word. Your task is to augment it so it keeps track of how many times it encounters each unique word in the input file. At the end, it should print out each word and how many times it was encountered, and a report of how many unique words were encountered. To keep things simple, don't worry about punctuation - it is just part of the word.

For example, if the input file contains:

I could not, would not, on a boat.
I will not, will not, with a goat.
I will not eat them in the rain.
I will not eat them on a train.
Not in the dark! Not in a tree!
Not in a car! You let me be!
I do not like them in a box.
I do not like them with a fox.
I will not eat them in a house.
I do not like them with a mouse.
I do not like them here or there.
I do not like them ANYWHERE!
I do not like green eggs and ham!
I do not like them, Sam-I-am.

the output should be:

Word frequency counts:
I: 12
could: 1
not,: 4
would: 1
on: 2
a: 9
boat.: 1
will: 5
with: 3
goat.: 1
not: 10
eat: 3
them: 8
in: 6
the: 2
rain.: 1
train.: 1
Not: 3
dark!: 1
tree!: 1
car!: 1
You: 1
let: 1
me: 1
be!: 1
do: 7
like: 7
box.: 1
fox.: 1
house.: 1
mouse.: 1
here: 1
or: 1
there.: 1
ANYWHERE!: 1
green: 1
eggs: 1
and: 1
ham!: 1
them,: 1
Sam-I-am.: 1
41 unique words found.

Files containing the above excerpt from Dr. Seuss's Green Eggs and Ham and a transcript of Abbott and Costello's Who's on First? routine are provided in the starter project as example inputs for testing.

Again, an ArrayList is a great way to accomplish this. The custom class WordFrequency is also likely to be very helpful to you as you work to complete the required functionality.

Submitting

Before 11:59 PM, Sunday, April 17, 2016, submit your lab for grading. To complete the submission, email a copy of your lab (a .7z or .zip file containing your project directory) to terescoj AT strose.edu.

Grading

This assignment is worth 20 points, which are distributed as follows:

> FeatureValueScore
NumberDragGame all numbers draggable/droppable 6
NumberDragGame no exceptions generated 4
WordCount list of unique words 5
WordCount word frequency counts 3
WordCount unique word count 2
Total 20