0

My program is not printing out details from my ArrayList that is drawn from a text file. Text file details are spilt into 2 in a database manner sharing one similarity.

I know I am leaving out all my other classes but I would like to know what it is printing or where is it calling from?

Program output from my text file/ ArrayList:

Students above average: CourseworkStudent@53f65459 CourseworkStudent@3b088d51

Student below average: CourseworkStudent@1786dec2 CourseworkStudent@74650e52 CourseworkStudent@15d0c81b

Main Client

public class MainClient {
public static int choice;
public static Scanner kb = new Scanner(System.in);
ArrayList<Student> courses = new ArrayList<Student>();
ArrayList<Student> students = new ArrayList<Student>();
public void studentTxtRead() {//Reading of Student.txt 
    Scanner studFile = null;
    try {
    studFile = new Scanner(new File("Student.txt"));
        while(studFile.hasNextLine()){
        String line = studFile.nextLine();
        String[] data = line.split("\\s+");
        students.add(new Student(data[0], data[1], data[2], Long.parseLong(data[3])
        ,Integer.parseInt(data[4]),Integer.parseInt(data[5]), Integer.parseInt(data[6])));
        }//end of while loop
    }//end of try loop
    catch(FileNotFoundException ex){
        System.out.println("FILE NOT FOUND");
    }
    studFile.close();
}//end of studentTxtRead

public void courseworkStudentAvg(){
    double total = 0.0;
    int count = 0;
     for(int i = 0; i < courses.size(); i++){
         if(courses.get(i) instanceof CourseworkStudent) {
         CourseworkStudent courseW = (CourseworkStudent)courses.get(i);
         total += courseW.getCourseMarks();
         count++;
     }//end of if
}//end of for
     double avg = total/count;
     System.out.println("Students above averge: ");
     for(int i=0; i<courses.size(); i++) {
         if(courses.get(i)instanceof CourseworkStudent) {
             CourseworkStudent courseW =(CourseworkStudent) courses.get(i);
             if(courseW.getCourseMarks()> avg) {
                 System.out.println(courseW);
             }//end of if
         }//end of if
      }//end of for
     System.out.println("\nStudent below average: ");
     for(int i =0; i<courses.size(); i++) {
         if(courses.get(i) instanceof CourseworkStudent) {
             CourseworkStudent courseW = (CourseworkStudent) courses.get(i);
             if(courseW.getCourseMarks()< avg) {
                 System.out.println(courseW);
             }//end of if
         }//end of if
      }//end of for
}//end of courseworkStudentAvg

public void calculateCouGradeMarks(){//calculate grade/marks for coursework
       for(int i = 0; i < courses.size(); i++){// Calculate grades for Course Student
           if(courses.get(i) instanceof CourseworkStudent){
               CourseworkStudent courW = (CourseworkStudent) courses.get(i);
               courW.CGrading();
           }
       }           
}//end of CalculateCouGradeMarks  
  • Welcome to Stackoverflow, please read [How To Ask](https://stackoverflow.com/help/how-to-ask). Pay special attention to [How To Create MCVE](https://stackoverflow.com/help/mcve). Make sure you tag your question with proper labels (programming language, relevant technologies etc). The more effort you'll put into posting a good question: one which is easy to read, understand and which is [on topic](https://stackoverflow.com/help/on-topic) - the chances are higher that it will attract the relevant people and you'll get help even faster. Good luck! – Nir Alfasi Nov 17 '20 at 13:10

2 Answers2

0

Add a toString() Method to your CourseworkStudent class

Mirko
  • 1,512
  • 1
  • 12
  • 19
0

You are attempting to print object instances of CourseworkStudent. These are the objects described as e.g. CourseworkStudent@53f65459.

This is because System.out.println() cannot interpret your object as a String. So it prints an object identifier.

In order to print contents you need implement a toString() function, as stated in the other answer, and precisely define what your objects are supposed to look like as a string.

Koenigsberg
  • 1,726
  • 1
  • 10
  • 22