I wanted to make a class GradeBook, then create an object for each student, and save their name and courseName and Grade in a vector, then in the end, print them all. Here's my code:
public static void main(String [] args)
{
Vector<GradeBook> gVec = new Vector<GradeBook>() ;
Scanner sc = new Scanner (System.in) ;
String sName = sc.nextLine();
String cName = sc.next();
int grade = sc.nextInt() ;
while(!sName.equals("end"))
{
GradeBook st = new GradeBook() ;
st.setCouseInfo(sName, cName, grade) ;
gVec.add(st) ;
sName = sc.nextLine();
cName = sc.next();
grade = sc.nextInt() ;
}
}
The prgoram gets name, checks if it's "end" or not, then gets the courseName and the grade, sets them to GradeBook Fields which are studentName, courseName and courseGrade, then it adds them to a vector of GradeBook.
But in the end of the program I have a problem printing the results, it can't be done like how I did it in C++, like:
for ( int i=0;i<gVec.size();i++)
{
System.out.println(gVec[i].studentName);
System.out.println(gVec[i].courseName);
System.out.println(gVec[i].courseGrade);
}
Can someone give me a tip on how to use vectors in java? Thanks!