Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I'm completely stumped and struggling with the entirety of this project. The language is Java. Much appreciated for any help! Description: In our earlier programs,

I'm completely stumped and struggling with the entirety of this project. The language is Java. Much appreciated for any help!

image text in transcribed

image text in transcribedimage text in transcribed

image text in transcribed

Description: In our earlier programs, the states of the objects we constructed at runtime were lost when the program stopped. For many applications, this is an unacceptable limitation. A word processor, for instance, wouldn't be very useful if we lost our documents when we turned off our computer. For our third lab, we will write a pair of classes that do not have this limitation: Song and Playlist. Playlist objects store a list of Song objects that can be modified in various ways. Most importantly, the state of a Playlist can be saved and loaded from a text file, so we can keep track of our music collection even after our program stops! Class Diagram: 10..1 0..* Song -title: String -artist: String -minutes: int -seconds: int -numPlays: int - IDX TITLE = 0: int -IDX ARTIST = 1: int -IDX LENGTH = 2: int - IDX NUM PLAYS = 3: int +Song(info: String) +Song (other: Song) +getTitle(): String +getArtist(): String +getMinutes(): int +getSeconds(): int +getLength(): String +getNumPlays(): int +incrementPlays(): void +toString(): String Playlist -songs: ArrayList +Playlist() +Playlist(filename: String) - load(filename: String): void +save(filename: String): void +addSong( song: Song): void +addSong(index: int, song: Song): void +addSongs (filename: String): void +getSong(index: int): Song +numSongs(): int +playSong(index: int): void +remove Song(index: int): Song +toString(): String +favoriteArtist(): String +totalPlaytime(): String Song Class: Each Song has a title, artist, length, and play count. The length is stored in two fields: minutes and seconds. Songs can be constructed from either an info String or another Song object. Info Strings have the following format: ",<artist>,<minutes>:<seconds the numbers on aggregation line indicate that each song belongs to either or playlist. likewise indicates playlist has more songs. values are separated by commas with no spaces. index of value is stored in a static variable. for instance idx_artist stores>", which is the value of the artist field. Optionally, an info String may have a fourth value that specifies the number of times a song has been played: "<title>, <artist>,<minutes>:<seconds>, <numplays>" If this value is absent, initialize numPlays to 0. To illustrate this format, consider the following info String: "Ten Years Gone, Led Zeppelin, 6:31" A Song constructed from this String stores "Ten Years Gone" in the title field, "Led Zeppelin in the artist field, 6 in the minutes field, and 31 in the seconds field. The info String does not have a fourth value, so the object stores 0 in the numPlays field. Below are descriptions of some methods of the Song class: Song(Song other): This is known as a "copy constructor." It creates a new song that is a copy of an existing Song. That is, it initializes the fields of the new Song to the values stored in the given Song. The utility of this method will become clear when writing the Playlist class. .getLength(): Return the song length in the format of an info String: "<minutes>: <seconds if the number of seconds is less than pad value with a leading zero so it has two digits. easiest way to do this format method string class. use which indicates that should be decimal integer at least incrementplays increase numplays by note mutator implies songs are mutable. .tostring return an info values fields. not include in output. getlength avoid duplicating code. playlist class: each stores reference arraylist songs. we want protect these they can only modified methods order accomplish any song must copied before added or returned from playlist. otherwise calling will have mutable private data.2 below descriptions construct empty filename file strings. contain for every line and match file. load read strings given name. create add end intended helper addsongs save output tostring contents already exists. .addsong copy index index. public version .getsong numsongs playsong increment plays remove necessary copy. fields on joining newline characters. terminate character. example contains constructed strings: what miles davis fifth genesis then string: firth favorite artist appears most frequently null. totalplaytime total length all following format:>:<minutes>:<seconds the number of minutes and seconds should each be a between if hours is use this format instead:>:<seconds pad the number of seconds with a leading zero if it is less than hours greater minutes as well. ne used scanner and printwriter classes to read write tiles. you are welcome use those here but bufferedreader buffered writer lightweight alternatives.3 objects these can be constructed following statements: br="new" filereader bufferedwriter bw="new" filewriter call readline on reader next line file. method returns null after reads last line. str given string done reading or writing close method. any that uses must able throw an input-output exception. import java.io.ioexception add ioexception parameter list. collaboration: collaborate other students online resources for help cite names your collaborators urls sources in comments code. description: our earlier programs states we at runtime were lost when program stopped. many applications this unacceptable limitation. word processor instance wouldn very useful documents turned off computer. third lab will pair do not have limitation: song playlist. playlist store list modified various ways. most importantly state saved loaded from text file so keep track music collection even stops diagram: int idx title="0:" artist="1:" length="2:" num plays="3:" void arrayliststyle=""> +Playlist() +Playlist(filename: String) - load(filename: String): void +save(filename: String): void +addSong( song: Song): void +addSong(index: int, song: Song): void +addSongs (filename: String): void +getSong(index: int): Song +numSongs(): int +playSong(index: int): void +remove Song(index: int): Song +toString(): String +favoriteArtist(): String +totalPlaytime(): String Song Class: Each Song has a title, artist, length, and play count. The length is stored in two fields: minutes and seconds. Songs can be constructed from either an info String or another Song object. Info Strings have the following format: "<title>,<artist>,<minutes>:<seconds the numbers on aggregation line indicate that each song belongs to either or playlist. likewise indicates playlist has more songs. values are separated by commas with no spaces. index of value is stored in a static variable. for instance idx_artist stores>", which is the value of the artist field. Optionally, an info String may have a fourth value that specifies the number of times a song has been played: "<title>, <artist>,<minutes>:<seconds>, <numplays>" If this value is absent, initialize numPlays to 0. To illustrate this format, consider the following info String: "Ten Years Gone, Led Zeppelin, 6:31" A Song constructed from this String stores "Ten Years Gone" in the title field, "Led Zeppelin in the artist field, 6 in the minutes field, and 31 in the seconds field. The info String does not have a fourth value, so the object stores 0 in the numPlays field. Below are descriptions of some methods of the Song class: Song(Song other): This is known as a "copy constructor." It creates a new song that is a copy of an existing Song. That is, it initializes the fields of the new Song to the values stored in the given Song. The utility of this method will become clear when writing the Playlist class. .getLength(): Return the song length in the format of an info String: "<minutes>: <seconds if the number of seconds is less than pad value with a leading zero so it has two digits. easiest way to do this format method string class. use which indicates that should be decimal integer at least incrementplays increase numplays by note mutator implies songs are mutable. .tostring return an info values fields. not include in output. getlength avoid duplicating code. playlist class: each stores reference arraylist songs. we want protect these they can only modified methods order accomplish any song must copied before added or returned from playlist. otherwise calling will have mutable private data.2 below descriptions construct empty filename file strings. contain for every line and match file. load read strings given name. create add end intended helper addsongs save output tostring contents already exists. .addsong copy index index. public version .getsong numsongs playsong increment plays remove necessary copy. fields on joining newline characters. terminate character. example contains constructed strings: what miles davis fifth genesis then string: firth favorite artist appears most frequently null. totalplaytime total length all following format:>:<minutes>:<seconds the number of minutes and seconds should each be a between if hours is use this format instead:>:<seconds pad the number of seconds with a leading zero if it is less than hours greater minutes as well. ne used scanner and printwriter classes to read write tiles. you are welcome use those here but bufferedreader buffered writer lightweight alternatives.3 objects these can be constructed following statements: br="new" filereader bufferedwriter bw="new" filewriter call readline on reader next line file. method returns null after reads last line. str given string done reading or writing close method. any that uses must able throw an input-output exception. import java.io.ioexception add ioexception parameter list. collaboration: collaborate other students online resources for help cite names your collaborators urls sources in comments code></seconds></seconds></minutes></seconds></minutes><umplays></seconds></minutes></artist>

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 2012 Proceedings Part 2 Lnai 7197

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284892, 978-3642284892

More Books

Students also viewed these Databases questions

Question

a sin(2x) x Let f(x)=2x+1 In(be)

Answered: 1 week ago