さて、私の質問はブール値のリターンに関するものです。私のCompSciの宿題では、メソッドを使用してコース登録プログラムを作成する必要があります。そのうちの1つは、コースの追加メソッドです。基本的に、カタログでクラスを検索し、一致する場合はそれを生徒のスケジュールに追加して、ブール値trueを返します。私はこれをしました、しかし何らかの理由でそれは私にエラーを与えています。コードは次のとおりです。
public static boolean addCourse(
Course[] catalog,
Course[] mySchedule,
int myNumCourses,
int dept,
int courseNum)
{
int j;
int i;
int k;
int deptCat;
int courseNumCat;
Course courseAdd = null;
char checkDay;
int checkTime;
if (mySchedule.length == myNumCourses) {
return false;
}
for (i = 0 ; i < catalog.length ; i++) {
Course course = catalog[i];
deptCat = course.getDepartment();
courseNumCat = course.getCourseNumber();
if (deptCat == dept && courseNumCat == courseNum) {
courseAdd = catalog[i];
break;
}
else continue; }
for (j = 0 ; j < myNumCourses ; j++) {
if (mySchedule[j] == null) {
mySchedule[j] = courseAdd;
return true;
}
else continue;
}
for (k = 0 ; k < mySchedule.length ; k++) {
Course course = mySchedule[k];
if (course != null) {
checkDay = course.getDay();
checkTime = course.getPeriod();
if (checkDay == courseAdd.getDay() && checkTime == courseAdd.getPeriod()) {
return false;
}
}
else continue;
}
}
ブール値の戻り値を認識しないのはなぜですか?ループの中に入れたからですか?