I have something that might help... When you have an array list of objects, each object has instance variable values. The idea is to extract and print the values of each variable in each object. The way you are doing it now prints the OBJECT (and its memory address, I think), rather than the variable values.
To solve this have a look at the program below. It's a program that sets and gets student grades, names, and student Id's and each student object is stored in an Array List. I wrote it to do exactly what you want (I think!). You need 2 classes... the main() method class to provide values for the variables, and a second class that has Getter methods, where each get() method gets the value you want. You print the values using the get() methods.
Here's the main() class...
public class GradeTester {
/**
* @param args
*/
public static void main(String[] args) {
ArrayList<Grader> GraderList = new ArrayList<Grader>();
Scanner in = new Scanner(System.in);
System.out.println("Enter the number of students: ");
String numStudents = in.next(); // Store the number of students
int numStu = Integer.valueOf(numStudents); //Convert String to int
System.out.println("Enter the Assignment name: ");
String assignName = in.next(); // Store the assignment name
for(int i = 0; i < numStu; i++){
System.out.println("Enter the student name: ");
String studentName = in.next(); // Store the student name
System.out.println("Enter the student ID: ");
String studentID = in.next(); // Store the student ID
System.out.println("Enter the student score: ");
String score = in.next(); // Store the student score
int studentScore = Integer.valueOf(score); //Convert
Grader graderObj = new Grader(assignName, studentScore, studentID, studentName);
GraderList.add(graderObj);
}
Collections.sort(GraderList);
ListIterator<Grader> iterator = GraderList.listIterator();
iterator = GraderList.listIterator();
while (iterator.hasNext())
System.out.println("The scores are: " + iterator.next().getScore()); //Display ordered scores
//Display each value for each grader object
for(Grader grader : GraderList){
System.out.println(grader.getAssignmentName() + grader.getStudentID() + grader.getStudentName() + grader.getScore());
}
And here is the class with the Getters that actually extract the variable values...
public class Grader implements Comparable {
String assignmentName;
String studentID;
String studentName;
int score;
/**
* @param assignmentName
* @param score
* @param studentID
* @param studentName
*/
public Grader(String assignmentName, int score, String studentID,
String studentName) {
super();
this.assignmentName = assignmentName;
this.score = score;
this.studentID = studentID;
this.studentName = studentName;
}
public String getAssignmentName() {
return assignmentName;
}
public String getStudentID() {
return studentID;
}
public String getStudentName() {
return studentName;
}
public int getScore() {
return score;
}
Hope this helps!
Tyster