1.1-Introductie-Programmeren

Play with a list of words

Difficulty: Filled Filled Outlined

Do the exercises below, this time with a list of words. You can reuse parts of code from the previous exercise. Ask the user to enter as many words as he/she wants. It does not matter whether the user enters a single word or several words per entry. We are not going to distinguish that from each other.

You put all input in an ArrayList. The list is complete as soon as ENTER is given twice. Write code to make the program do the following things:

  1. Display the number of entries that have been entered.
  2. Display the content of the list. Tip: just use the print statement from the SaxionApp.
  3. Swap the first and last element of the list.
  4. Display the new contents of the list.
  5. Display the middle element in all CAPITAL LETTERS.
  6. Remove the middle element.
  7. Display the new content of the list. (see screenshot with the output).

Search the javadoc of ArrayList and String yourself how to get that data from the ArrayList.

Tip

  1. The same tip as in the previous exercise remains: Program in small steps and make sure you always have a correctly working program before adding the next step.
  2. Take a good look at the example development of this exercise. Commentary is provided between the lines of code showing other ways to achieve the same. It’s about the trade-off between efficient code and readable code.

    Example

Example

Example