Home CPSC 330

Java Exercise 2

Objective

To become more familiar programming in Java with ArrayLists and Strings.

Task

One simple way of estimating the reading difficulty of a piece of text is to calculate the average word length. Estimating reading difficulty is used by elementary educators to determine how difficult a story may be for children of different ages to read. Stories with shorter average word length will generally be easier to read.

For example the text:


Spot is a dog.  Spot likes to run.  See spot run.

Has an average word length of 3.09.

On the other hand, the text:


In interpolating problems, spline interpolation is often referred to as polynomial interpolation.

Has an average word length of 7.0

You will write a program that will take in a sequence of words from the user and print out the average word length. Along with the word length, you should print out a difficulty rating of "easy", "medium" or "hard". If a piece of text has an average word length of less than 4, it should be classified as easy. If the average word length is greater than or equal to 4, but less than 6, it should be classified as medium. And if the average word length is greater than or equal to 6, it should be considered hard.


Details

  1. The user will enter a line of input that is composed of multiple words.
  2. Store these strings in an ArrayList.
  3. Calculate the average length of the words that are in the ArrayList.
  4. Print out the average word length, along with the classification of easy/medium/hard.

Submitting

When your program works, email the code to ifinlay@umw.edu.

Copyright © 2018 Ian Finlayson | Licensed under a Creative Commons Attribution 4.0 International License.