Skip to content

Dates and Times

The presidents.tsv file includes fields with the first inauguration and end of term dates for each president (end of term is empty for the current president).

  1. Modify the President class to include String fields for the term begin and end dates.
  2. Create getters and setters.
  3. Modify (or re-create) the constructor to include these new fields.
  4. Add the new fields to toString

  5. Copy PresidentApp.java, naming the new copy PresidentAppDates.

  6. Make sure the new class's main instantiates a PresidentAppDates, not PresidentApp.

  7. Modify PresidentAppDates to capture these fields from the file, and pass them to the President constructor.
  8. Get this working and tested, printing out the full list of presidents.

  9. In the President class, change the datatypes of the term begin and end dates to LocalDate.

  10. Fix the getters, setters, and constructor.

  11. In PresidentApp modify loadPresidents to convert the date strings from the file to LocalDate values using a DateTimeFormatter.

  12. Add a new method to President: getTermLength. This should return a Period object representing the interval between the term begin and end dates. If the president has no term end date (that is, the current president) it should return the difference between term start and the current date.

  13. Include this in the president's toString.

Stretch Goals

  1. Create a method that takes a list of presidents and writes it as tab-separated values to a file.

  2. Records should be formatted so the existing code would be able to read and parse the records.

  3. When testing, be careful NOT to use resources/presidents.tsv as the output file!


Up