L01
Due by the end of this meeting
SUBMIT
/
Submission Summary
Words (Review of Arrays, Loops, Methods and Conditionals)
Synopsis
Write a program Lab01
to read in multiple words
and then redisplay them based on their length.
The user is prompted whether they want to show words that are
longer, shorter, or equal to a length they provide.
The activity continues until the user asks to quit.
Details
Write a program that behaves as follows:
-
It prompts for and reads the number of words the user has.
-
It prompts for and reads that many words.
-
It repeats the following until the user chooses the quit option:
-
It prompts for a command from long, short, equal and quit.
-
For each of the long/short/equal options it
prompts for the length,
then reports the appropriate words one per line.
-
For unknown options it prints an error message.
Other requirements:
-
Create a method to read an integer value.
It prompts for input using a String given to it,
reads the user's response,
tidies the input stream,
and returns the user's response.
(It does not need to do any error checking on the value,
but if it does,
the number it reads should be positive.)
-
Use an array to hold the words.
-
Use a while loop to read commands until the user chooses quit.
-
Commands are case-insensitive, so QUIT, Quit and quit
(for example)
all result in the program ending.
-
Create a method for each option (long/short/equal).
-
Use a for-loop or enhanced-for-loop (AKA a for-each loop)
to go thru the array
to find the appropriate words to print.
-
The printed words should be preceded by a bullet
(a star, circle or hyphen,
with a space on either side of it).
The following are examples
of running the Lab01 program for L01.
Text in blue shows where the user enters input,
with the showing
where the user presses the enter key.
How many words do you have? 10
Enter them below:
one two three four five six seven eight nine ten
Enter your choice: Long, Short, Equal or Quit? Long
How long is the shortest word to show? 5
Here are the words:
- three
- seven
- eight
Enter your choice: Long, Short, Equal or Quit? short
How long is the longest word to show? 3
Here are the words:
- one
- two
- six
- ten
Enter your choice: Long, Short, Equal or Quit? equal
How long should the words be? 4
Here are the words:
- four
- five
- nine
Enter your choice: Long, Short, Equal or Quit? quit
How many words do you have? 5
Enter them below:
nonmonotonic reasoning is nonclassical logic
Enter your choice: Long, Short, Equal or Quit? short
How long is the longest word to show? 5
Here are the words:
- is
- logic
Enter your choice: Long, Short, Equal or Quit? EQUAL
How long should the words be? 10
Here are the words:
Enter your choice: Long, Short, Equal or Quit? what?
I don't recognize that command!
Enter your choice: Long, Short, Equal or Quit? long
How long is the shortest word to show? 10
Here are the words:
- nonmonotonic
- nonclassical
Enter your choice: Long, Short, Equal or Quit? quit
Submit this/these files:
SUBMIT
/
Submission Summary