Clinica2 - AlbertProfe/Java_AppWeb_Spring_2021 GitHub Wiki

Clinica2

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

public static void 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

  1. Clinica.java
  2. Course.java
  3. Doctor.java
  4. Employee.java
  5. MainApplication.java
  6. MyDate.java
  7. Person.java
  8. Student.java
  9. Teacher.java
  10. Test.java
  11. Utilities.java

Clinica2

public Class Teacher()

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

Teacher's fileds:

teacher

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

teacher_constructor

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

teaccher_course

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()

teacher_getsalary

Getters and setter from the IDE:

teaccher_gettersettersalary

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.

teaccher_tostring

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()

test object course and test polymorphism

Compilation time vs running time: Compilation vs running

⚠️ **GitHub.com Fallback** ⚠️