L08

Due by the end of Tuesday, 8 March 2021


SUBMIT   /   CHECK

Today's Activities

Activity 1
Download the file ReverseLines.java. It is a program that reads up to six lines entered by the user and prints them back in reversed order. Test the program by entering three lines (followed by a blank line).
Enter up to 6 lines below. Enter a blank line to end input. One Two Three In reverse order they are: Three Two One
Test it again by trying to add seven lines. (NOTE: it will not let you enter the seventh line; it will immediately jump to printing the lines in reverse order after the sixth line has been entered.)
Enter up to 6 lines below. Enter a blank line to end input. One Two Three Four Five Six In reverse order they are: Six Five Four Three Two One

Revise the code so that it uses a List<String> instead of a String[]. Don't change any of its other behaviour (yet). It should still stop reading lines after six lines of input.

Activity 2
Revise the program again so that it allows the user to enter an (essentially) unlimited number of lines.
Enter up to 6 lines below. Enter a blank line to end input. One Two Three Four Five Six Seven Eight Nine Ten In reverse order they are: Ten Nine Eight Seven Six Five Four Three Two One

Oh! Better get rid of the mentions of limits...

A program to reverse lines entered by the user. Enter lines below. Enter a blank line to end input.
Activity 3
Add a loop to the program that goes thru the list of lines the user entered and removes any line that has the letter-string "sex" in it, and also changes to UPPER CASE all lines that have "North" in them.
If a line happens to have BOTH "sex" and "North" in it, it should be deleted. In that case it does not have to be changed to UPPER CASE.

Note that "sex" or "North" can be anywhere in the line, not just at the start. There is a String method that lets you check whether one String contains another. Use it.

Have it print the revised list of lines (in the original order) to confirm that the changes have been made.
A program to reverse lines entered by the user. Enter lines below. Enter a blank line to end input. Cornwall Somerset Middlesex Essex Wessex Kent York Northumberland Durham In reverse order they are: Durham Northumberland York Kent Wessex Essex Middlesex Somerset Cornwall Cornwall Somerset Kent York NORTHUMBERLAND Durham

Submit this/these files:

You will be graded on the following:

  1. ReverseLines has been submitted; it compiles and runs without crashing
  2. The lines variable has its type changed
  3. ... including the correct base type
  4. lines are added to the list in the most reasonable way
  5. blank line NOT added to the list
  6. code sets no limit on the number of lines added
  7. lines are printed out in reverse order
  8. Program revises the list
  9. ... by deleting lines with "sex" in them
  10. ... by upper-casing lines with "North" in them
  11. ... without missing or mishandling any lines
  12. ... and using a ListIterator loop

SUBMIT   /   CHECK