我正在为一个 220 类编写代码,它将由一个类处理的歌曲添加到另一个名为 MixCD 的类中,该类具有一组歌曲。我的问题是,在定义第二首或第三首歌曲时,它会与数组中的先前歌曲混淆还是它们是专有的?
添加歌曲的代码是这样的
System.out.println("What is the Song Title?");
songA.setTitle(sc.next());
System.out.println("What is the Song's Artist?");
songA.setArtist(sc.next());
System.out.println("How long is the Song? (In Seconds)");
songA.setRunTime(sc.nextInt());
if(((songA.getRunTime() / 60) < songCD.calcRemainingTime())){
if (songCD.addToCD(songA) == true){
System.out.println("Song successfully added");
lastSongAdded = songA;
} //if
else {
System.out.println("Song was unable to be added");
} //else
} //if
else {
System.out.println("Song was unable to be added");
}
break;
And the Add to CD code is this:
for(int i = 0; i < mySongs.length; i++) {
if( mySongs[i] != null ) {
mySize++;
}
}
if (mySize < (mySongs.length-1)){
mySongs[mySize] = newSong;
return true;
} //if
else {
return false;
} //else
} //addToCD
因此,当将新歌曲添加到 CD 时,它会更改 songA,但它会更改 songCD[0] 中的歌曲等等吗?