To practice with Deque
s and String
s
before moving to search and sorting.
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.
In this assignment you are to complete a long series of small tasks.
Create a main Java application within a class TestDriver
of package homework09
.
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
String
s.
The generateArray
method should return an array
of String
s.
To keep Java and NetBeans happy, have the two methods return
the three String
s "one"
, "two"
,
and "three"
. Because we are using the
Deque
as a list, rather than stack, use the addLast
method to
add new elements.
Within the class TestDriver
, write a method
printArray
that prints
an array of String
s to System.out
.
The printArray
has a single argument:
the array to be printed.
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.
With the main method of TestDriver
, call both
generateDeque
and
generateArray
to create
a Deque
and array of String
s and then
call printDeque
and printArray
to print
the Deque
and array.
Write a helper method to generate a four-character String
where
the characters are randomly choosen from the lower case letters
'a'
to 'z'
.
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 String
s.
If n
is negative, return an empty Deque
or array.
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 Deque
s.