-
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
31 changed files
with
760 additions
and
2 deletions.
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 |
---|---|---|
|
@@ -15,5 +15,4 @@ public static void main(String[] args) throws Throwable { | |
throw e; | ||
} | ||
} | ||
|
||
} |
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; | ||
|
||
import me.alex4386.gachon.sw14462.utils.Chainloader; | ||
|
||
public class Main { | ||
public static String chainloadTarget = "ex9_4"; | ||
|
||
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; | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/me/alex4386/gachon/sw14462/day18/ex9_2a/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.day18.ex9_2a; | ||
|
||
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_2a/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_2a; | ||
|
||
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_2a/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_2a; | ||
|
||
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 Undergraduate("Kick, Anita", 9931, 2); | ||
people[2] = new Student("DeBanque, Robin", 8812); | ||
people[3] = new Undergraduate("Bugg, June", 9901, 4); | ||
for (Person p : people) | ||
{ | ||
p.writeOutput(); | ||
System.out.println(); | ||
} | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/me/alex4386/gachon/sw14462/day18/ex9_2a/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,41 @@ | ||
package me.alex4386.gachon.sw14462.day18.ex9_2a; | ||
|
||
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); | ||
} | ||
} | ||
|
||
|
45 changes: 45 additions & 0 deletions
45
src/main/java/me/alex4386/gachon/sw14462/day18/ex9_2a/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,45 @@ | ||
package me.alex4386.gachon.sw14462.day18.ex9_2a; | ||
|
||
|
||
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); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/me/alex4386/gachon/sw14462/day18/ex9_2b/Circle.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,22 @@ | ||
package me.alex4386.gachon.sw14462.day18.ex9_2b; | ||
|
||
public class Circle extends Shape { | ||
private double radius; | ||
|
||
public Circle(double radius) { | ||
this.radius = radius; | ||
} | ||
|
||
@Override | ||
public double getArea() { | ||
return Math.PI * Math.pow(radius, 2); | ||
} | ||
|
||
public String toString() { | ||
return "Circle: radius=" + radius; | ||
} | ||
|
||
public boolean equals(Circle obj) { | ||
return this.radius == obj.radius; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/me/alex4386/gachon/sw14462/day18/ex9_2b/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,17 @@ | ||
package me.alex4386.gachon.sw14462.day18.ex9_2b; | ||
|
||
public class Main { | ||
public static void main(String[] args) { | ||
Shape[] shapes = new Shape[4]; | ||
shapes[0] = new Rectangle(10, 20); | ||
shapes[1] = new Circle(10); | ||
shapes[2] = new RightTriangle(10, 20); | ||
shapes[3] = new Shape(); | ||
|
||
for (Shape s : shapes) { | ||
System.out.println(s); | ||
System.out.println("Area: " + s.getArea()); | ||
System.out.println(); | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/me/alex4386/gachon/sw14462/day18/ex9_2b/Rectangle.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,25 @@ | ||
package me.alex4386.gachon.sw14462.day18.ex9_2b; | ||
|
||
public class Rectangle extends Shape { | ||
private double width; | ||
private double height; | ||
|
||
public Rectangle(double width, double height) { | ||
this.width = width; | ||
this.height = height; | ||
} | ||
|
||
@Override | ||
public double getArea() { | ||
return width * height; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Rectangle: width=" + width + ", height=" + height; | ||
} | ||
|
||
public boolean equals(Rectangle obj) { | ||
return this.width == obj.width && this.height == obj.height; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/me/alex4386/gachon/sw14462/day18/ex9_2b/RightTriangle.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,25 @@ | ||
package me.alex4386.gachon.sw14462.day18.ex9_2b; | ||
|
||
public class RightTriangle extends Shape { | ||
private double width; | ||
private double height; | ||
|
||
public RightTriangle(double width, double height) { | ||
this.width = width; | ||
this.height = height; | ||
} | ||
|
||
@Override | ||
public double getArea() { | ||
return width * height / 2; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "RightTriangle: width=" + width + ", height=" + height; | ||
} | ||
|
||
public boolean equals(RightTriangle obj) { | ||
return this.width == obj.width && this.height == obj.height; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/me/alex4386/gachon/sw14462/day18/ex9_2b/Shape.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.day18.ex9_2b; | ||
|
||
public class Shape { | ||
public double getArea() { | ||
return 0.0; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/me/alex4386/gachon/sw14462/day18/ex9_3/Billing.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_3; | ||
|
||
public class Billing { | ||
private Patient patient; | ||
private Doctor doctor; | ||
|
||
private int visitCount; | ||
|
||
public Billing(Patient patient, Doctor doctor) { | ||
this.patient = patient; | ||
this.doctor = doctor; | ||
|
||
this.visitCount = 0; | ||
} | ||
|
||
public Patient getPatient() { | ||
return this.patient; | ||
} | ||
|
||
public void setPatient(Patient patient) { | ||
this.patient = patient; | ||
} | ||
|
||
public Doctor getDoctor() { | ||
return this.doctor; | ||
} | ||
|
||
public void setDoctor(Doctor doctor) { | ||
this.doctor = doctor; | ||
} | ||
|
||
public void visit() { | ||
this.visitCount++; | ||
} | ||
|
||
public int getVisitCount() { | ||
return this.visitCount; | ||
} | ||
|
||
public double getIncome() { | ||
return this.visitCount * this.doctor.getVisitFee(); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
src/main/java/me/alex4386/gachon/sw14462/day18/ex9_3/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,54 @@ | ||
package me.alex4386.gachon.sw14462.day18.ex9_3; | ||
|
||
import me.alex4386.gachon.sw14462.day17.ex9_1b.Person; | ||
|
||
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/day18/ex9_3/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.day18.ex9_3; | ||
|
||
public enum DoctorSpeciality { | ||
MEDICINE, | ||
SURGERY, | ||
DENTIST, | ||
ORIENTAL; | ||
} |
Oops, something went wrong.