为什么这不起作用?这是我的“getTutorNames”方法的程序。完整的问题在链接中。这只是该计划的一部分。有人可以帮忙吗?我被困了几个小时。这里有一个例子我的错误信息之一:PeerTutoringReport.java:30:错误:变量nameList已在方法getTutorNames()中定义 返回nameList; ^
答案 0 :(得分: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;
}
}