-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMusic.java
More file actions
90 lines (81 loc) · 2.94 KB
/
Music.java
File metadata and controls
90 lines (81 loc) · 2.94 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/** A music file object that extends the Media class
* Adds on the length, artist, and album of the song
* @author aydin-ali kachra
* @version 1
*/
public class Music extends Media {
//instance variables
private int songLength; //measured in seconds
private String artistName;
private String albumName;
/** Creates a new Music object
* @param fileName - name of the music file
* @param fileType - type of music file
* @param fileSize - size of the music file in MB
* @param songLength - the length of the song in seconds
* @param artistName - the name of the artist who sings the song
* @param albumName - the name of the album the song belongs to
*/
public Music(String fileName, String fileType, double fileSize, int songLength, String artistName, String albumName) {
super(fileName, fileType, fileSize);
this.songLength = songLength;
this.artistName = artistName;
this.albumName = albumName;
}
/** Returns the length of the song
* @return the song length
*/
public int getSongLength() {
return this.songLength;
}
/** Returns the name of the song's artist
* @return the song's artist
*/
public String getArtistName() {
return this.artistName;
}
/** Returns the name of the song's album
* @return the song's album
*/
public String getAlbumName() {
return this.albumName;
}
/** Returns which application launches when you open a music file
* Completes abstract method from Media class
* @return the application that launches when the music file opens
*/
public String openFile() {
return "Launching Spotify...";
}
/** Finds if the Music object is equal another object
* Overrides equals() in Media class
* @param other - object which you are comparing the Music file to
* @return whether the two objects are equal or not
*/
public boolean equals(Object other) {
//checks if the super class is equal, otherwise there's no point on checking the rest
if (super.equals(other)) {
if (other == null) {
return false;
}
if (!(other instanceof Music)) {
return false;
}
Music toCompare = (Music) other;
if (this.songLength == toCompare.songLength &&
this.artistName.equals(toCompare.artistName) &&
this.albumName.equals(toCompare.albumName)) {
return true;
}
return false;
}
return false;
}
/** Creates and returns a string rep of the Music object
* Overrides toString() in Media class
* @return the string rep of the Media object
*/
public String toString() {
return "Media Type: music, " + super.toString() + ", Song Length: " + this.songLength + "s, Artist: " + artistName + ", Album: " + albumName;
}
}