Skip to content

Commit

Permalink
chore: code
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex4386 committed May 3, 2024
1 parent c6ac27d commit a301966
Show file tree
Hide file tree
Showing 9 changed files with 252 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/me/alex4386/gachon/sw14462/day18/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import me.alex4386.gachon.sw14462.utils.Chainloader;

public class Main {
public static String chainloadTarget = "ex9_4";
public static String chainloadTarget = "ex9_6";

public static void main(String[] args) throws Throwable {
String packageName = Main.class.getPackage().getName();
Expand Down
43 changes: 43 additions & 0 deletions src/main/java/me/alex4386/gachon/sw14462/day18/ex9_6/Employee.java
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 src/main/java/me/alex4386/gachon/sw14462/day18/ex9_6/Faculty.java
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;
}
}
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 src/main/java/me/alex4386/gachon/sw14462/day18/ex9_6/Person.java
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);
}
}
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 src/main/java/me/alex4386/gachon/sw14462/day18/ex9_6/Staff.java
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 src/main/java/me/alex4386/gachon/sw14462/day18/ex9_6/Student.java
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;
}
}


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);
}
}

0 comments on commit a301966

Please sign in to comment.