diff --git a/exercise1/Ex9.pdf b/exercise1/Ex9.pdf new file mode 100644 index 0000000..87a017e Binary files /dev/null and b/exercise1/Ex9.pdf differ diff --git a/exercise1/Human.java b/exercise1/Human.java index 4b9b45e..9076bca 100644 --- a/exercise1/Human.java +++ b/exercise1/Human.java @@ -2,22 +2,22 @@ // 1.Change the staticPrint() method so that its output cannot be changed in all the classes that extend or implement Human. -public abstract class Human { +public abstract class Human{ private String fullName; - public String getFullName() { + public String getFullName(){ return fullName; } - public void setFullName(String fullName) { + public void setFullName(String fullName){ this.fullName = fullName; } - public void sayMyName() { + public void sayMyName(){ System.out.println("im a human!"); } - public void staticPrint() { + public static final void staticPrint(){ System.out.println("this function should always print this string in all subclasses"); } } diff --git a/exercise1/Main.java b/exercise1/Main.java index ad47473..4f149be 100644 --- a/exercise1/Main.java +++ b/exercise1/Main.java @@ -1,4 +1,3 @@ -package exercise1; import java.util.ArrayList; import java.util.List; @@ -13,6 +12,20 @@ public class Main { public static void main(String[] args) { + Student student = new Student(); + System.out.println(student instanceof Human); // true + Professor professor = new Professor(); + System.out.println(professor instanceof Human); // true + + Human human1 = new Student(); + human1.sayMyName(); + // -> Fullname: null + + Human human2 = new Professor(); + human2.sayMyName(); + // -> Fullname: null + // ProfessorFaculty: null + } } diff --git a/exercise1/Professor.java b/exercise1/Professor.java index 7c3b522..2a5b0f3 100644 --- a/exercise1/Professor.java +++ b/exercise1/Professor.java @@ -4,5 +4,42 @@ // 4.Add the following attributes to this class with setters and getters: professorSpecialty, professorFaculty, numberOfCourse // 5.Change the professor class so that when we call the sayMyName() method on an instance of this class, fullName of the professor plus their professorFaculty is printed. -public class Professor { +public class Professor extends Human{ + private String professorSpecialty; + private String professorFaculty; + private int numberOfCourses; + + // public Professor(String fullName){ + // super.setFullName(fullName); + // } + + // professorSpecialty + public String getProfessorSpecialty(){ + return professorSpecialty; + } + public void setProfessorSpecialty(String professorSpecialty){ + this.professorSpecialty = professorSpecialty; + } + + // professorFaculty + public String getProfessorFaculty(){ + return professorFaculty; + } + public void setProfessorFaculty(String professorFaculty){ + this.professorFaculty = professorFaculty; + } + + // numberOfCourse + public int getNumberOfCourses(){ + return numberOfCourses; + } + public void setNumberOfCourses(int numberOfCourses){ + this.numberOfCourses = numberOfCourses; + } + + // sayMyName + public void sayMyName(){ + System.out.println("FullName: " + getFullName()); + System.out.println("ProfessorFaculty: " + getProfessorFaculty()); + } } diff --git a/exercise1/Student.java b/exercise1/Student.java index 0f8f606..051a2c1 100644 --- a/exercise1/Student.java +++ b/exercise1/Student.java @@ -5,5 +5,41 @@ // 2. Change the student class so that when we call the sayMyName() method on an instance of this class, the fullName attribute of the student is printed. // 3.Add the following attributes to the student class with setters and getters: studentNumber, majorName, universityName -public class Student { +public class Student extends Human{ + private String studentNumber; + private String majorName; + private String universityName; + + // public Student(String fullName){ + // super.setFullName(fullName); + // } + + // studentNumber + public String getStudentNumber(){ + return studentNumber; + } + public void setStudentNumber(){ + this.studentNumber = studentNumber; + } + + // majorName + public String getMajorName(){ + return majorName; + } + public void setMajorName(String majorName){ + this.majorName = majorName; + } + + // universityName + public String getUniversityName(){ + return universityName; + } + public void setUniversityName(String universityName){ + this.universityName = universityName; + } + + // sayMyName + public void sayMyName(){ + System.out.println("Fullname:" + getFullName()); + } }