-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCD.java
More file actions
82 lines (66 loc) · 1.55 KB
/
CD.java
File metadata and controls
82 lines (66 loc) · 1.55 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
// Andrew Clear, Lab03
/**This class creates the CD objects
*
*/
public class CD extends MediaItem {
private String artist;
private int vocals;
private int music;
private int lyrics;
/**The CD constructor
*
* @param title
* @param price
* @param art
*/
public CD(String title, double price, String art) {
super(title,price);
this.artist = art;
}
/* the toString method, formatted to display nicely in the
* GUI. Shortens the title if it is > 45 characters long
* @see MediaItem#toString()
*/
@Override
public String toString() {
String shortTitle = this.getTitle();
if (this.getTitle().length() > 45) {
shortTitle = shortTitle.substring(0, 42);
shortTitle = shortTitle.concat("...");
}
return String.format("CD [%.2f] $%-7.2f '%-45s' (vocals=%s, lyrics=%s, music=%s)", this.overallRating(),
this.getPrice(), shortTitle, this.vocals, this.lyrics, this.music);
}
/* Calculates the average rating
* (non-Javadoc)
* @see MediaItem#overallRating()
*/
@Override
public double overallRating() {
return (double)(this.vocals + this.music + this.lyrics ) / 3;
}
public String getArtist() {
return artist;
}
public int getVocals() {
return vocals;
}
public int getMusic() {
return music;
}
public int getLyrics() {
return lyrics;
}
public void setArtist(String artist) {
this.artist = artist;
}
public void setVocals(int vocals) {
this.vocals = vocals;
}
public void setMusic(int music) {
this.music = music;
}
public void setLyrics(int lyrics) {
this.lyrics = lyrics;
}
}