Created
March 27, 2016 03:35
-
-
Save JZHeadley/e02d5fa7e34e8263e057 to your computer and use it in GitHub Desktop.
hlfsnjakl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Sleepyhead : Passion Pit :Manners : 8 | |
| The Kids Don't Stand a Chance : Vampire Weekend :Vampire Weekend : 3 | |
| For Emma : Bon Iver :For Emma, Forever Ago : 7 | |
| White Winter Hymnal : Fleet Foxes :Fleet Foxes : 12 | |
| You Got Yr. Cherry Bomb : Spoon :Ga Ga Ga Ga Ga (Bonus Track Version) : 10 | |
| 1901 : Phoenix :Wolfgang Amadeus Phoenix : 6 | |
| Sweet Disposition : The Temper Trap :Conditions : 24 | |
| Cheerleader : Grizzly Bear :Veckatimest : 16 | |
| Little Secrets : Passion Pit :Manners : 19 | |
| Ragged Wood : Fleet Foxes :Fleet Foxes : 7 | |
| Grapevine Fires : Death Cab for Cutie :Narrow Stairs : 15 | |
| Chicago : Sufjan Stevens :The Avalanche - Outtakes and Extras from the Illinois Album : 23 | |
| The Sound of Settling : Death Cab for Cutie :Transatlanticism : 12 | |
| Sleeping In : The Postal Service :Give Up : 25 | |
| Take Me to the Riot : Stars :In Our Bedroom After the War : 21 | |
| Mykonos : Fleet Foxes :Mykonos - Single : 24 | |
| Your Heart Is an Empty Room : Death Cab for Cutie :Plans : 7 | |
| Kissing The Lipless : The Shins :Chutes Too Narrow : 19 | |
| The Reeling : Passion Pit :Manners : 24 | |
| M79 : Vampire Weekend :Vampire Weekend : 6 | |
| He Doesn't Know Why : Fleet Foxes :Fleet Foxes : 6 | |
| A Lack Of Color : Death Cab For Cutie :Transatlanticism : 5 | |
| So Here We Are : Bloc Party :Silent Alarm : 20 | |
| First Day of My Life : Bright Eyes :I'm Wide Awake It's Morning : 17 | |
| Daniel : Bat for Lashes :Two Suns : 6 | |
| Naked As We Came : Iron & Wine :Our Endless Numbered Days : 24 | |
| Do You Realize? : The Flaming Lips :Yoshimi Battles The Pink Robots : 5 | |
| Oxford Comma : Vampire Weekend :Vampire Weekend : 5 | |
| Moth's Wings : Passion Pit :Manners : 22 | |
| What Sarah Said : Death Cab for Cutie :Plans : 4 | |
| Blue Ridge Mountains : Fleet Foxes :Fleet Foxes : 15 | |
| Furr : Blitzen Trapper :Furr : 7 | |
| Fire It Up : Modest Mouse :We Were Dead Before The Ship Even Sank : 16 | |
| You Don't Know Me : Ben Folds :Way to Normal : 8 | |
| Transatlanticism : Death Cab for Cutie :Transatlanticism : 8 | |
| Stillness Is the Move : Dirty Projectors :Bitte Orca : 21 | |
| Make Light : Passion Pit :Manners : 15 | |
| Tiger Mountain Peasant Song : Fleet Foxes :Fleet Foxes : 17 | |
| Such Great Heights : Iron & Wine :Garden State : 5 | |
| 42 : Coldplay :Viva la Vida : 4 | |
| Pink Bullets : The Shins :Chutes Too Narrow : 6 | |
| Sometime Around Midnight : The Airborne Toxic Event :The Airborne Toxic Event : 23 | |
| Yoshimi Battles The Pink Robots Pt.1: The Flaming Lips :Yoshimi Battles The Pink Robots : 7 | |
| To Kingdom Come : Passion Pit :Manners : 13 | |
| Tiny Vessels : Death Cab for Cutie :Transatlanticism : 18 | |
| Sun It Rises : Fleet Foxes :Fleet Foxes : 11 | |
| Chemtrails : Beck :Modern Guilt : 14 | |
| A Movie Script Ending : Death Cab For Cutie :The Photo Album : 22 | |
| Up Against the Wall : Peter Bjorn and John :Writer's Block : 13 | |
| So Far Around the Bend : The National :Dark Was the Night : 13 | |
| Saint Simon : The Shins :Chutes Too Narrow : 20 | |
| Nothing Ever Happened : Deerhunter :Microcastle : 15 | |
| Eyes As Candles : Passion Pit :Manners : 19 | |
| Quiet Houses : Fleet Foxes :Fleet Foxes : 14 | |
| Passenger Seat : Death Cab for Cutie :Transatlanticism : 7 | |
| You and I : Wilco :Wilco (The Album) : 6 | |
| Girl Sailor : The Shins :Wincing The Night Away : 4 | |
| 16 Military Wives : The Decemberists :Picaresque : 10 | |
| Crack the Shutters : Snow Patrol :A Hundred Million Suns : 5 | |
| Against All Odds : The Postal Service :Against All Odds - Single : 13 | |
| Let Your Love Grow Tall : Passion Pit :Manners : 7 | |
| Your Protector : Fleet Foxes :Fleet Foxes : 9 | |
| Mine's Not A High Horse : The Shins :Chutes Too Narrow : 9 | |
| Open Your Eyes : Snow Patrol :Eyes Open : 11 | |
| You Never Know : Wilco :Wilco (The Album) : 8 | |
| Swimming In The Flood : Passion Pit :Manners : 1 | |
| Love Always Remains : MGMT :Time to Pretend : 22 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.Objects; | |
| /** | |
| * <p>An object representing a song. Contains the song's title, artist, album, and play count.</p> | |
| * <p>Date: 3/26/2016</p> | |
| * <p>Course: CMSC256-001</p> | |
| * | |
| * @author Jonathon Z. Headley | |
| * @version 1.0.0 | |
| */ | |
| public class Song implements Comparable { | |
| private String songTitle; | |
| private String artistName; | |
| private String albumName; | |
| private int playCount; | |
| public Song(String songTitle, String artistName, String albumName, int playCount) { | |
| this.songTitle = songTitle; | |
| this.artistName = artistName; | |
| this.albumName = albumName; | |
| this.playCount = playCount; | |
| } | |
| public Song(String songTitle, String artistName, String albumName) { | |
| this.songTitle = songTitle; | |
| this.artistName = artistName; | |
| this.albumName = albumName; | |
| } | |
| /** | |
| * Default constructor | |
| */ | |
| public Song() { | |
| this.songTitle = ""; | |
| this.artistName = ""; | |
| this.albumName = ""; | |
| this.playCount = 0; | |
| } | |
| /** | |
| * @return title of the song | |
| */ | |
| public String getSongTitle() { | |
| return songTitle; | |
| } | |
| /** | |
| * Sets the title of the song | |
| * | |
| * @param songTitle new title of the song. | |
| */ | |
| public void setSongTitle(String songTitle) { | |
| this.songTitle = songTitle; | |
| } | |
| /** | |
| * @return name of the artist of the song | |
| */ | |
| public String getArtistName() { | |
| return artistName; | |
| } | |
| /** | |
| * Sets the artist name to the given value | |
| * | |
| * @param artistName new artist name | |
| */ | |
| public void setArtistName(String artistName) { | |
| this.artistName = artistName; | |
| } | |
| /** | |
| * @return album name for the song | |
| */ | |
| public String getAlbumName() { | |
| return albumName; | |
| } | |
| /** | |
| * Sets the albumName of the song | |
| * | |
| * @param albumName new album name for the song | |
| */ | |
| public void setAlbumName(String albumName) { | |
| this.albumName = albumName; | |
| } | |
| /** | |
| * @return play count of the song. | |
| */ | |
| public int getPlayCount() { | |
| return playCount; | |
| } | |
| /** | |
| * Sets the playcount of the song | |
| * | |
| * @param playCount new playcount of the song | |
| */ | |
| public void setPlayCount(int playCount) { | |
| this.playCount = playCount; | |
| } | |
| @Override | |
| public boolean equals(Object o) { | |
| if (this == o) return true; | |
| if (o == null || getClass() != o.getClass()) return false; | |
| Song song = (Song) o; | |
| return Objects.equals(songTitle, song.songTitle) && | |
| Objects.equals(artistName, song.artistName) && | |
| Objects.equals(albumName, song.albumName); | |
| } | |
| /** | |
| * @return a to string representation of the object. | |
| */ | |
| @Override | |
| public String toString() { | |
| return "Title: " + songTitle + "\n" + | |
| "Artist: " + artistName + "\n" + | |
| "Album: " + albumName + "\n" + | |
| "Play Count: " + playCount; | |
| } | |
| /** | |
| * @param object Object to compare to | |
| * @return Returns positive if entered object is greater than this object. | |
| * Returns 0 if objects are equal. | |
| * Returns negative if entered object is less than this object. | |
| */ | |
| @Override | |
| public int compareTo(Object object) { | |
| int comparePlayCount = ((Song) object).getPlayCount(); | |
| if (this.equals(object)) { | |
| return 0; | |
| } | |
| return comparePlayCount - this.getPlayCount(); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.io.File; | |
| import java.io.FileNotFoundException; | |
| import java.util.ArrayList; | |
| import java.util.Collections; | |
| import java.util.Scanner; | |
| /** | |
| * <p>Displays a menu to perform operations on a playlist of songs.</p> | |
| * <p>Provides operations to search by Artist, Find a song, and display Favorites</p> | |
| * <p>Date: 3/26/2016</p> | |
| * <p>Course: CMSC256-001</p> | |
| * | |
| * @author Jonathon Z. Headley | |
| * @version 1.0.0 | |
| */ | |
| public class SongList { | |
| public static void main(String[] args) { | |
| printHeading(); | |
| Scanner scanner = new Scanner(System.in); | |
| boolean end = false; | |
| boolean commandArgsPresent = true; | |
| String filePath = ""; | |
| File songListFile = null; | |
| ArrayList<Song> songList = new ArrayList<>(); | |
| // Checking for command line args | |
| if (args.length == 0) { | |
| commandArgsPresent = false; | |
| } else { | |
| // Sanitizing Path | |
| filePath = args[0].replaceAll("\\\\", "\\\\\\\\"); | |
| songListFile = new File(filePath); | |
| } | |
| do { | |
| while (!commandArgsPresent || !(filePath.length() > 0)) { | |
| System.out.println("Please enter the path to the playlist file:\t"); | |
| // Sanitizing Path | |
| filePath = scanner.nextLine().replaceAll("\\\\", "\\\\\\\\"); | |
| songListFile = new File(filePath); | |
| commandArgsPresent = true; | |
| if (!(songListFile.isFile())) { | |
| filePath = ""; | |
| System.out.println("Invalid Path please enter a valid path."); | |
| } | |
| } | |
| try { | |
| songList = readSongs(songListFile); | |
| } catch (FileNotFoundException e) { | |
| e.printStackTrace(); | |
| } | |
| System.out.println(); | |
| displayMenu(); | |
| switch (scanner.nextLine()) { | |
| case "1": // Search by artist | |
| ArrayList<Song> songsByArtist = new ArrayList<Song>(); | |
| boolean flag = true; | |
| while (flag) { | |
| System.out.println("Enter the artist to search by:\t"); | |
| String artistName = scanner.nextLine(); | |
| if (artistName.length() > 0) { | |
| songsByArtist = getSongsByArtist(artistName, songList); | |
| if (!(songsByArtist.size() > 0)) { | |
| System.out.println("There is no artist by that name"); | |
| } else { | |
| flag = false; | |
| } | |
| } | |
| songsByArtist.forEach(songByArtist -> System.out.println(songByArtist.toString())); | |
| } | |
| break; | |
| case "2": // Find a song | |
| Song song; | |
| flag = true; | |
| while (flag) { | |
| System.out.println("Enter the song to search by:"); | |
| String line = scanner.nextLine(); | |
| if (line.length() > 0) { | |
| song = getSongByName(line, songList); | |
| if (song != null) { | |
| song.setPlayCount(song.getPlayCount() + 1); | |
| System.out.println(song.toString()); | |
| flag = false; | |
| } else { | |
| System.out.println("No song has that name!"); | |
| } | |
| } | |
| } | |
| break; | |
| case "3": // Display top 10 by play count | |
| System.out.println("Top 10 Favorites"); | |
| System.out.println("----------------"); | |
| displayFavorites(songList); | |
| break; | |
| case "4": // Quit; | |
| end = true; | |
| break; | |
| default: | |
| System.out.println("Invalid input"); | |
| break; | |
| } | |
| } while (!end); | |
| } | |
| /** | |
| * Gets the songs from the songList passed in that are made by the artist passed in | |
| * | |
| * @param artistSearchString Name of the artist to search for | |
| * @param songList List of songs to search | |
| * @return A list of all songs by the given artist sorted by album and title. | |
| */ | |
| private static ArrayList<Song> getSongsByArtist(String artistSearchString, ArrayList<Song> songList) { | |
| ArrayList<Song> artistsSongs = new ArrayList<Song>(); | |
| for (Song song : songList) { | |
| if (song.getArtistName().equalsIgnoreCase(artistSearchString)) { | |
| artistsSongs.add(song); | |
| } | |
| } | |
| Collections.sort(artistsSongs, (song1, song2) -> { | |
| String song1AlbumName = song1.getAlbumName(); | |
| String song2AlbumName = song2.getAlbumName(); | |
| int comparison = song1AlbumName.compareTo(song2AlbumName); | |
| if (comparison != 0) { | |
| return comparison; | |
| } else { | |
| String song1SongTitle = song1.getSongTitle(); | |
| String song2SongTitle = song2.getSongTitle(); | |
| return song1SongTitle.compareTo(song2SongTitle); | |
| } | |
| }); | |
| return artistsSongs; | |
| } | |
| /** | |
| * Displays the menu of operations to perform on the list. | |
| */ | |
| private static void displayMenu() { | |
| System.out.println("Please Select an option"); | |
| System.out.println("1:\tSearch by Artist"); | |
| System.out.println("2:\tFind Song"); | |
| System.out.println("3:\tDisplay Favorites"); | |
| System.out.println("4:\tQuit"); | |
| } | |
| private static ArrayList<Song> readSongs(File file) throws FileNotFoundException { | |
| ArrayList<Song> songs = new ArrayList<>(); | |
| Scanner fileScanner = new Scanner(file); | |
| while (fileScanner.hasNextLine()) { | |
| String line = fileScanner.nextLine(); | |
| String[] lineParts = line.split(":"); | |
| for (int i = 0; i < lineParts.length; i++) { | |
| lineParts[i] = lineParts[i].trim(); | |
| } | |
| // check length of line parts to see if it has a play count. | |
| if (lineParts.length == 4) { | |
| songs.add(new Song(lineParts[0], lineParts[1], lineParts[2], Integer.parseInt(lineParts[3]))); | |
| } else if (lineParts.length == 3) { | |
| songs.add(new Song(lineParts[0], lineParts[1], lineParts[2])); | |
| } | |
| } | |
| return songs; | |
| } | |
| private static void printHeading() { | |
| System.out.println("Name: Jonathon Z. Headley"); | |
| System.out.println("Project Number: 4"); | |
| System.out.println("Course Identifier: CMSC 256-001"); | |
| System.out.println("Semester: Spring 2016"); | |
| System.out.println(); | |
| } | |
| /** | |
| * Displays top ten songs by play count | |
| * | |
| * @param songs array of songs to base the favorites off of. | |
| */ | |
| private static void displayFavorites(ArrayList<Song> songs) { | |
| Collections.sort(songs); | |
| for (int i = 0; i < 10; i++) { | |
| System.out.println((i + 1) + ")\t" + songs.get(i).toString()); | |
| } | |
| } | |
| /** | |
| * Gets a song with the given name | |
| * | |
| * @param songSearchName Name of the song to find | |
| * @param songs list of the songs to search in | |
| * @return song with the given name | |
| */ | |
| private static Song getSongByName(String songSearchName, ArrayList<Song> songs) { | |
| Song songFound = null; | |
| for (Song song : songs) { | |
| if (song.getSongTitle().equalsIgnoreCase(songSearchName)) { | |
| songFound = song; | |
| return songFound; | |
| } | |
| } | |
| return null; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment