Hello all,

I have defined 3 classes with their attributes including their unique ID. The relationship between these objcts are hirarchical. For example, I have school, class, and students. At the begining of the simulation I create the school and number of classes and put students in the classes and store the list of school's and classes students in a list. At some points in time I am gadering all the students at the school level and sorting them out. This is happening at the school object the school and put them in the same or different classes based on one of their attributes (lets say thier social behaviors). Most of the students should be assigned to their former class (because of some sort of bound that they have created) but some are gonna change class.
Here is the skech of my 3 classes:

public class School {

private ArrayList<Student> SchoolList = new ArrayList<Student>();
.//Some other related attributes
.
.
    }

public class ClassRoom{
    private int classSize;
    private int ClassID;
    private ArrayList<Student> classList = new ArrayList<Student>();
    .
    .
    .
}
 public class Student{
    private int StID;
    privar int ClassID;
    .//Other attributes
    .

 }

My probelem is puting the sorted list of students from my schoolList to their classList in such a way that they maintain their old class unless they have to change it.
I guess, in short my problem is how to link the class Id and students in such a way that I can find them later.
PS: This supposed to be a quick project then i don't want to go to relational DBs and stuff. Also, I do have a classList and I can compare that with the new list of students to check if they are the same but this makes the program runs so slow that makes it out of the question.
I hope it made sense.

Thank you for any advice.

Think of it like this:

  1. School has list of students and courses. Each is unique to the school.
  2. Each course has a number of classes, uniquely identified by time and teacher (you can have multiple classes for the same course at the same time, but not the same teacher).
  3. Each class has a list of students, but each student CANNOT be in more than one class at the same time.
  4. A student can change from one class to another (in the same or another course) IF they don't have a scheduling conflict and the target class still has room for more students. That is a move operation on the student from class A to class B.

As for your program running slowly, it is likely you are doing an in-depth search which is terribly inefficient. Using hash lists is a good way to deal with situations where there can only be one of each entity in the list, such as students in the school, or class.

Thank you for the response.
Please forget about courses and schedule those are not important at all. The thing that I need is to find those students that have been in a class ID 0 and in the next period put them back in the same class ID 0 unless their ranking changed and they should move to another class. For me this is really important to after sorting all the students in the school put them back to the old class ID if their ranking allow it.

this makes the program runs so slow that makes it out of the question

Is this an assumption, or did you try it? You can sort a lot of objects in milliseconds on a 21st century PC.

Anyway, without seeing more of your code it's hard to understand why this seems so difficult. Do you have something in Student to maintain a list of the courses/classes that the Student is currently enrolled in? That would make processing a lot easier, at a small caost in terms of updating.

Edited 3 Years Ago by JamesCherrill

This article has been dead for over six months. Start a new discussion instead.