DOC PREVIEW
Stanford CS 106A - Study Notes

This preview shows page 1 out of 2 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 2 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 2 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Eric Roberts Handout #60CS 106A March 2, 2010Section Handout #8: Data Structure DesignThe idea for the FlyTunes example comes from a handout by Mehran Sahami.Much of the complexity of a project like Adventure comes in the design of the datastructure. To make sure that everyone starts out on a reasonable path, we’ve done thatdesign work for you, which makes the assignment quite a bit easier. At the same time,taking the design phase out of the assignment means that you get relatively little practicewith one of the more important aspects of programming. To remedy that, this week’ssection consists of two problems involving data structure design. The first is similar tothe type of data structure question that we like to ask on the final exam; the second is a bitmore open-ended and allows you to think about a more significant problem in datarepresentation than you could solve in an exam setting.1. Designing a CalendarDate classImplement a class named CalendarDate that exports the following methods:• A constructor that allows the client to create a new date by supplying the month, day,and year as integer values. Thus, it should be possible to write the followingdeclarations that use the CalendarDate class:CalendarDate independenceDay = new CalendarDate(7, 4, 1776);CalendarDate bastilleDay = new CalendarDate(7, 14, 1789);CalendarDate today = new CalendarDate(3, 2, 2010);CalendarDate tomorrow = new CalendarDate(3, 3, 2010);• Three getter methods—getMonth, getDay, getYear—that allow clients to retrievethese components of a CalendarDate object.•A compareTo method that compares the current CalendarDate object with a secondCalendarDate object supplied as an argument. The compareTo method shouldreturn—in much the same way as it does for the String class—an integer that is lessthan 0 if this date comes before the argument date, an integer greater than 0 if this datecomes after the argument date, and 0 if the two dates are the same. Thus, given theearlier declarations, the expressionindependenceDay.compareTo(bastilleDay)should return a negative integer, because the original Independence Day occurredearlier than the original Bastille Day. Using the same logictomorrow.compareTo(today)should return a positive integer, andtoday.compareTo(today)should return 0.•A toString method that converts a CalendarDate object into a String in thefollowing form:Month day, yearwhere Month is the full name of the month, day is the day of the month, and year is theyear. For example, the call– 2 –independenceDay.toString()should return the string "July 4, 1776".As you write this program, you should keep the following points in mind:• You may assume that all arguments to the constructor are valid and need not checkthem to see if they represent a legal date.• Your class definition should not include any instance variables that are visible outsidethe CalendarDate class itself.2. Designing a data structure for a FlyTunes music programMost of you have presumably used a digital music application such as iTunes, probablywithin the last 24 hours. Such systems allow you to store a database consisting of anumber of albums, each of which contains a number of tracks. Your job in this problemis to design the data structure for a new music application called FlyTunes that does muchthe same thing.In FlyTunes, the data structure for each track must include the following information:• The title of the song recorded on that track• The artist who recorded it• The running time in secondsEach album then consists of a number of tracks, along with the title of the album. TheFlyTunes database records information for as many albums as you choose to store in it.In this problem, your mission is to define three classes—FTDataBase, FTAlbum, andFTTrack—that maintain these data structures. Your job therefore consists of thefollowing steps:1. Figure out what information you need to store with each of these structures.2. Determine what information clients need to be able to obtain from the data structure.3. Write the prototypes for a set of methods that retrieve this information.4. Design an external representation that allows you to store FlyTunes data as a text file.5. Code the implementation for each of the three classes.It is important to note that this problem is wildly underspecified and there are many waysto solve it, depending on what data you choose to store and what methods you offer to theclient. The code in the solution is only one


View Full Document

Stanford CS 106A - Study Notes

Download Study Notes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Study Notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Study Notes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?