为什么这不起作用?这是我的程序“getTutorNames”方法。完整的问题在链接中。这只是该计划的一部分。有人可以帮忙吗?我已经被困了好几个小时了。例如,我的错误消息之一:PeerTutoringReport.java:30: error: variable nameList is already defined in method getTutorNames() Return nameList; ^
user2243127
问问题
79 次
1 回答
1
就像我在评论部分所说的那样,该方法存在多个问题
import javax.swing.JOptionPane;
import java.util.ArrayList;
public class PeerTutoringReport {
public static void main(String[] args) {
ArrayList<String> tutorNames = getTutorNames();
// sortTutorNames();
// getTutorDegree();
// getAmountOfStudentsForTutors();
// calculateStipend();
// displayResults();
}
private static boolean isNullorEmpty(String s) {
return s == null || s.matches("\\s*");
}
public static ArrayList<String> getTutorNames() {
ArrayList<String> nameList = new ArrayList<String>();
while (nameList.size() < 9) {
String firstName = JOptionPane
.showInputDialog("Enter Tutor First Name: ");
String lastName = JOptionPane
.showInputDialog("Enter Tutor Last Name: ");
if (isNullorEmpty(firstName) && isNullorEmpty(lastName)) {
continue;
}
nameList.add(lastName + "," + firstName);
}
return nameList;
}
}
于 2013-04-04T04:01:41.907 回答