Skip to content

Commit

Permalink
chore: add day17 practice
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex4386 committed Apr 29, 2024
1 parent b353eb8 commit a0b91fd
Show file tree
Hide file tree
Showing 10 changed files with 256 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/me/alex4386/gachon/sw14462/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.util.*;

public class Main {
public static String currentTarget = "day14";
public static String currentTarget = "day17";
public static boolean fallbackToLatest = true;

public static Map<String, Class<?>> getAvailableTargetClassNames() {
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/me/alex4386/gachon/sw14462/day17/Main.java
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;
}
}

}
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();
}
}
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 src/main/java/me/alex4386/gachon/sw14462/day17/ex9_1a/Person.java
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 src/main/java/me/alex4386/gachon/sw14462/day17/ex9_1a/Student.java
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 src/main/java/me/alex4386/gachon/sw14462/day17/ex9_1b/Doctor.java
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();
}

}
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 src/main/java/me/alex4386/gachon/sw14462/day17/ex9_1b/Main.java
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 src/main/java/me/alex4386/gachon/sw14462/day17/ex9_1b/Person.java
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);
}
}

0 comments on commit a0b91fd

Please sign in to comment.