package Tutorial9; import java.util.NoSuchElementException; import java.util.LinkedList; import java.util.Iterator; public class StudentListTest { public static void main(String args[]) { Student s1 = new Student(20, 99); Student s2 = new Student(85); Student s3 = new Student(100, 95); Student s4 = new Student(98); LinkedList s = new LinkedList(); s.addLast(s1); s.addLast(s2); s.addLast(s3); s.addLast(s4); int score = 90; int c = StudentListTest.count(s, score); System.out.println("Hay " + c + " estudiantes con calificación superior a " + score + ". "); } public static int count(LinkedList s, int threshold) { Iterator it =s.iterator(); int count=0; while (it.hasNext()) { Student stu = (Student)it.next(); if (stu.getGrade() >= threshold) { stu.print(); count++; } } return count; } } class Student { private static int nextID = 1; private int id; //En realidad, no necesitamos utilizar el ID para este problema. private int grade; //private Student next; public Student( int i, int g) { id = i; grade = g; nextID=i+1; } public Student(int g) { id = nextID; grade = g; nextID++; } public int getGrade() { return grade; } public void print() { System.out.println("ID de estudiante: #"+id+"; Grade : "+grade); } }