Repository navigation
Expand file tree
/
Copy pathAlbumCollection.java
More file actions
57 lines (45 loc) · 1.76 KB
/
Copy pathAlbumCollection.java
File metadata and controls
57 lines (45 loc) · 1.76 KB
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
//store details of a colluctoin of almbums
//member variable of Albums
//methods for awnsering general queries
import java.util.ArrayList;
import java.util.List;
public class AlbumCollection {
//An AlbumCollection object is composed of a list of albums and the artist (this is doubled up with Album and thus we could remove one too optimise)
private final String artist;
private final List<Album> albums = new ArrayList<>();
//Constructor
public AlbumCollection(String artist) {
this.artist = artist;
}
//Method too add an Album too the AlbumCollection's 'albums' List
public void addAlbum(Album album) {
albums.add(album);
}
//Acessor methods
public String getArtist() {
return artist;
}
public List<Album> getAlbums() {
return albums;
}
//test harness
public static void main(String[] args) {
Album albumObjectOne = new Album("Kraftwerk", "COMPUTER WORLD", 1981);
Album albumObjectTwo = new Album("Kraftwerk", "DIE MENSCH-MASCHINE", 1978);
//no need to add tracks as no track methords to test
AlbumCollection albumCollectionObject = new AlbumCollection("Kraftwerk"); // artist name is the title of the collection
albumCollectionObject.addAlbum(albumObjectOne);
albumCollectionObject.addAlbum(albumObjectTwo);
System.out.println(
"This is a test harness function for the AlbumCollection class\nExample of getArtist:\n" +
albumCollectionObject.getArtist() +
"\n\nExample of getAlbums:\n" +
albumCollectionObject.getAlbums() +
"\n\nputting them albums to strings:"
);
List<Album> Albums = albumCollectionObject.getAlbums();
for (Album album : Albums) {
System.out.println(album.stringAlbumInfo());
}
}
}