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

Ashkan Asef #20

Open
wants to merge 2 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
1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion exercise1/Human.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
29 changes: 18 additions & 11 deletions exercise1/Main.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
package exercise1;

import java.util.ArrayList;
import java.util.List;

// After completing the Student and Professor classes, create an instance of each one:
// 6. Using instanceof keyword, check if the instances that you have created are really an instance of human class
// 7. Write the following code: Human human = new Student(); What is the output of human.sayMyName() ?
// 8. Now write this:
// Human human = new Professor();
// What is the output of human.sayMyName() ?
// 9. What can we understand from question 7 and 8?

public class Main {
public static void main(String[] args) {
Student student = new Student();
Professor professor = new Professor();

if (student instanceof Human) {
System.out.println("student is an instance of Human");
}
else
System.out.println("student is not an instance of Human");
if (professor instanceof Human) {
System.out.println("professor is an instance of Human");
}
else
System.out.println("professor is not an instance of Human");

Human human_student = new Student("student_name", 1, "math", "beheshti");
Human human_professor = new Professor("professor_name", "number theory", "mathematics", 24);

human_student.sayMyName();
human_professor.sayMyName();
}
}
49 changes: 43 additions & 6 deletions exercise1/Professor.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,45 @@
package exercise1;
public class Professor extends Human {
private String professorSpecialty;
private String professorFaculty;
private int numberOfCourses;

// 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 {
}
public Professor(String fullName, String professorSpecialty, String professorFaculty, int numberOfCourses) {
setFullName(fullName);
setProfessorSpecialty(professorSpecialty);
setProfessorFaculty(professorFaculty);
setNumberOfCourses(numberOfCourses);
}

public Professor() {
}

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(getFullName() + "-" + getProfessorFaculty());
}
}
47 changes: 42 additions & 5 deletions exercise1/Student.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,46 @@
package exercise1;
public class Student extends Human {
private int studentNumber;
private String majorName;
private String universityName;

// 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 Student(String fullName, int studentNumber, String majorName, String universityName) {
setFullName(fullName);
setStudentNumber(studentNumber);
setUniversityName(universityName);
setMajorName(majorName);
}

public class Student {
public Student(){
}


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

public int 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(getFullName());
}
}
14 changes: 14 additions & 0 deletions exercise1/answer.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
این نمونه ای از چندشکلی در برنامه نویسی است
از آنجایی که هر دو کلاس زیرشاخه های کلاس
Human
هستند میتوان شی ای از کلاس
Human
ساخت و آن را با کلاس های زیرشاخه
Student
و
Professor
مقداردهی کرد

به همین علت تابع
sayMyName
مقادیر متفاوتی به ازای هر شی دارد
24 changes: 24 additions & 0 deletions out/production/AP-1/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
replay_pid*
8 changes: 8 additions & 0 deletions out/production/AP-1/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions out/production/AP-1/.idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions out/production/AP-1/.idea/AP-1.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions out/production/AP-1/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions out/production/AP-1/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

124 changes: 124 additions & 0 deletions out/production/AP-1/.idea/uiDesigner.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions out/production/AP-1/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading