Last active
June 4, 2019 09:15
-
-
Save 76342ck/18c46d4eca9de63d953a to your computer and use it in GitHub Desktop.
Week6 Collection
This file contains 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
----jGRASP exec: java SongDriver | |
NumSongs = 7 / PlayList song limit = 12 | |
songList[0] = < Title: If You, Artist: Big Bang, Album: MADE, Track Length: 264000> | |
songList[1] = < Title: If You, Artist: Big Bang, Album: MADE, Track Length: 264000> | |
songList[2] = < Title: If You, Artist: Big Bang, Album: MADE, Track Length: 264000> | |
songList[3] = < Title: If You, Artist: Big Bang, Album: MADE, Track Length: 264000> | |
songList[4] = < Title: If You, Artist: Big Bang, Album: MADE, Track Length: 264000> | |
songList[5] = < Title: If You, Artist: Big Bang, Album: MADE, Track Length: 264000> | |
songList[6] = < Title: If You, Artist: Big Bang, Album: MADE, Track Length: 264000> | |
NumSongs = 7 / PlayList song limit = 12 | |
songList[0] = < Title: If You, Artist: Big Bang, Album: MADE, Track Length: 264000> | |
songList[1] = < Title: If You, Artist: Big Bang, Album: MADE, Track Length: 264000> | |
songList[2] = < Title: If You, Artist: Big Bang, Album: MADE, Track Length: 264000> | |
songList[3] = < Title: If You, Artist: Big Bang, Album: MADE, Track Length: 264000> | |
songList[4] = < Title: If You, Artist: Big Bang, Album: MADE, Track Length: 264000> | |
songList[5] = < Title: If You, Artist: Big Bang, Album: MADE, Track Length: 264000> | |
songList[6] = < Title: If You, Artist: Big Bang, Album: MADE, Track Length: 264000> | |
----jGRASP: operation complete. |
This file contains 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
public class Playlist { | |
private static Song[] songs; | |
private static int count; | |
private String playlistName; | |
public Playlist() { | |
songs = new Song[12]; | |
count = 0; | |
} | |
public String getPlaylistName() { | |
return playlistName; | |
} | |
public void setPlayListName() { | |
this.playlistName = playlistName; | |
} | |
public void add(Song a) { | |
if(count == songs.length) { | |
System.out.println("ERROR: Collection is full. Songs were not added to the Playlist."); | |
} | |
songs[count] = a; | |
count++; | |
} | |
public Song get(int i) { | |
if(count > i) { | |
return songs[i]; | |
} | |
else { | |
return null; | |
} | |
} | |
public Song remove(String name) { | |
boolean found = false; | |
int indexToRemove = 0; | |
while(indexToRemove < count && !found) { | |
if(songs[indexToRemove].getName().equals(name)) { | |
found = true; | |
} | |
else { | |
indexToRemove++; | |
} | |
} | |
if(indexToRemove < count) { | |
for(int from = indexToRemove + 1; from < count; from++) { | |
songs[from-1] = songs[from]; | |
} | |
songs[count-1] = null; | |
count--; | |
} | |
return null; | |
} | |
public static void print() { | |
String result = "NumSongs = " + count | |
+ " / PlayList song limit = " + songs.length + "\n"; | |
for (int i=0; i<count; i++) { | |
result += ("songList[" + i + "] = <" | |
+ songs[i] + ">\n"); | |
} | |
System.out.println(result.toString() + "\n"); | |
} | |
public int size() { | |
return count; | |
} | |
public int totalTime() { | |
int totalTime = 0; | |
for (int i=0; i<count; i++) { | |
totalTime = songs[i].getLength(); | |
} | |
return totalTime; | |
} | |
public String formattedTotalTime() { | |
long h, m, s; | |
String lengthString; | |
s = Song.length; | |
m = s/60; | |
s = s%60; | |
h = m/60; | |
m = m%60; | |
lengthString = String.format("%02d",h) + ":" + | |
String.format("%02d",m) + ":" + | |
String.format("%02d",s); | |
return lengthString; | |
} | |
public static void clear() { | |
for (int i=0; i<songs.length; i++) { | |
songs[i] = null; | |
count = 0; | |
} | |
return ; | |
} | |
} |
This file contains 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
public class Song { | |
private static String name; | |
private static String artist; | |
private static String album; | |
private static int length; | |
public Song(String songName, String artistName, String albumName, int trackLength) { | |
setArtist(artistName); | |
setName(songName); | |
setAlbum(albumName); | |
setLength(trackLength); | |
} | |
public void setName(String songName) { | |
name = songName; | |
} | |
public static String getName() { | |
return name; | |
} | |
public void setArtist(String artistName) { | |
artist = artistName; | |
} | |
public static String getArtist() { | |
return artist; | |
} | |
public void setAlbum(String albumName) { | |
album = albumName; | |
} | |
public static String getAlbum() { | |
return album; | |
} | |
public void setLength(int trackLength) { | |
length = trackLength; | |
} | |
public static int getLength() { | |
return length; | |
} | |
} | |
This file contains 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
public class SongDriver { | |
public static void main(String[] args) { | |
Playlist one = new Playlist(); | |
Song song1 = new Song("Hotline Bling", "Drake", "Hotline Bing - Single", 267000); | |
Song song2 = new Song("What Do You Mean?", "Justin Bieber", "What Do You Mean? - Single", 207000); | |
Song song3 = new Song("Watch Me", "Silento", "Watch Me (Whip / Nae Nae) - Single", 185000); | |
Song song4 = new Song("679", "Fetty Wap ft. Remy Boyz", "Fetty Wap", 185000); | |
Song song5 = new Song("Can't Feel My Face", "The Weeknd", "Beauty Behind the Madness", 213000); | |
Song song6 = new Song("Good for You", "Selena Gomez ft. A$AP Rocky", "Good for You - Single", 221000); | |
Song song7 = new Song("If You", "Big Bang", "MADE", 264000); | |
one.add(song1); | |
one.add(song2); | |
one.add(song3); | |
one.add(song4); | |
one.add(song5); | |
one.add(song6); | |
one.add(song7); | |
Playlist.print(); | |
one.remove(new String ("679")); | |
one.remove("Watch Me"); | |
Playlist.print(); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment