Class Roster
First Last: 98
First Last: 85
In doing this I am supposed to use an iterator and a while loop to iterate through the ArrayList of students. I can use a for each loop but I DO NOT want to do so as I want to learn how to do it without that method right now. I was doing it like this but I am getting errors:
public class Roster {
//
// Data members
//
private ArrayList<Student> students;
//
// Constructors
//
/**
* Constructor to create a Roster object.
*
*/
public Roster() {
// Instantiate the ArrayList of students
ArrayList<Student> students= new ArrayList<Student>();
createStudents();
}
//
// Operations
//
//
// Helper methods
//
private void createStudents() {
// Create students for the ArrayList
Student aStudent= new Student("Bugs","Bunny",98);
Student bStudent= new Student("Daffy","Duck",77);
Student cStudent= new Student("Elmer", "Fudd",85);
Student dStudent= new Student();
//Add each student to the students ArrayList
students.add(aStudent);
students.add(bStudent);
students.add(cStudent);
students.add(dStudent);
// Use the mutator methods of the Student class to set the fourth Student
// to be "Porky", "Pig", 92
students.get(3).setFirstName("Porky");
students.get(3).setLastName("Pig");
students.get(3).setStudGrade(92);
String getClassStats;
Iterator<Student> studentIterator= students.listIterator();
while studentIterator.hasNext();
{
Student aStudent= studentIterator.next();
System.out.println(aStudent.getClassStats());
}
I am then supposed to be able to go into my other class and add a method call to getClassStats and then print out the string that is returned to check it. I have done this but I am getting errors as well:
public class RosterDemo {
/**
* Demos the functionality of the Roster class.
*/
public void run()
{
// Create a Roster
Roster theRoster = new Roster();
//Get class statistics
System.out.println(getClassStats());
}
Not being able to print that line out is really hurting me because I can't see what I have done but every example I come across people are doing everything in one main method and not having to pull from other classes.

New Topic/Question
Reply



MultiQuote





|