在课后,现在没有接口/校外班:
- Test - for creating test data
- Music - should store all CDs
- CD - should store Artist and CD title + all Songs
- Artist - only contains String name
- Song - contains default-constructor with (Artist anArtist, String songtitle, String Duration)
- Duration - for the song duration and later calculations
i 审判一名ArrayList,但当我加入另一个裁谈会时,它就得过手。 我需要一个数据类型,储存数据,并与另一个阵列连接。 例如:储存CD1的艺术家和所有权,并与包含CD1所有歌曲的其他阵列建立联系。
感谢
班级代码 测试:
Artist aArtist = new Artist("artist1");
CD aCD = myMusic.addCD(aArtist, "CD1");
aCD.addSong(aArtist, "song1", "1:00");
aArtist = new Artist("artist2");
CD aCD = myMusic.addCD(aArtist, "CD2"); //Overwrites arraylist from CD1
aCD.addSong(aArtist, "song2", "2:00");
i 改变我的阿雷拉主义者的班级音乐和班级CD... i) 认为解决这一理论比较容易,但这里是法典:(输出所有保存的歌曲和CD所有权)。
音乐班:
import java.util.ArrayList;
public class Music {
private ArrayList<CD> myCDs = new ArrayList<CD>();
public CD addCD(Artist anArtist, String cdTitle) {
CD aCD = new CD(anArtist, cdTitle);
myCDs.add(aCD);
return aCD;
}
public void showData() {
for (int i = 0; i < myCDs.size(); i++) {
for (int j = 0; j < myCDs.get(i).getMyCD().size(); j++) {
System.out.println(myCDs.get(i).getMyCD().get(j).getSong());
}
}
}
}
CD类:
import java.util.ArrayList;
public class CD {
private String cdTitle;
private ArrayList<Song> myCD = new ArrayList<Song>();
public CD(Artist aArtist, String cdTitle) {
setMyCD(aArtist, cdTitle);
}
public ArrayList<Song> getMyCD() {
return myCD;
}
public String getMyCDtitle() {
return cdTitle;
}
public void setMyCD(Artist anArtist, String cdTitle) {
this.cdTitle = anArtist.getName() + ": " + cdTitle;
}
public void addSong(Artist anArtist, String aTitle, String aDuration) {
myCD.add(new Song(anArtist, aTitle, aDuration));
}
}
中学:
public class Song {
private String song;
public String getSong() {
return song;
}
public void setSong(String song) {
this.song = song;
}
public Song(Artist anArtist, String songtitle, String aDuration) {
Duration songDuration = new Duration(aDuration);
setSong(anArtist.getName() + ": " + songtitle + " ("
+ songDuration.getSongDuration() + ")");
}
}
in general: how would you solve such a project ? i would appreciate every advice or uml diagram.