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.
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.
Develop the method smallerThan
that determines whether the
file is smaller than some maximum size that can be mailed as an attachment.
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.
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.
passengers in a cab just pay flat fee per mile
passengers in a limo must pay at least the minimum rental fee, otherwise they pay by the mile
passengers in a van pay $1.00 extra for each passenger
Develop the method
lowerPrice
that determines whether the fare for a given number of miles is lower than some amount.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.
Develop the class hierarchy to represent books in the discount bookstore.
Develop the method
salePrice
that computes the sale price of each book.Develop the method
cheaperThan
that determines whether on book is cheaper than another book.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).
Develop the class hierarchy to represent a list of books in the discount bookstore.
Describe in English examples of three book lists and represent them as objects in this class hierarchy.
develop the method
price
that computes the total for the sale, based on the sale price of each book.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.
Develop the method
maxlength
that determines the length of the
longest river segment.Develop the method
confluences
that counts the number of confluences in the river system.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