• Advertisement
Sign in to follow this  

help with arrayList class in java...

This topic is 4480 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hey, i am trying to make this program for my java class... this is what I have in main:
import java.util.ArrayList;
public class CRS
{
	public static void main (String []args)
	{
		Instructor [] inst = new Instructor [3];
		Student [] stud = new Student [3];
		Course [] cours = new Course [3];
		ArrayList <Registration> registration = new ArrayList  <Registration>();

		inst [0] = new Instructor ("Ron Davidson", 1);
		inst [1] = new Instructor ("William Davis", 2);
		inst [2] = new Instructor ("Kevin Wilson" , 3);

		cours [0]= new Course ("CS100", "Intro to Comp Sci", 5, 30, 15, inst [0]);
		cours [1]= new Course ("CS151", "OOP with C++ I", 4, 25, 22, inst [1]);
		cours [2]= new Course ("CS143", "OOP with Java II", 3, 40, 38, inst [2]);

		stud [0] = new Student ("Shivam Mathur", 1);
		stud [1] = new Student ("Linda Clark ", 2);
		stud [2] = new Student ("Mark Harris", 3);

		registration.add (new Registration (0.0, cours [0], stud [0]));
		registration.add (new Registration (0.0, cours [1], stud [1]));
		registration.add (new Registration (0.0, cours [2], stud [2]));
		registration.add (new Registration (0.0, cours [1], stud [0]));
		registration.add (new Registration (0.0, cours [2], stud [1]));
		registration.add (new Registration (0.0, cours [0], stud [2]));
		registration.add (new Registration (0.0, cours [2], stud [0]));
		registration.add (new Registration (0.0, cours [0], stud [1]));
		registration.add (new Registration (0.0, cours [1], stud [2]));
		
		System.out.println ("Creating instructors...");
		System.out.println ("Creating courses...");
		System.out.println ("Creating students...");
		System.out.println ("Registering students...");
		System.out.println ("Assigning grades...");
		System.out.println ();
		System.out.println ("SID\t" + "StudentName\t" + "Course\t" + "Credits\t" + "Instructor\t" + "Grade");
		System.out.println ("---\t" + "-----------\t" + "------\t" + "-------\t" + "----------\t" + "-----");

		for (int i = 0; i < registration.size(); i++)
		{
			System.out.println(registration.get(i));
		}

	}
}


One of the requirements for the assignment was not to assign grades when registrations are created. So I created registration with grades 0.0 for all grades. Now I have to assign grades to every student using the setStudentGrade() method. But I don't know how to use it with the arrayList class becuase I didn't create registrations in this format Registration regi1 = new Registration(0.0, cours [0], stud [0]); with this I could have just done "regi1.setStudentGrade(3.4);" I hope this makes sense thankyou

Share this post


Link to post
Share on other sites
Advertisement
i am not really sure what you are having trouble with, but why not extend arraylist by creating your own student class that contains fields which include grade?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement