0

I'm creating a web-based scholar system for students to look up their scores, view their schedule, etc. However, I'm having a problem on architecting this system, as in I can't find a suitable way to associate the data.

There's a student, which is in a (school) class. The student has a scoreboard. The (school) class has a list of the "assignments" the students had for each subject, but it only has informations such as name, maximum score, weight. The actual score sits on the student's scoreboard.

  • Many students are in the same class.
  • Only one instance of an assignment should exist at any time, and it should live in the SchoolClass object, because it's then applied to the whole class instead of per-student.
  • A student, then, should only hold it's own score, and reference the rest of the assignment data from outside.

How do i reference the specific homework from the student?

That was kind of confusing. This is what I currently have:

class Student extends Person {
    private SchoolClass schoolClass;
    private Scorecard scorecard;
}

class Subject {
    private String name; /// "Compilers II", "Data Structures", etc.
}

class SchoolClass {
    private Course course; // "Computer Science", "Administration", etc.
    private List<Assignment> assignments;

    class Assignment {
        private Subject subject;
        private int maxScore;
        private int weight;
        private String name; // "Test about material resistance II"
    }
}

class Scorecard {
    // How to reference each assignment from each subject in this student's class cleanly?
}

Is my design going on a good direction or should I just erase this and begin again? Thanks!

Délisson Junio
  • 1,296
  • 4
  • 21
  • 43

1 Answers1

1

This is looking pretty good, but there are a couple things I would like to point out.

  • Is the Person classs abstract? If so then well done! If not it probably should be because person is a general term. For more information about when to make a class abstract check out my answer to this question.
  • Well done using Assignment as a nested class! It directly relates to SchoolClass so it should be nested, but how about the Subject class? That seems to be directly connected to SchoolClass as well therefore it would not be a bad idea to make Subject a nested class also.

As for referencing a single homework assignment, this depends on how you want to get it by. If you want to get it by index then use a getter. To do this you could simply put this code in SchoolClass:

public Assignment getAssignment(int index)
{
     return assignments.get(index);
}

However if you want to use reference it by name instead it is a little more tricky, but still pretty strait-forward. You would add a getter to your Assignment class like this:

public String getName()
{
    return name;
}

Then you would simply have to write another getter for SchoolClass like this:

public Assignment getAssignmentByName(String name)
{
    for (Assignment assignment : assignments)
    {
        if (assignment.getName().equals(name))
            return assignment;
    }

    System.out.println("No assignment found by the name of " + name);
    return null;
}

Hope that helps! If you have any questions don't hesitate to ask!

Edit:

In order to let your assignment objects describe themselves they should override Object.toString(). The following code should be put in your assignment class.

// I noticed that you only have a maxScore variable, I think that a score variable is needed
private int score;

@Override
public String toString()
{
    return "The score for this assignment is: " + score;
}
Community
  • 1
  • 1
BitNinja
  • 1,477
  • 1
  • 19
  • 25
  • Yes, `Person` is abstract. But I'm asking more about, like, how should each student's scorecard reference each assignment's score for his class? it's more than just finding the assignment by name, it has to contain something that tells the student something like "this is the score for assignment ***: x". should it contain hashmaps whose keys are Assignment's? What's your suggestion? – Délisson Junio Feb 16 '14 at 23:42
  • How about a `ReportCard` class? This could have an `ArrayList` of SchoolClass objects (one for each subject), which in turn already has a list of assignments. I updated the answer to include overriding the `toString()` method so that the assignment objects can describe themselves. – BitNinja Feb 16 '14 at 23:57
  • I don't think you understood what I asked fully, but you helped me anyways. I actually meant how to reference the Assignments from the Student class. The actual `Assignment` class doesn't have any info on the actual student's score because there is one instance of `Assignment` for a whole class. So I will end up using a HashMap on the `Student` class. – Délisson Junio Feb 17 '14 at 23:24