-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
252 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/main/java/me/alex4386/gachon/sw14462/day18/ex9_6/Employee.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package me.alex4386.gachon.sw14462.day18.ex9_6; | ||
|
||
public class Employee extends Person { | ||
private int employeeID; | ||
private String department; | ||
|
||
public Employee(String name, int employeeID, String department) { | ||
super(name); | ||
this.employeeID = employeeID; | ||
this.department = department; | ||
} | ||
|
||
public void writeOutput() { | ||
super.writeOutput(); | ||
System.out.println("Employee ID: " + employeeID); | ||
System.out.println("Department: " + department); | ||
} | ||
|
||
public boolean equals(Employee otherEmployee) { | ||
return this.hasSameName(otherEmployee) && (this.employeeID == otherEmployee.employeeID) && this.department.equalsIgnoreCase(otherEmployee.department); | ||
} | ||
|
||
public int getEmployeeID() { | ||
return employeeID; | ||
} | ||
|
||
public String getDepartment() { | ||
return department; | ||
} | ||
|
||
public void setEmployeeID(int employeeID) { | ||
this.employeeID = employeeID; | ||
} | ||
|
||
public void setDepartment(String department) { | ||
this.department = department; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Employee - Name: " + getName() + ", Employee ID: " + employeeID + ", Department: " + department; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/me/alex4386/gachon/sw14462/day18/ex9_6/Faculty.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package me.alex4386.gachon.sw14462.day18.ex9_6; | ||
|
||
public class Faculty extends Employee { | ||
private String title; | ||
|
||
public Faculty(String name, int employeeID, String department, String title) { | ||
super(name, employeeID, department); | ||
this.title = title; | ||
} | ||
|
||
public void setTitle(String newTitle) { | ||
title = newTitle; | ||
} | ||
|
||
public String getTitle() { | ||
return title; | ||
} | ||
|
||
public void writeOutput() { | ||
super.writeOutput(); | ||
System.out.println("Title: " + title); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Faculty - Name: " + getName() + ", Title: " + title; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/me/alex4386/gachon/sw14462/day18/ex9_6/Main.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package me.alex4386.gachon.sw14462.day18.ex9_6; | ||
|
||
import java.util.Arrays; | ||
|
||
public class Main { | ||
public static void main(String[] args) { | ||
PolymorphismDemo.main(args); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/me/alex4386/gachon/sw14462/day18/ex9_6/Person.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package me.alex4386.gachon.sw14462.day18.ex9_6; | ||
|
||
public class Person | ||
{ | ||
private String name; | ||
public Person() | ||
{ | ||
name = "No name yet"; | ||
} | ||
|
||
public Person(String initialName) | ||
{ | ||
name = initialName; | ||
} | ||
|
||
public void setName(String newName) | ||
{ | ||
name = newName; | ||
} | ||
|
||
public String getName() | ||
{ | ||
return name; | ||
} | ||
|
||
public void writeOutput() | ||
{ | ||
System.out.println("Name: " + name); | ||
} | ||
|
||
public boolean hasSameName(Person otherPerson) | ||
{ | ||
return this.name.equalsIgnoreCase(otherPerson.name); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/me/alex4386/gachon/sw14462/day18/ex9_6/PolymorphismDemo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package me.alex4386.gachon.sw14462.day18.ex9_6; | ||
|
||
public class PolymorphismDemo | ||
{ | ||
public static void main(String[] args) | ||
{ | ||
Person[] people = new Person[4]; | ||
people[0] = new Undergraduate("Cotty, Manny", 4910, 1); | ||
people[1] = new Faculty("Dent, Arthur", 6102, "Physics", "Distinguished Professor"); | ||
people[2] = new Student("DeBanque, Robin", 8812); | ||
people[3] = new Staff("Bugg, June", 9901, "Computer Science", 3); | ||
for (Person p : people) | ||
{ | ||
p.writeOutput(); | ||
System.out.println(); | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/me/alex4386/gachon/sw14462/day18/ex9_6/Staff.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package me.alex4386.gachon.sw14462.day18.ex9_6; | ||
|
||
public class Staff extends Employee { | ||
private int payGrade; | ||
|
||
public Staff(String name, int employeeID, String department, int payGrade) { | ||
super(name, employeeID, department); | ||
this.payGrade = payGrade; | ||
} | ||
|
||
public void setPayGrade(int newPayGrade) { | ||
payGrade = newPayGrade; | ||
} | ||
|
||
public int getPayGrade() { | ||
return payGrade; | ||
} | ||
|
||
public void writeOutput() { | ||
super.writeOutput(); | ||
System.out.println("Pay Grade: " + payGrade); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Staff - Name: " + getName() + ", Pay Grade: " + payGrade; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/me/alex4386/gachon/sw14462/day18/ex9_6/Student.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package me.alex4386.gachon.sw14462.day18.ex9_6; | ||
|
||
public class Student extends Person | ||
{ | ||
private int studentNumber; | ||
public Student() | ||
{ | ||
super(); | ||
studentNumber = 0;//Indicating no number yet | ||
} | ||
public Student(String initialName, int initialStudentNumber) | ||
{ | ||
super(initialName); | ||
studentNumber = initialStudentNumber; | ||
} | ||
public void reset(String newName, int newStudentNumber) | ||
{ | ||
setName(newName); | ||
studentNumber = newStudentNumber; | ||
} | ||
public int getStudentNumber() | ||
{ | ||
return studentNumber; | ||
} | ||
public void setStudentNumber(int newStudentNumber) | ||
{ | ||
studentNumber = newStudentNumber; | ||
} | ||
public void writeOutput() | ||
{ | ||
System.out.println("Name: " + getName()); | ||
System.out.println("Student Number: " + studentNumber); | ||
} | ||
public boolean equals(Student otherStudent) | ||
{ | ||
return this.hasSameName(otherStudent) && | ||
(this.studentNumber == otherStudent.studentNumber); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Student - Name: " + getName() + ", Student Number: " + studentNumber; | ||
} | ||
} | ||
|
||
|
44 changes: 44 additions & 0 deletions
44
src/main/java/me/alex4386/gachon/sw14462/day18/ex9_6/Undergraduate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package me.alex4386.gachon.sw14462.day18.ex9_6; | ||
|
||
public class Undergraduate extends Student | ||
{ | ||
private int level; //1 for freshman, 2 for sophomore //3 for junior, or 4 for senior. | ||
public Undergraduate() | ||
{ | ||
super(); | ||
level = 1; | ||
} | ||
public Undergraduate(String initialName, | ||
int initialStudentNumber, int initialLevel) | ||
{ | ||
super(initialName, initialStudentNumber); setLevel(initialLevel); //checks 1 <= initialLevel <= 4 | ||
} | ||
public void reset(String newName, int newStudentNumber, | ||
int newLevel) | ||
{ | ||
reset(newName, newStudentNumber); //Student's reset setLevel(newLevel); //Checks 1 <= newLevel <= 4 | ||
} | ||
public int getLevel() | ||
{ | ||
return level; | ||
} | ||
public void setLevel(int newLevel) | ||
{ | ||
if ((1 <= newLevel) && (newLevel <= 4)) | ||
level = newLevel; | ||
else | ||
{ | ||
System.out.println("Illegal level!"); | ||
System.exit(0); | ||
} } | ||
public void writeOutput() | ||
{ | ||
super.writeOutput(); | ||
System.out.println("StudentLevel: " + level); | ||
} | ||
public boolean equals(Undergraduate otherUndergraduate) | ||
{ | ||
return equals((Student)otherUndergraduate) && | ||
(this.level == otherUndergraduate.level); | ||
} | ||
} |