有人可以告訴我這是怎麼回事?這就是webcat所說的!WebCAT爲(弗吉尼亞理工大學)提交將不會允許我提交此
[PL10]在PlayList.removeSong(1)用3首歌曲: 播放列表removeSong [PL11]在PlayList.removeSong後具有錯誤的內容(2)與三首歌曲:播放列表removeSong [PL12後具有錯誤的內容] PlayList.removeSong(int)中有3首歌曲:播放列表在播放列表中應該保持不變,並且索引不良 [PL13] PlayList在播放歌曲後發生錯誤的內容(歌曲)> 1次 [PL14]異常調用播放列表.removeSong(Song)with 3首歌曲列表
import java.io.File;
import java.util.ArrayList;
import java.util.Scanner;
public class PlayList {
private String name;
private ArrayList<Song> songList;
public String getName() {
return this.name;
}
public String setName(String name) {
return this.name = name;
}
public ArrayList getsongList() {
return this.songList;
}
public ArrayList setsongList(ArrayList songList) {
return this.songList = songList;
}
@Override
public String toString() {
return "PlayList [name= " + name + ", Songlist = " + songList + "]";
}
public PlayList() {
this.name = "Untitled";
}
public PlayList(String newName) {
this.name = newName;
songList = new ArrayList<Song>(); // add for both constructors
}
/**
* Longest method. Takes input from file, converts it to string and displays
* song or 'loads' it
**/
public boolean loadSongs(String filename) {
try {
File text = new File(filename);
Scanner scan = new Scanner(text);
while (scan.hasNextLine()) {
String art = "anything";
String sng = "somethingelse";
for (int i = 0; i <= 4; i++) {
if (i == 0) {
art = scan.nextLine().trim();
if (art.length() == 0) {
continue;
}
}
if (i == 1) {
sng = scan.nextLine();
}
if (i == 2) {
String[] duration = scan.nextLine().split(";");
int m = Integer.parseInt(duration[0]); // like 1:
int s = Integer.parseInt(duration[1]); // like 135
int sec = 0;
int min = 0;
int rem = 0;
if (s >= 60) { // if s = 135
sec = s/60; // sec = 2.25, or 2
rem = s % 60; // rem = 15
s = rem; // s is now 15
min = m * sec + m; // 1*2 + 1 = 3
}
Song anysong = new Song(art, sng, min, s);
songList.add(anysong);
}
}
}
return true;
} catch (Exception e) {
return false;
}
}
public boolean clear() {
if (!songList.isEmpty()) {
songList.clear();
return true;
}
return false;
}
public boolean addSong(Song s) {
if (songList.add(s)) {
return true;
}
return false;
}
public Song removeSong(int index) {
index = 0;
int i = 0;
// check to see if the index is in the boundaries of the songList
if (index >= 0 && index < songList.size()) {
for (i = 0; i < songList.size(); i++) {
return songList.remove(i);
}
return songList.remove(i);
}
else {
return null;
}
// else return null
// if (index >= 0 && index < songList.size()
}
public Song removeSong(Song s) {
boolean found = false;
for (int j = 0; j > songList.size(); j++) {
songList.remove(s);
if (songList.remove(j).equals(songList.remove(j + 1))) {
found = true;
return s;
} else {
return null;
}
// compare all of these .equals()
// what your doing right now is deleting all the songs
// if you find that two are true, set ffound = true
// then return s if found is true, return null if found is false
}
return s;
}
// getSong method
public Song getSong(int index) {
int i = 0;
if (index >= 0 && index <= songList.size()) {
for (i = 0; i < songList.size(); i++) {
return songList.get(i);
}
}
return songList.get(i);
}
// it is similar to the removeSong(int Index)
// you need the same if statement
public void play(Song s) {
for (int z = 0; z > songList.size(); z++) {
System.out.println(songList);
}
}
public int size() {
return songList.size();
}
}
太謝謝你了!這個問題沒有了,但現在還有其他一些問題:/ – 2014-09-18 23:46:02
那麼,你可以對這個問題作出任何正確的回答,然後用你的新問題開一個新的問題。 – csmckelvey 2014-09-18 23:47:22
@roippi不,這是一個(不一定非常可讀)的方式來分配,並在同一時間返回右側。 – hexafraction 2014-09-18 23:53:01