I was required to apply OOP concepts in every exercise in my Computer Science class. Exercise 7 introduced us to Classes and Objects. We had to create a class called Person and program it to add, remove, and display a person from a 1-dimensional array of 10 persons. Next came in Exercise 8 and 9, where we were introduced to Inheritance and Encapsulation where we had to create a Student class which would inherit from Person, a Teacher class which would inherit from Person, and a Principal class that would inherit from Person. Student class included:
- First and last name
- Home and email address
- Phone number and student ID
- A 1-dimensional array of four courses
Teacher class included:
- Teacher`s name (Mr/Ms/Mrs last name)
- Department name (assume 1 only)
- 3 course names (courseA, courseB, courseC)
- student list for course 1 (max 20)
- student list for course 2 (max 20)
- student list for course 3 (max 20)
- method to add a student to a course (eg. addStudent(String coursename, Student student))
- method to check if the course is full or not (eg. isCourseFull(String courses))
The Principal class included:
- list of teachers (max. 10)
- school name
- a method to find the teacher and add the student to the course (eg. addStudentToCourse(Person student, String courseName)
- a method to add a Teacher to the school (eg. addTeacherToSchool(Teacher teacher))
I had to be able to add, remove, and display a list of students/teachers, which works perfectly fine as I completed this.
But, our next task was in Exercise 10, which introduced us to Polymorphism and Casting. We had to create a School class which would have a school name, address, principal`s name, and a list of people (max. 300). I have to design a method the adds people to the school: addPersonToBuilding(Person person), and then modify my previous program so that people are added to the school when they are created. My program (main method) should only require a reference to the School class.
I have created the School class already, along with the variables, getters and setters, and created the methods addPersonToBuilding, addStudentToSchool, and addTeacherToSchool, but there isn`t much in them yet.
I just want some guidance on the School class. When creating the method addPersonToBuilding, I would add the student and teacher instance in the people array. I`d create a method to add a student/teacher to the school, and in those methods, add the student/teacher into the people array. The addPersonToBulding method would refer to the add student/teacher to school methods. The method to add PersonToBuliding will be called on for whenever the user chooses to add a student/teacher in the main method. Would this be used in main? Would a constructor be made for this? Would I use studentPerson/teacherPerson as my instances to add a student/teacher to school? How will things change from exercise 8/9 - 10? Like, in the main method, since it will only refer to the School class, what will be changed? The instances? The methods to add a student/teacher? Principal input? School input?
- Person studentPerson = new School(); (Polymorphism??)
- Person teacherPerson = new School(); (Polymorphism??)
I know what I need to do, and I have created an entire notepad to brainstorm ideas and list some key information that I think will be necessary for School class. All I need is a little guidance and advice. Am I on the right track?