Due: Friday, May 4, 2018 @ 11:59PM
NOTE THE MODIFIED DUE DATE
Extend the last lab (MUTunes) to use Objects
The name of the input file MUST BE SPELLED EXACTLY AS Music.txt
. Any deviations will result in a ZERO as none of my test cases will work. The file starts with an integer on the first line that specifies the song count. Each line afterwards represents a song. The song lines will be formatted thus:
Time:Title:Artist
For example, the file might contain the following data:
5
212:Float On:Modest Mouse
259:Cherub Rock:Smashing Pumpkins
351:The Price You Pay:Bruce Springsteen
417:Teen Age Riot:Sonic Youth
285:Portions for Foxes:Rilo Kiley
Use PRECISELY the file format described above.
The colons delimit the data on each line, which allows us to have spaces in artist and song names. You can use the colons to separate the three fields so you can place each one in the proper array (see the Hints section).
Output the data from the file in three columns, in the order of title, artist, and time. Left justify the title and artist in a field of 24 characters (%-24s
). Right justify the time in a field of 4 characters (%4d
).
Include a total for the times. Then print the longest and shortest songs. Finally, output the song titles in alphabetical order. MATCH the output format below EXACTLY.
For the file above, you would output the following.
TITLE ARTIST TIME
----- ------ ----
Float On Modest Mouse 212
Cherub Rock Smashing Pumpkins 259
The Price You Pay Bruce Springsteen 351
Teen Age Riot Sonic Youth 417
Portions for Foxes Rilo Kiley 285
TOTAL TIME 1524
LONGEST SONG
------------
Teen Age Riot Sonic Youth 417
SHORTEST SONG
-------------
Float On Modest Mouse 212
Song.java
/* Filename: Song.java
* Author: Your name
* Course: CSCI 161 (Section 00)
* Date: Today's date
* Assignment: Lab 11
* Description: A simple Song class used for a Music Library
*/
public class Song {
// TODO: three fields named "title", "artist", and "length"
/**
* Creates a new song from a title, artist, and length
* @param trackTitle the track title
* @param trackArtist the track artist
* @param trackLength the track length (duration in seconds)
*/
public Song(String trackTitle, String trackArtist, int trackLength) {
// TODO: initialize each member
}
/**
* prints a song to System.out using formatted output (printf)
*/
public void print() {
// TODO: use System.out.printf -- remember the trailing newline character!
}
}
MusicLibrary.java
/* Filename: MusicLibrary.java
* Author: Your name
* Course: CSCI 161 (Section 00)
* Date: Today's date
* Assignment: Lab 11
* Description: A simple MusicLibrary class which manages a collection of Songs
*/
import java.util.Scanner;
public class MusicLibrary {
// TODO: there is one field of type Song Array -- name it "songs"
/**
* Constructs a new music library from a file
* @param fileScanner the Scanner to read library information from
*/
public MusicLibrary(Scanner fileScanner) {
// TODO: grab song count from fileScanner and advance to next line
// TODO: create song array
// TODO: process line-by-line and add parsed data to the song array
}
/**
* prints the library as a table
*/
public void print() {
// TODO: print out the header first, then have a for-loop which
// will tell each song to print itself
}
/**
* Accumulates the sum of all of the songs in the library
* @return the total time (in seconds)
*/
public int getTotalTime() {
// TODO: similar to last lab
}
/**
* Finds the longest song in the library
* @return the song with the longest track length
*/
public Song getLongestSong() {
// TODO: similar to last lab, but return the song instead of the index
}
/**
* Finds the shortest song in the library
* @return the song with the shortest track length
*/
public Song getShortestSong() {
// TODO: similar to last lab, but return the song instead of the index
}
}
MUTunes.java
/* Filename: MUTunes.java
* Author: Professor Killian
* Course: CSCI 161
* Date: April 23, 2018
* Assignment: Lab 11
* Description: A sample MUTunes driver program
*/
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class MUTunes {
public static void main(String[] args) throws FileNotFoundException {
Scanner sc = new Scanner(new File("Music.txt"));
MusicLibrary library = new MusicLibrary(sc);
library.print();
System.out.println();
int totalTime = library.getTotalTime();
System.out.printf("%-48s%4d\n\n", "TOTAL TIME", totalTime);
Song longest = library.getLongestSong();
System.out.println("LONGEST SONG");
System.out.println("------------");
longest.print();
System.out.println();
Song shortest = library.getShortestSong();
System.out.println("SHORTEST SONG");
System.out.println("-------------");
shortest.print();
System.out.println();
}
}
Everything you have to implement is marked with TODO
Please test that everything is working with the provided MUTunes.java
file
Please update both Song.java
and MusicLibrary.java
Due to multiple files, I am modifying the submission directions slightly.
File
>
Export...
General
>
Archive File
"Next"
"src"
folder"MusicLibrary.java"
and "Song.java"
on the right side"Create only selected directories"
is selected"Browse..."
and save the ZIP file somewhereAutolab will automatically give a score of ZERO if you do not have the fields for Song
correctly declared.
Autolab will automatically give a score of ZERO if you change method signatures
20 points: having a well-formatted, well-documented source code file. This includes your name, date, description, and comments throughout the program. This also includes other style requirements, such as method naming conventions. NOTE: The autograder will not display these points.
15 points: MusicLibrary
constructor
5 points: MusicLibrary
print (note -- spacing matters for points)
10 points: MusicLibrary
getTotalTime
10 points: MusicLibrary
getLongestSong
10 points: MusicLibrary
getShortestSong
10 points: Song
constructor
10 points: Song
print (note -- spacing matters for points)
10 points: exact output
NOTE: if your program does not compile/run, the highest score you will earn will be a 20/100