0

One school has multiple classes. Each class has different classID. Teachers have name, age and teach multiple subjects. Students have name, age and unique identity number in class. Teachers and students are people. Subjects have subject name.

How to relate teachers who teach multiple subjects to different classes? For example Miss A teaches math and science to class 1 but only literature to class 2. And one class can have multiple teachers.

public class Classes {
    private int classId;
    private List<Subjects> subjectsList;
    private List<Students> studentsList;

    public Classes(int classId, List<Subjects> subjectsList,
                   List<Students> studentsList){
        this.classId = classId;
        this.subjectsList = subjectsList;
        this.studentsList = studentsList;
    }
}

public class People {
    private String name;
    private int age;

    public People(String name, int age){
        this.name = name;
        this.age = age;
    }
}

public class Students extends People{
    private int classIdentityID;
    public Students(String name, int age, int classIdentityID){
        super(name,age);
        this.classIdentityID = classIdentityID;
    }
}

public class Subjects {
    private String subjectName;
    
    public Subjects(String subjectName){
        this.subjectName = subjectName;
    }
}

public class Teachers extends People{
    private List<Subjects> subjectsList;

    public Teachers(String name, int age,List<Subjects> subjectsList){
        super(name, age);
        this.subjectsList = subjectsList;
    }
}

If I need to know who is teaching math in class 1, how should I design a table so it is not difficult to query?

philipxy
  • 14,867
  • 6
  • 39
  • 83
  • What is your 1 specific researched non-duplicate question re how/why you are 1st stuck on what step among which following what published presentation of what design method given what? How are you stuck querying? [mre] Right now you are essentially asking us to (re)write a textbook with bespoke tutorial with no details on what you misunderstand or do or don't understand. [ask] [Help] Basic questions are faqs. [research](https://meta.stackoverflow.com/q/261592/3404097) [“help me"](https://meta.stackoverflow.com/q/284236/3404097) [homework](https://meta.stackoverflow.com/q/334822/3404097) – philipxy Nov 16 '22 at 06:33
  • Actually, I stuck with how to design the relationships between Teachers-Classes-Subjects. The teachers can teach many subjects that are not necessary in the one class while one class can have multiple teachers for multiple subjects. – David Moore Nov 16 '22 at 07:00
  • Please clarify via edits, not comments. Please put all but only what is needed to ask your 1 specific question in your post. Please act on my earlier comments. PS So what is stopping you from recording 'teacher [tid] teaches subject [sid] in class [cid]?'--or smaller relationships that it might be expressible in terms of--although you should explain how you are stuck following your given method. – philipxy Nov 16 '22 at 07:16
  • [relationships between 3 entities in ER diagram--is a ternary enough or are 2 binaries also needed?](https://stackoverflow.com/a/45557994/3404097) [Should this ER diagram use a ternary relationship instead](https://stackoverflow.com/a/44235312/3404097) [Best Solution - Ternary or Binary Relationship](https://stackoverflow.com/a/35337369/3404097) – philipxy Nov 16 '22 at 07:50
  • Table relation(ship)s aka associations aka meanings aka (row) membership criteria aka (characteristic) predicates are necessary & sufficient to record & query. Constraints--including cardinalities--saying how "many"--need not exist, be known or be declared to record or query. They can be used to help improve designs. (And declaring can help a DBMS to disallow some invalid states & to optimize.) – philipxy Nov 16 '22 at 08:22

0 Answers0