AP Computer Science – A project involving multiple
classes
Classes you will
write:
- A Song
Class – maintains the following information about a song:
- Song
title
- Number
of minutes in song length
- Number
of seconds in song length ( must be 0-59)
- A Disc
Class – maintains the following information about a disc
- Title
of disc
- Artist
of disc
- Number
of songs on disc
- An ArrayList of Song objects (songs on the disc)
- A DiscChanger Class –
maintains the following information about a Disc Changer
- An ArrayList with 3 Disc objects
- An ArrayList to store a current playlist of Song objects created from the current Disc objects
Here are methods that must be present in each class:
Song Class
- Default Constructor (sets empty title, 0
for min, sec)
- Initalize Constructor (title, min, sec)
- String getTitle()
// returns title of song
- int getMin() //
returns minutes of song length
- int getSec //
returns seconds of song length
- int getTotalSec()//
returns total seconds of song length
- void setTitle()
// set title of song
- void setMin()
// set minutes of song length
- void setSec //
set seconds of song length
- void toString
// displays the song title, min, sec
(see example below)
The Happy Song 4:09
Disc Class
- Default Constructor (parameter is file
path used to access the text file which loads, title, artist, number of
tracks and list of songs)
- String getTitle()
// returns title of disc
- String getArtist()
// returns artist of disc
- int getNumSongs()
// returns the number of songs on disc
- int getMin() //
returns minutes of disc length
- int getSec() //
returns seconds of disc length
- int getTotalSec()//
returns total seconds of disc length
- Song getSong(int i)// returns song i from disc
- void setTitle()
// set title of disc
- void setArtist()
// set artist of disc
- void setNumSongs
// set number of songs on disc
- void toString
// displays the song title, artist and song list with times and total
length of disc at the end (see example below)
Title: Houses of the Holy
Artist: Led Zeppelin
Songs: 8
1: The Song Remains the Same 6:26
2: The Rain Song 7:14
3: Over the Hills and Far Away 5:47
4: The Crunge 4:13
5: Dancing Days 5:22
6: D'yer Mak'er 5:18
7: No Quarter 6:52
8: The Ocean 5:32
Total Time: 46:44
DiscChanger Class
- Default Constructor (Like the Disc Class, but there are 3 file paths, one for each disc)
- String getTitle(int d)
// returns title of disc d
- String getArtist(int d)
// returns artist of disc d
- int getNumSongs(int d)
// returns the number of songs on disc d
- Disc getDisc(int d)
// returns the entire Disc object for disc d
- int getMin(int d) //
returns minutes of disc length for disc d
- int getSec(int d) //
returns seconds of disc length
for disc d
- int getTotalSec(int d)//
returns total seconds of disc length
for disc d
- Song getSong(int d, int s)// returns song s from disc d
- Song randomSong(int d)
// selects a random song from disc d
- Song randomSong()
// selects a random song from a random disc
- void shuffle(int d)
// shuffles the songs from disc d and displays the results, each song on its own line
- void shuffleAll // shuffles the songs from all 3 discs and displays the results, each song on its own line
- void toString // displays the disc title, artist, # of songs and total
length of disc for each disc (see example below)
Disc 1
Title: Houses of the Holy
Artist: Led Zeppelin
Songs: 8
Total Time: 46:44
Disc 2
Title: The Joshua Tree
Artist: U2
Songs: 11
Total Time: 50:08
Disc 3
Title: Greatest Hits
Artist: Simon and Garfunkel
Songs: 14
Total Time: 44:11