5  Lab Wednesday am:

Methods for Unions

Recall problem 2: that described a revision of the problem in exercise 2:
Problem Develop class definitions for a collection of classes that represent several different kinds of files. All files have name and size given in bytes. Image files (gif) also include information about the height and width of the image, and the quality of the image. Text files (txt) include information about the number of characters, words, and lines. Sound files (mp3) include information about the playing time of the recording, given in seconds.
  1. Develop the method timeToDownload that computes how long it takes to download a file at some network connection speed, typically given in bytes per second. The size of the file is given in bytes.

  2. Develop the method smallerThan that determines whether the file is smaller than some maximum size that can be mailed as an attachment.

  3. Develop the method sameName that determines whether the name of a file is the same as some specified name.

Recall the exercise  2: Take a look at the data definition in figure  5.
                 +---------------------+
                 | ATaxiVehicle        |
                 +---------------------+
                 | int idNum           |
                 | int passangers      |
                 | int pricePerMile    |
                 +---------------------+
                         / \
                         ---
                          |
      +----------------+--+-----------------+
      |                |                    |
 +--------+     +---------------+   +----------------+
 | Cab    |     | Limo          |   | Van            |
 +--------+     +---------------+   +----------------+
 |        |     | int minRental |   | boolean access |
 +--------+     +---------------+   +----------------+

Figure: A class diagram for taxis

Translate it into a collection of classes. Also create instances of each class.
  1. Develop the method fare that computes the fare in a given vehicle, based on the number of miles travelled, and using the following formulas for different vehicles.

    1. passengers in a cab just pay flat fee per mile

    2. passengers in a limo must pay at least the minimum rental fee, otherwise they pay by the mile

    3. passengers in a van pay $1.00 extra for each passenger

  2. Develop the method lowerPrice that determines whether the fare for a given number of miles is lower than some amount.

  3. Develop the method cheaperThan that determines whether the fare in one vehicle is lower than the fare in another vehicle for the same number of miles.

Consider this revision of the problem in exercise 2:
Problem Develop a program that assists a bookstore manager in a discount bookstore. The program should keep a record for each book. The record must include its title, the author's name, its price, and its publication year. In addition, the books There are three kinds of books with different pricing policy. The hardcover books are sold at 20% off. The sale books are sold at 50% off. The paperbacks are sold at the list price.
  1. Develop the class hierarchy to represent books in the discount bookstore.

  2. Develop the method salePrice that computes the sale price of each book.

  3. Develop the method cheaperThan that determines whether on book is cheaper than another book.

  4. Develop the method sameAuthor that determines whether some book was written by the specified author.

Methods for lists

Develop a program that assists a bookstore manager in a discount bookstore (see exercise 5).
  1. Develop the class hierarchy to represent a list of books in the discount bookstore.

  2. Describe in English examples of three book lists and represent them as objects in this class hierarchy.

  3. develop the method price that computes the total for the sale, based on the sale price of each book.

  4. Develop the method thisAuthor that produces a list of all books by this author in the bookstore list.

Develop the following additional methods for the river system.
  1. Develop the method maxlength that determines the length of the
    longest river segment.

  2. Develop the method confluences that counts the number of confluences in the river system.

  3. Develop the method locations that produces a list of all locations on this river - the sources, the mouths, and the confluences.

Methods for trees and similar structures

  • Refer to the problem  3: develop methods to count the number of ancestors, to determine whether there is a person with some name in the tree, etc.

  • Refer to the problem  3: Develop methods to find whether a given player is in the list, count the players, etc.