Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exercise1;ParnianAghili #3

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Human.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package exercise1;

public abstract class Human {
private String fullName;

public String getFullName() {
return fullName;
}

public void setFullName(String fullName) {
this.fullName = fullName;
}

public void sayMyName() {
System.out.println("I'm a human!");
}

public final void staticPrint() {
System.out.println("This function should always print this string in all subclasses");
}
}
35 changes: 35 additions & 0 deletions Professor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package exercise1;

public class Professor extends Human {
private String professorSpecialty;
private String professorFaculty;
private int numberOfCourses;

public String getProfessorSpecialty() {
return professorSpecialty;
}

public void setProfessorSpecialty(String professorSpecialty) {
this.professorSpecialty = professorSpecialty;
}

public String getProfessorFaculty() {
return professorFaculty;
}

public void setProfessorFaculty(String professorFaculty) {
this.professorFaculty = professorFaculty;
}

public int getNumberOfCourses() {
return numberOfCourses;
}

public void setNumberOfCourses(int numberOfCourses) {
this.numberOfCourses = numberOfCourses;
}

public void sayMyName() {
System.out.println("Full Name: " + getFullName() + ", Faculty: " + getProfessorFaculty());
}
}
36 changes: 36 additions & 0 deletions main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package exercise1;

public class Professor extends Human {
private String professorSpecialty;
private String professorFaculty;
private int numberOfCourses;

public String getProfessorSpecialty() {
return professorSpecialty;
}

public void setProfessorSpecialty(String professorSpecialty) {
this.professorSpecialty = professorSpecialty;
}

public String getProfessorFaculty() {
return professorFaculty;
}

public void setProfessorFaculty(String professorFaculty) {
this.professorFaculty = professorFaculty;
}

public int getNumberOfCourses() {
return numberOfCourses;
}

public void setNumberOfCourses(int numberOfCourses) {
this.numberOfCourses = numberOfCourses;
}

@Override
public void sayMyName() {
System.out.println("Full Name: " + getFullName() + ", Faculty: " + getProfessorFaculty());
}
}
36 changes: 36 additions & 0 deletions student.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package exercise1;

public class Student extends Human {
private String studentNumber;
private String majorName;
private String universityName;

public String getStudentNumber() {
return studentNumber;
}

public void setStudentNumber(String studentNumber) {
this.studentNumber = studentNumber;
}

public String getMajorName() {
return majorName;
}

public void setMajorName(String majorName) {
this.majorName = majorName;
}

public String getUniversityName() {
return universityName;
}

public void setUniversityName(String universityName) {
this.universityName = universityName;
}


public void sayMyName() {
System.out.println("Full Name: " + getFullName());
}
}
6 changes: 6 additions & 0 deletions tozihhat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

/*
هر دو کلاس Student و Professor از کلاس Human ارث‌بری می‌کنند و به این ترتیب توانایی استفاده از ویژگی‌ها و روش‌های ارث‌بری شده را دارند.
با این حال، خروجی‌هایی که از متدهای sayMyName برای نمونه‌های Student و Professor دریافت می‌شود نشان می‌دهد که مقادیر fullName و professorFaculty
برای آنها مقداردهی نشده است، به همین دلیل خروجی این مقادیر به صورت null است.
*/