-
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
10 changed files
with
256 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
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,19 @@ | ||
package me.alex4386.gachon.sw14462.day17; | ||
|
||
import me.alex4386.gachon.sw14462.utils.Chainloader; | ||
|
||
public class Main { | ||
public static String chainloadTarget = "ex9_1b"; | ||
|
||
public static void main(String[] args) throws Throwable { | ||
String packageName = Main.class.getPackage().getName(); | ||
String chainLoadTargetClass = packageName + "." + chainloadTarget + ".Main"; | ||
|
||
try { | ||
Chainloader.chainloadTarget(chainLoadTargetClass, args); | ||
} catch (Exception e) { | ||
throw e; | ||
} | ||
} | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/me/alex4386/gachon/sw14462/day17/ex9_1a/InheritanceDemo.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,12 @@ | ||
package me.alex4386.gachon.sw14462.day17.ex9_1a; | ||
|
||
public class InheritanceDemo | ||
{ | ||
public static void main(String[] args) | ||
{ | ||
Student s = new Student(); | ||
s.setName("Warren Peace"); | ||
s.setStudentNumber(1234); | ||
s.writeOutput(); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/me/alex4386/gachon/sw14462/day17/ex9_1a/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,7 @@ | ||
package me.alex4386.gachon.sw14462.day17.ex9_1a; | ||
|
||
public class Main { | ||
public static void main(String[] args) { | ||
InheritanceDemo.main(args); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/me/alex4386/gachon/sw14462/day17/ex9_1a/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.day17.ex9_1a; | ||
|
||
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); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/main/java/me/alex4386/gachon/sw14462/day17/ex9_1a/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,42 @@ | ||
package me.alex4386.gachon.sw14462.day17.ex9_1a; | ||
|
||
|
||
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); | ||
} | ||
} | ||
|
||
|
52 changes: 52 additions & 0 deletions
52
src/main/java/me/alex4386/gachon/sw14462/day17/ex9_1b/Doctor.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,52 @@ | ||
package me.alex4386.gachon.sw14462.day17.ex9_1b; | ||
|
||
public class Doctor extends Person { | ||
private DoctorSpeciality speciality; | ||
private double visitFee = 0.0; | ||
|
||
public Doctor() { | ||
super(); | ||
this.speciality = null; | ||
this.visitFee = 0.0; | ||
} | ||
|
||
public Doctor(String initialName, DoctorSpeciality speciality, double visitFee) { | ||
super(initialName); | ||
this.speciality = speciality; | ||
this.visitFee = visitFee; | ||
} | ||
|
||
public void setSpeciality(DoctorSpeciality speciality) { | ||
if (speciality == null) { | ||
throw new IllegalArgumentException("Speciality cannot be null"); | ||
} | ||
|
||
this.speciality = speciality; | ||
} | ||
|
||
public DoctorSpeciality getSpeciality() { | ||
return this.speciality; | ||
} | ||
|
||
public void setVisitFee(double visitFee) { | ||
if (visitFee < 0) { | ||
throw new IllegalArgumentException("Visit Fee cannot be negative"); | ||
} | ||
|
||
this.visitFee = visitFee; | ||
} | ||
|
||
public double getVisitFee() { | ||
return this.visitFee; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Doctor: " + this.getName() + ", Speciality: " + this.getSpeciality() + ", Visit Fee: " + this.getVisitFee(); | ||
} | ||
|
||
public boolean equals(Doctor otherDoctor) { | ||
return this.hasSameName(otherDoctor) && this.getSpeciality() == otherDoctor.getSpeciality() && this.getVisitFee() == otherDoctor.getVisitFee(); | ||
} | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/me/alex4386/gachon/sw14462/day17/ex9_1b/DoctorSpeciality.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,8 @@ | ||
package me.alex4386.gachon.sw14462.day17.ex9_1b; | ||
|
||
public enum DoctorSpeciality { | ||
MEDICINE, | ||
SURGERY, | ||
DENTIST, | ||
ORIENTAL; | ||
} |
45 changes: 45 additions & 0 deletions
45
src/main/java/me/alex4386/gachon/sw14462/day17/ex9_1b/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,45 @@ | ||
package me.alex4386.gachon.sw14462.day17.ex9_1b; | ||
|
||
public class Main { | ||
public static void main(String[] args) { | ||
System.out.println("=== Doctor 1 ==="); | ||
Doctor d1 = new Doctor(); | ||
d1.setName("Dr. John Doe"); | ||
d1.setSpeciality(DoctorSpeciality.MEDICINE); | ||
d1.setVisitFee(10000); | ||
System.out.println(d1); | ||
|
||
System.out.println("=== Doctor 2 ==="); | ||
Doctor d2 = new Doctor(); | ||
d2.setName("Dr. Jane Smith"); | ||
d2.setSpeciality(DoctorSpeciality.SURGERY); | ||
d2.setVisitFee(15000); | ||
System.out.println(d2); | ||
|
||
System.out.println("=== Doctor 3 ==="); | ||
Doctor d3 = new Doctor(); | ||
d3.setName("Dr. John Doe"); | ||
d3.setSpeciality(DoctorSpeciality.MEDICINE); | ||
d3.setVisitFee(10000); | ||
System.out.println(d3); | ||
|
||
|
||
System.out.println("=== Compare Doctor 1 & Doctor 2 ==="); | ||
System.out.println("Expected Result: Different"); | ||
if (d1.equals(d2)) { | ||
System.out.println("Doctor 1 and Doctor 2 are the same."); | ||
} else { | ||
System.out.println("Doctor 1 and Doctor 2 are different."); | ||
} | ||
|
||
System.out.println("=== Compare Doctor 1 & Doctor 3 ==="); | ||
System.out.println("Expected Result: Same"); | ||
if (d1.equals(d3)) { | ||
System.out.println("Doctor 1 and Doctor 3 are the same."); | ||
} else { | ||
System.out.println("Doctor 1 and Doctor 3 are different."); | ||
} | ||
|
||
|
||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/me/alex4386/gachon/sw14462/day17/ex9_1b/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.day17.ex9_1b; | ||
|
||
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); | ||
} | ||
} |