On this page:
3.1 Instructions
Practice Problems
Problem 1: Working with lists
8.5

Assignment 3: Designing methods for Complex Data, Practice with Lists and Accumulators

Goals: Practice working with lists. Learn to design methods and practice designing with accumulators.

3.1 Instructions

Be very, very careful with naming! Again, the solution files expect your submissions to be named a certain way, so that they can define their own Examples class with which to test your code. Therefore, whenever the assignment specifies:
  • the names of classes,

  • the names and types of the fields within classes,

  • the names, types and order of the arguments to the constructor,

  • the names, types and order of arguments to methods, or

  • filenames,

...be sure that your submission uses exactly those names.

Make sure you follow the style guidelines that handin enforces. For now the most important ones are: using spaces instead of tabs, indenting by 2 characters, following the naming conventions (data type names start with a capital letter, names of fields and methods start with a lower case letter), and having spaces before curly braces.

You will submit this assignment by the deadline using the handin submission system. You may submit as many times as you wish. Be aware of the fact that close to the deadline the system may have a long queue of submissions which means it takes longer for your code to be submitted - so try to finish early.

As always, you may only use techniques that have been covered in lectures so far in your solutions.

You will submit this assignment in two parts:

Due Dates:
  • Part 1: Monday, January 29th, 9:00 pm (with self-eval due Tues by 10pm)

  • Part 2: Thursday, February 1st, 9:00 pm

Practice Problems

Work out these problems on your own. Save them in an electronic portfolio, so you can show them to your instructor, review them before the exam, use them as a reference when working on the homework assignments.

Problem 1: Working with lists

Related files:
  ILoWord.java  

For all questions in this problem, be sure to follow the design recipe carefully:
  • Give sufficient examples of data, and sufficient tests, to test your methods thoroughly.

  • If you find yourself wanting to use a field-of-field or getters, stop. Fill out the template for each method, and figure out another design.

  • Think carefully about how to use dynamic dispatch, and where to define methods, to keep your code as simple and clean as possible.

Note: The following method defined for the class String may be useful:

// does this String come before the given String lexicographically? // produce value < 0 --- if this String comes before that String // produce value zero --- if this String is the same as that String // produce value > 0 --- if this String comes after that String int compareTo(String that)

In a future assignment, we will be creating a game that deals with lists of words. A word can be active or inactive in the game so we come up with the following definitions for a list of words:

Related files:
  ILoWord.java  

In this assignment, we will implement some methods for lists of words. Some of these may be relevant to the later game assignment, others are for practice.

All of the following methods should be defined in ILoWord. You may need to design helpers for some of the methods as well.