diff --git a/Screenshot_2024-05-15-23-29-31-532_com.android.chrome.jpg b/Screenshot_2024-05-15-23-29-31-532_com.android.chrome.jpg new file mode 100644 index 0000000..bb1e323 Binary files /dev/null and b/Screenshot_2024-05-15-23-29-31-532_com.android.chrome.jpg differ diff --git a/exercise1/Human.java b/exercise1/HumaN.java similarity index 92% rename from exercise1/Human.java rename to exercise1/HumaN.java index 4b9b45e..dae8469 100644 --- a/exercise1/Human.java +++ b/exercise1/HumaN.java @@ -17,7 +17,7 @@ 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..0eee412 100644 --- a/exercise1/Main.java +++ b/exercise1/Main.java @@ -13,6 +13,23 @@ public class Main { public static void main(String[] args) { + public static void main(String[] args) { + Human student = new Student(); + Human professor = new Professor(); + +System.out.println(student instanceof Human); // true +System.out.println(professor instanceof Human); // true + Human human = new Student(); + human.sayMyName(); + /* خروجی: +SayMyName + - null + +You are GODDAMN right. */ + + Human human = new Professor(); + human.sayMyName(); // خروجی: My name is: null, I am from null + + + } } } diff --git a/exercise1/ProfessoR.java b/exercise1/ProfessoR.java new file mode 100644 index 0000000..5f093fa --- /dev/null +++ b/exercise1/ProfessoR.java @@ -0,0 +1,42 @@ +package exercise1; + +// Implement or extend the human class to make a professor class... +// 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 extends Human { + private String professorFaculty; +private int numberOfCourse; +private String professorSpecialty; + + +public void setProfessorFaculty(String professorFaculty) { + this.professorFaculty = professorFaculty; +} + +public void setNumberOfCourse(int numberOfCourse) { + this.numberOfCourse = numberOfCourse; +} + +public void setProfessorSpecialty(String professorSpecialty) { + this.professorSpecialty = professorSpecialty; +} + + +public String getProfessorFaculty() { + return professorFaculty; +} + +public int getNumberOfCourse() { + return numberOfCourse; +} + +public String getProfessorSpecialty() { + return professorSpecialty; +} + @Override + public void sayMyName() { + System.out.println("My name is: " + getFullName() + ", I am from " + professorFaculty); + } + +} diff --git a/exercise1/Professor.java b/exercise1/Professor.java deleted file mode 100644 index 7c3b522..0000000 --- a/exercise1/Professor.java +++ /dev/null @@ -1,8 +0,0 @@ -package exercise1; - -// Implement or extend the human class to make a professor class... -// 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 { -} diff --git a/exercise1/StudenT.java b/exercise1/StudenT.java new file mode 100644 index 0000000..57cdb4b --- /dev/null +++ b/exercise1/StudenT.java @@ -0,0 +1,52 @@ +package exercise1; + +// Human is an abstract concept, so we have created an abstract class to represent it... +// Implement or extend the Human class to make a student class. +// 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 extends Human { + private String studentNumber; + private String majorName; + private String universityName; + + public Student(String fullName) { + super(fullName); + } + + + public void setStudentNumber(String studentNumber) { + this.studentNumber = studentNumber; + } + + public String getStudentNumber() { + return studentNumber; + } + + public void setMajorName(String majorName) { + this.majorName = majorName; + } + + public String getMajorName() { + return majorName; + } + + public void setUniversityName(String universityName) { + this.universityName = universityName; + } + + public String getUniversityName() { + return universityName; + } + + + @Override + public void sayMyName() { + System.out.println("+SayMyName"); + System.out.println("-" + getFullName()); + System.out.println("+You are GODDAMN right."); + } +} +/* +https://youtube.com/shorts/UHSDllBVFOg?si=C5Dn0CDQPZUPmf03 +*/ diff --git a/exercise1/Student.java b/exercise1/Student.java deleted file mode 100644 index 0f8f606..0000000 --- a/exercise1/Student.java +++ /dev/null @@ -1,9 +0,0 @@ -package exercise1; - -// Human is an abstract concept, so we have created an abstract class to represent it... -// Implement or extend the Human class to make a student class. -// 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 { -}