public class CollegeCourse
{
private String courseID;
private int creditHours;
private char grade;
public String getCourse()
{
return courseID;
}
public int getCredits()
{
return creditHours;
}
public char getGrade()
{
return grade;
}
public void setCourse(String cid)
{
courseID=cid;
}
public void setCredits(int hours)
{
creditHours=hours;
}
public void setGrade(char g)
{
grade=g;
}
}
public class Student
{
private int studentID;
private CollegeCourse[] classes=new CollegeCourse[5];
public int getID()
{
return studentID;
}
public void setStudentID(int s)
{
studentID=s;
}
public CollegeCourse getCourses(int x)
{
CollegeCourse course=classes[x];
return course;
}
public void setObject(CollegeCourse obj,int x)
{
classes[x]=obj;
}
}
import java.util.Scanner;
public class InputGrades
{
public static void main(String[] args)
{
String course;
int credits;
char grade;
Student[] grades=new Student[10];
Scanner input=new Scanner(System.in);
for (int x=0;x<1;x++)
{
grades[x]=new Student();
System.out.println("Enter ID for student #"+(x+1));
grades[x].setStudentID(input.nextInt());
for(int y=0;y<5;y++)
{
CollegeCourse one=new CollegeCourse();
input.nextLine();
System.out.println("Enter course ID for class number "+y);
one.setCourse(input.nextLine());
System.out.println("Enter credits for "+y);
one.setCredits(input.nextInt());
input.nextLine();
System.out.println("Enter a grade for "+y);
one.setGrade(input.nextLine().charAt(0));
grades[x].setObject(one, y);
}
}
for (int i=0;i<1;i++)
{
for (int j=0;j<5;j++)
{
System.out.println("Course: "+grades[i].getCourses(j));
//Cant figure out how to print this
}
}
}
}
It will print the student ID number and that is it. It then prints out a bunch of garbage for the remaining courses displayed under the "j" for loop. I cant seem to figure it out... Any help would be appreciated
toString()or something, but as furkle said, we need a bit more info.