Clinica2 - AlbertProfe/Java_AppWeb_Spring_2021 GitHub Wiki
Now we are studying an intro to teacher <> course <> student relationship many to many, we are developing more and more course and teacher classes. We have got 11 classes because we have added one more class: Doctor, so far we will not use Doctor class.
We add a new static method to test: testObjectsCourse
let's create and test some teacher and course objects to study casting and how reference-variable and object work at compilation time and running time
- Clinica.java
- Course.java
- Doctor.java
- Employee.java
- MainApplication.java
- MyDate.java
- Person.java
- Student.java
- Teacher.java
- Test.java
- Utilities.java

[https://github.com/AlbertProfe/Java_AppWeb_Spring_2021/blob/master/Clinica2/src/clinica/Teacher.java](Teacher Class)
Teacher's fileds:

Constructor: supersend up six parameters, five to Employee's constructor (salaryEmployee) and then from that spot Employee (name, day, month, year, basicSalary), five to Person's constructor. Once Employee's constructor and Person's constructor have created the object, just then they return to Teacher's constructor to make the rest of the job: this.paymentPerCourse and create the ArrayList courses

We need to create the course methods just to add/remove the object's course from the ArrayList courses

We also need to create the getSalary method, that will inherence basicSalary from Person, salaryEmployee from Employee and then calculate the teacherAsSalary as paymentPerCourse * the size of the arrayList courses, so paymentPerCourse * this.getCourses().size()

Getters and setter from the IDE:

toString, we create a custom toString, so we text @Override and the teacher's data with the super to create the string from Employee's and Person's data.

Teacher Class code:
public class Teacher extends Employee{
private ArrayList<Course> courses;
private double paymentPerCourse;
private double salaryAsTeacher = 0.0;
public Teacher(String name, int day, int month, int year,
double basicSalary, double salaryEmployee,double paymentPerCourse) {
super(name, day, month, year, basicSalary, salaryEmployee);
this.paymentPerCourse = paymentPerCourse;
this.courses = new ArrayList<Course>();
}
@Override
public double getSalary () {
return this.getSalaryAsTeacher() + basicSalary + salaryEmployee;
}
public void addCourse (Course course) {
this.courses.add(course);
//setSalaryAsTeacher();
}
public void removeCourse (Course course) {
this.courses.remove(course);
//setSalaryAsTeacher();
}
public ArrayList<Course> getCourses() {
return courses;
}
public void setCourses(ArrayList<Course> courses) {
this.courses = courses;
}
@Override
public String toString() {
return "Teacher" + super.toString()
+ "\n number of courses: " + this.getCourses().size()
+ "\n [courses=" + courses + " ]"
+ "\n paymentPerCourse: " + paymentPerCourse
+ "\n salaryAsTeacher: " + paymentPerCourse * this.getCourses().size()
+ "\n salary Total: " + this.getSalary();
}
//getter and setters from ide ...
}
We also discuss polymorphism and compilation time vs execution (running) time at public static void testObjectsCourse()

Compilation time vs running time:
