Project #1
Due Date: beginning of class, Tuesday, Sept. 21, 2004
IF YOU CANNOT FINISH THIS PROJECT
ON TIME, YOU MUST WITHDRAW FROM THIS COURSE BECAUSE YOU ARE
NOT READY FOR IT. SWITCH TO CSci 53, THEN TAKE CSci 133 IN THE SPRING
SEMESTER.
The purpose of this project is to make sure everyone in this class
is "up to speed" with basic Java, so that starting with Project 2 we
can get into the real business of the course. You will start with an
existing program, and make a number of step-by-step modifications to
it. You are expected to test and submit all the versions.
This project depends mostly on pages 320-328 of Lewis & Loftus, Java Software Solutions.
Version 1:
Lewis & Loftus, p. 326-327, presents a program that counts the
number of uppercase and lowercase letters in a single line of text. The
source code for this program is in programs53/LetterCount.java.
Copy it into your csci133 directory. Then compile and execute this
program, and examine it carefully. In
this and the other versions, choose your test data systematically and
carefully, and explain how and why you chose each
test case.
Version 2:
Now copy LetterCount.java
into a new file, LetterCount2.java,
and modify it so that the uppercase and lowercase letter counts are
combined in a single array. For example, in "Madam, I'm Adam",
version 1 would report one uppercase A and 3 lowercase ones, but
Version 2 would report 4 A's:
a/A: 4.
Version 3:
Now copy LetterCount2.java
into LetterCount3.java.
Version 3 will display only the nonzero counts.
Version 4:
Now copy LetterCount3.java
into LetterCount4.java.
Version 4 will display, to the right of each nonzero count, a
horizontal line of asterisks, one asterisk per occurrence. For example,
a/A: 4 ****
Version 5:
LetterCount5.java
will
plot a vertical bar of
asterisks for each letter, using the class mbf.Screen to move the
cursor
to the desired screen position each time. Example:
|
|
|
*
|
*
|
* *
|
*
*
* * *
| * *
*
* *
* * *
| * *
*
* *
* * *
| * *
* *
* * * * *
| * *
* *
* * * * * *
| * *
* *
* * * * * *
| * *
* *
* * * * * * *
| * *
* * * * * *
* * * * * *
| * * *
* * * * * * * * * * *
* *
| * * * *
* * * * * * * * * * *
* *
| * * * * * * *
* * * * * * * * * * * *
*
| * * * * * * * * * * * * * * * *
* * * * * * * * * *
-----------------------------------------------------------
a b c d e f g h i j k l m
n o p q r s t u v w x y z
Version 6:
LetterCount6.java
will
track the letter frequencies in a multiline block of text instead of
just a single line. The end of the block of text will be indicated by a
line which contains only ###. To avoid typing
test
data repeatedly, you can store a block of text in a file using an
editor, and use redirection to cause readString to go to the
file for
input. Suppose this file is test.dat; then your Unix command line would
look like
jrun LetterCount6.java <test.dat
Version 7:
Finally, because each column can have no more than 20-some asterisks
(the terminal has 24 rows), LetterCount7.java
will scale the bars. Do this
by keeping track of the largest count in the array, then divide it by
the maximum column length (integer division!) to find the scale factor, or number of
occurrences each asterisk will represent. Then you can divide each
nonzero frequency by the scale factor to find the length of each column.
Example:
scale factor * = 4
|
|
|
|
*
|
*
|
*
|
*
|
* *
|
* *
*
* * *
| * *
*
* *
* * *
| * *
*
* *
* * *
| * *
* *
* * * * *
| * *
* *
* * * * * *
| * *
* *
* * * * * *
| * *
* *
* * * * * * *
| * *
* * * * * *
* * * * * *
| * * *
* * * * * * * * * * *
* *
| * * * *
* * * * * * * * * * *
* *
| * * * * * * *
* * * * * * * * * * * *
*
| * * * * * * * * * * * * * * * *
* * * * * * * * * *
-----------------------------------------------------------
a b c d e f g h i j k l m
n o p q r s t u v w x y z
What to submit:
Submit listings (.txt files) and test runs for all versions.
You need not submit a formal test plan, but you must provide
documentation that explains how you tested each version.
Grading:
Grading for this first project will be 0-20 points: 2 points for
version 1 and 3 points for the subsequent versions. Starting with
Project 2, we will use an entirely different grading formula.
(end of project)