©2006 Felleisen, Proulx, et. al.
2 Complex Data
2.1 Problem (4.5)
Consider this generalization of exercise 2.3:
Develop a program that creates a gallery from three different kinds of media: images (gif), texts (txt), and sounds (mp3). All have names for source files and sizes (number of bytes). Images also include information about the height, the width, and the quality of the image. Texts specify the number of lines needed for visual representation. Sounds include information about the playing time of the recording, given in seconds.
Develop a data representation for these media. Then represent these three examples with objects:
an image, stored in flower.gif; size: 57,234 bytes; width: 100 pixels; height: 50 pixels; quality: medium;
a text, stored in welcome.txt; size: 5,312 bytes; 830 lines;
a music piece, stored in theme.mp3; size: 40960 bytes, playing time 3 minutes and 20 seconds. Solution
2.2 Problem (4.6)
Take a look at the class diagram in figure 1. Translate it into interface and class definitions. Also create instances of each class. Solution
+---------------------+ | ITaxiVehicle | +---------------------+ / \ --- | | +----------------+--------------------+ | | | +------------------+ +------------------+ +------------------+ | Cab | | Limo | | Van | +------------------+ +------------------+ +------------------+ | | | int minRental | | boolean access | | int idNum | | int idNum | | int idNum | | int passengers | | int passengers | | int passengers | | int pricePerMile | | int pricePerMile | | int pricePerMile | +------------------+ +------------------+ +------------------+
Figure 1: A class diagram for taxis
Last modified: Wednesday, December 28th, 2005 10:51:30amHTML conversion by TeX2page 20050501