Skip to content

Amir Hossein Roosta. #2

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

Open
wants to merge 7 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion exercise1/Human.java → 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");
}
}
17 changes: 17 additions & 0 deletions exercise1/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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


}

}
}
42 changes: 42 additions & 0 deletions exercise1/ProfessoR.java
Original file line number Diff line number Diff line change
@@ -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);
}

}
8 changes: 0 additions & 8 deletions exercise1/Professor.java

This file was deleted.

52 changes: 52 additions & 0 deletions exercise1/StudenT.java
Original file line number Diff line number Diff line change
@@ -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
*/
9 changes: 0 additions & 9 deletions exercise1/Student.java

This file was deleted.