musicrecording.java
来自「《Java核心技术应用开发》电子工业出版社书籍源代码」· Java 代码 · 共 65 行
JAVA
65 行
/**
* 这个类代表音乐CD数据本身
*/
public class MusicRecording extends Recording implements java.io.Serializable {
protected String artist;
protected Track trackList[];
public MusicRecording(String theArtist, Track[] theTrackList,
String theTitle, double thePrice,
String theCategory, String theImageName,
Duration theDuration) {
super(theTitle, thePrice, theCategory, theImageName, theDuration);
artist = theArtist;
trackList = theTrackList;
}
public MusicRecording(String theArtist, Track[] theTrackList,
String theTitle, double thePrice,
String theCategory, String theImageName) {
super(theTitle, thePrice, theCategory, theImageName);
artist = theArtist;
trackList = theTrackList;
}
public String getArtist() {
return artist;
}
public Track[] getTrackList() {
return trackList;
}
public Duration getDuration() {
Track tempTrack;
Duration tempDuration;
int total = 0;
for (int i=0; i < trackList.length; i++) {
tempTrack = trackList[i];
tempDuration = tempTrack.getDuration();
total += tempDuration.getTotalSeconds();
}
return new Duration(total);
}
public String toString() {
return artist + " - " + title;
}
public int compareTo(Object object) {
MusicRecording recording = (MusicRecording) object;
String targetArtist = recording.getArtist();
return artist.compareTo(targetArtist);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?