CS 2102 - Dterm 09

Homework 3 - Methods for Self-Referential Class Hierarchies

Due date: Friday, March 27 at 5pm

Assignment Goals


The Assignment

This assignment is a modified version of an assignment designed by Felliesen and Proulx, 2009.

For this assignment you should turn in two files: hw3-soccer.bjava and hw3-filesystem.bjava.

Problems

  1. For hw3-soccer.bjava, start with the code in soccer-team.bjava. Make sure you understand the code in this file before proceeding. The data definitions represent information about players in a youth soccer league. A soccer team is represented by the Captain class, which records the captain's name and age, the name of the team, and a roster of the other players on the team. The captain himself (or herself) is also considered to be a player. Team members who are not captains are represented by their name and age.

    As an indication that you understand the data representation, write as a comment at the top of your file (after the names of you and your partner) the names of all teams represented by the given data, and the names of the players on each team.

  2. Design the method count that counts the total number of players in a soccer league. Make sure you add to the templates as you develop methods (you do not have to provide a template for an empty list). Your templates should follow the structure we've used in class (in your template, show fields, methods, and methods for fields). Be precise when formulating the purpose statement for a method in a particular class (use "this" and "given" appropriately). Finally, make sure you provide adequate test cases for each method you develop, including helpers.

  3. Design the method listAll that produces a list of all players in a soccer league.

  4. Here's another problem with a similar stucture. In this problem, you'll be representing information about a file system on a computer. For hw3-filesystem.bjava, start with the code in files-directories.bjava. Create another set of data in the Examples class to represent the following file structure:
    Pages (a directory) contains:
          - index.html (file)
          - my-pics.html (file)
          - Pictures (directory) contains:
                   o house.jpeg (file)
                   o friend.jpeg (file)
                   o brother.jpeg (file)
          - Quotations (directory) contains:
                   o twain.txt (file)
                   o cervantes.txt (file)
    
    You may choose any sizes for the files (assume the sizes are in kiloBytes).

  5. Design the method totalSize that computes the size of a directory by adding the sizes of all the files in it. Additionallly, every directory requires 4 kiloBytes for keeping track of its list of files and subdirectories. Again, add to the templates as you go.

  6. Design the method allFiles that produces a list of all files of the given kind in a directory (and in any of its subdirectories and in any of their subdirectories...)

What to Turn In

Using web-based turnin, turn in two files, hw3-soccer.bjava and hw3-filesystem.bjavacontaining all code and documentation for this assignment. Both partners' names and wpi login names should appear in a comment at the top of both files.