-
Notifications
You must be signed in to change notification settings - Fork 0
/
Album.java
69 lines (58 loc) · 1.83 KB
/
Album.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import java.util.ArrayList;
public class Album {
private static ArrayList<Album> albums = new ArrayList<Album>();
private String name;
private Date date;
private ArrayList<Artist> artists;
private ArrayList<Song> songs;
public Album(String n, ArrayList<Artist> a, Date d){
name = n;
date = d;
artists = a;
songs = new ArrayList<Song>();
albums.add(this);
for (int i=0; i<a.size(); i++) a.get(i).addAlbum(this);
}
public static Album getAlbum(String n){
for (int i=0; i<albums.size(); i++){
if (albums.get(i).name.toLowerCase().equals(n.toLowerCase())) return albums.get(i);
}
return null;
}
public static ArrayList<Album> getAllAlbums(){
return albums;
}
public void addSong(Song song){
songs.add(song);
}
public ArrayList<Song> getSongs(){
return songs;
}
public String getName(){
return name;
}
public Date getDate(){
return date;
}
public ArrayList<Artist> getArtists(){
return artists;
}
public static ArrayList<Album> sortAlbumsAlphabetically(ArrayList<Album> albums){
int albumCount = albums.size();
for (int i=0; i<albumCount-1; i++){
int maxIndex = i;
for (int j=i+1; j < albumCount; j++){
String maxString = albums.get(maxIndex).getName().toLowerCase();
String indexString = albums.get(j).getName().toLowerCase();
if(indexString.compareTo(maxString)<0) maxIndex = j;
}
Album temp = albums.get(maxIndex);
albums.set(maxIndex, albums.get(i));
albums.set(i, temp);
}
return albums;
}
public String toString(){
return name;
}
}