Due on Wednesday 30th January
You should submit solutions to this h/w via the cms system by 11pm on Wednesday.
Since the primary point of this h/w is to ensure that everyone is comfortable writing
a simple i/o program in Java, each person should sumbit their own work, but you are
strongly encouraged to talk to folk to get such help as you need, whether they are
course staff, fellow students, or others -- though do ensure that by the time you
submit your work that you're comfortable with the ideas involved and feel that you
could do it entirely yourself were you to be asked to.
Question 1:
This is in two related parts. Firstly you should write a simple Java program which
will invite the user to enter a string of text at the keyboard and display some basic
analysis of the text. All we're looking for in the first stage is to say
- how many characters were entered,
- how many words were entered (a 'word' is a string of characters separated by
spaces ... include the intial word and final word),
- what the average word length is (give this as a decimal).
When you have this working, add in code to be able to say what the most common non-space
character is (if there are several with the same top frequency, then list them all).
The second part is to repeat the above, but this time reading from a file and writing
the results to a file as well as displaying the results on the screen. The output file
should be called "answers.txt", and the input file can be found at
inputFile.txt
Clarification: Several folk have been asking what constitues an allowable 'letter'
for a word when counting. Obviously it would be nice to exclude punctuation (although hyphens
would count some of the time, and an apostrophe would count sometimes, and ...). As can be seen,
it's not altogether easy to decide when an ascii character should count. So since this is meant
as a relatively gentle first homework, I suggest that we take a pragmatic approach of counting
all non-space characters (spaces, tabs, newlines, etc. 'are' spaces) as allowable characters for
building a word. In this case the string "these 88 words have avg length 3.68 chars.." would have 8 'words'
with "88", "3.68", and "chars.." being 'words'. Thus you need only separate a string via the
space and tab (\t) characters, which should make things much easier for you when building a suitable if or
switch statement.