CSCI 202 Homeworks 9

Purpose

To practice with Deques and Strings before moving to search and sorting.

Due dates

This assigment will be worked on in class on March 19 and 21. The completed assignment must be submitted as Homework 9 of CSCI 202 on Moodle by 11:00 PM Tuesday, March 27.

The tasks

In this assignment you are to complete a long series of small tasks.

Part 1

Create a main Java application within a class TestDriver of package homework09.

Part 2

Within the class TestDriver, create “dummy” static methods generateDeque and generateArray. Both should receive a single integer as a parameter.

The generateDeque method should return a Deque of Strings.

The generateArray method should return an array of Strings.

To keep Java and NetBeans happy, have the two methods return the three Strings "one", "two", and "three". Because we are using the Deque as a list, rather than stack, use the addLast method to add new elements.

Part 3

Within the class TestDriver, write a method printArray that prints an array of Strings to System.out. The printArray has a single argument: the array to be printed.

Part 4

Within the class TestDriver, write a method printDeque that prints an Deque of String to System.out. The printArray has a single argument: the Deque to be printed.

Part 5

With the main method of TestDriver, call both generateDeque and generateArray to create a Deque and array of Strings and then call printDeque and printArray to print the Deque and array.

Part 6

Write a helper method to generate a four-character String where the characters are randomly choosen from the lower case letters 'a' to 'z'.

Part 7

Using your helper method modify the generateDeque and generateArray methods so that they return, as appropriate, a Deque or array of size n, where n is the argument to the generate method, of random four-character Strings. If n is negative, return an empty Deque or array.

Part 8

Remove the code within the main routine. Add two loops within the main routine. Each should be executed five times.

In each loop, generate a random number between 202 and 255. In the first loop pass the random number to generateArray and then use printArray to print the array returned by generateArray. In the second loop, similarly generate and print random Deques.