Array of objects problem

I am new to here and new to Java, so please take it easy on me! lol
I am trying to create an array of objects with the initial dataset coming from a txt file. Here is a sample of the txt file ..

COSC1073:Programming 1
ISYS1057:Database Concepts
COSC1082:Computer Organization
MATH1074:Mathematics for Computing

Here is my code to extract the data and add into an array of Course objects...
[code]public class gradCheck {

public static void main(String[] args) throws IOException {
//Create Array for the objects
Course[] courseArray = new Course[18];

//Create an instance of the file courses = new"courses.txt");

//Create the scanner
Scanner input = new Scanner(courses);

//Read data from the file
for (int i = 0; i < courseArray.length; i++){
String courseCode =;
String courseName = input.nextLine();
courseArray[i] = new Course (courseCode, courseName);


//below is my Course class

public class Course {

String courseCode;
String courseName;

Course (){
courseCode = "null";
courseName = "null";

Course (String courseCode, String courseName){

public String getCourseCode(String courseCode){
return setCourseCode(courseCode);

private String setCourseCode(String courseCode) {
this.courseCode = courseCode;
return courseCode;

public String getCourseName(String courseName){
return setCourseName(courseName);

private String setCourseName(String courseName) {
this.courseName = courseName;
return courseName;

Sample of the output when printing contents in the object array.
Course@a62fc3 ...

Should be more like ...
COSC1073:Programming 1
ISYS1057:Database Concepts
COSC1082:Computer Organization ...


  • When you're printing out your data it should be

    System.out.println(courseArray[i].getCourseCode() + ":" + courseArray[i]getCourseName());
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


In this Discussion