2017-02-01 17 views
1

私は自分のプログラムに問題を抱えています。なぜこのエラーが発生しているのか分かりません。どんな提案も大きな助けになるでしょう!私は何かが欠けているかどうかは分かりません。私は正しくArrayクラスをインポートしました。シンボルを見つけることができません - サイズ()

private String title; 
private ArrayList<Student> students; 
private int courseId; 
private static int courseIdList = 0; 

/** 
* 
*/ 
public Course(String tile) 
{ 
    this.title = title; 
    courseId = courseIdList; 
    courseIdList++; 
    students = new ArrayList<Student>(); 
} 

/** 
* @param returns the title 
*/ 
public String getTitle(String title) 
{ 
    return title; 
} 

/** 
* @return returns the ID 
*/ 
public int getId() 
{ 
    return courseId; 
} 

/** 
* 
*/ 
public void addStudent(Student students) 
{ 
    for(int i = 0; i < students.size(); i++) 
    { 
     if(students.getId() != students.get(i).getId()) 
     { 
      students.add(i); 
      return; 
     } 
    } 
} 

/** 
* 
*/ 
public void removeStudent(Student students) 
{ 
    for(int i = 0; i < students.size(); i++) 
    { 
     if(students.getId() == students.get(i).getId()) 
     { 
      students.remove(i); 
      return; 
     } 
    } 
} 

/** 
* @return if class is above or equal to 10 then return true, else return false; 
*/ 
public boolean isFull(Student students) 
{ 
    if(students.size() >= 30) 
    { 
     return true; 
    } 
    else 
    { 
     return false; 
    } 
} 

/** 
* @returns if the class is below ten then return true, else return false 
*/ 
public boolean cancel(Student students) 
{ 
    if(students.size() < 10) 
    { 
     return true; 
    } 
    else 
    { 
     return false; 
    } 
} 

/** 
* 
*/ 
public ArrayList<Student> getStudents() 
{ 
    return students; 
} 

/** 
* 
*/ 
public boolean inClass(Student students) 
{ 
    for(int i = 0; i < students.size(); i++) 
    { 
     if(student.getId() == students.get(i).getId()) 
     { 
      return true; 
     } 
    } 
    return false; 
} 

/** 
* boolean returns true if a student's ID mathes and false if their ID does not. 
*/ 
public boolean equals(Student s) 
{ 
    if(this.getId() == s.getId()) 
    { 
     return true; 
    } 
    return false; 
} 

/** 
* 
*/ 
public double getAverage() 
{ 
    double sum = 0; 

    for(Student s : students) 
    { 
     sum += s.getGrade(); 
    } 

    double avg = sum/students.size(); 
    return avg; 
} 

/** 
* 
*/ 
public void getHighestGrade() 
{ 
    int highestGrade = 0; 
    for(Student s : students) 
    { 
     if(students.getGrade() > s.get(i).getGrade()) 
     { 
      students.highestGrade(i); 
     } 
    } 

    return new Student(" ", 0,0); 
} 

/** 
* 
*/ 
public ArrayList<Student> getWarnings() 
{ 
    for(i = 0; i < students.size; i++) 
    { 
     if (students.getGrade() <= 70) 
     { 
      return students; 
     } 
    } 
} 

/** 
* 
*/ 
public void removeSeniors(Student students) 
{ 
    for(i = 0; i < students.size; i++) 
    { 
     if(students.getId() == students.get(i).subString(0,2).equalsTo(17)) 
     { 
      students.remove(i); 
     } 
    } 
} 

/** 
* 
*/ 
public void sortByGrade() 
{ 

} 

/** 
* 
*/ 
public void sortByAlpha() 
{ 

} 

/** 
* 
*/ 
public String toString() 
{ 
    String printOut = ""; 

    printOut += "Course name: " + title + "\nStudent ID: " + courseId; 

    return printOut; 

    for(Student students : students) 
    { 
     printOut += students.toString() + "\n"; 
    } 
} 

}

+0

'Student 'メソッドを' addStudent'メソッドと他の多くのメソッドに渡します。生徒のリストではありません。 List studentsのようなリストを渡す必要があります。 –

+0

@ottrob THXは動作しましたが、今はgetId()で同じエラーが発生していますか?それについて何か考えていますか? –

答えて

0

次にその反対:) studentsListなくStudentあります。リストをループして各生徒を処理する必要があります。

public void doSomething(List<Student> students) { 
    // does not work because students is a List of students not a student. 
    students.getId(); // ERROR 

    // loop over the list and then get the id of a single student 
    for(Student student : students) { 
     int id = student.getId(); 
     // do something with the id 
    } 
} 

size() Listインタフェース

getId()の方法は、あなたの学生のクラスのメソッドです。

関連する問題