Skip to content

Develop #6

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 11 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
Binary file added exercise1/Ex9.pdf
Binary file not shown.
10 changes: 5 additions & 5 deletions exercise1/Human.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
15 changes: 14 additions & 1 deletion exercise1/Main.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
package exercise1;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -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

}
}
39 changes: 38 additions & 1 deletion exercise1/Professor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
38 changes: 37 additions & 1 deletion exercise1/Student.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}