|
@@ -163,4 +163,56 @@ class DemoBankAccount { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
class Student extends Person { |
|
|
|
|
|
private double gpa; |
|
|
|
|
|
|
|
|
|
|
|
public double getGpa() { |
|
|
|
|
|
return gpa; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void setGpa(double gpa) { |
|
|
|
|
|
this.gpa = gpa; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public String toString() { |
|
|
|
|
|
return "Student [gpa=" + gpa + ", name=" + this.getName() + "]"; |
|
|
|
|
|
// Ah, we can't access private members of parent classes from the child class |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
class Lecturer extends Person { |
|
|
|
|
|
private double salary; |
|
|
|
|
|
|
|
|
|
|
|
public double getSalary() { |
|
|
|
|
|
return salary; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void setSalary(double salary) { |
|
|
|
|
|
this.salary = salary; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public String toString() { |
|
|
|
|
|
return "Lecturer [salary=" + salary + ", name=" + this.getName() + "]"; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Exercise 3.1, 3.2, 3.3 - implement Student and Lcturer classes |
|
|
|
|
|
* |
|
|
|
|
|
*/ |
|
|
|
|
|
class DemoStudentLecturer { |
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
|
|
Student adrian = new Student(); |
|
|
|
|
|
adrian.setName("Adrian"); |
|
|
|
|
|
adrian.setGpa(3.5); |
|
|
|
|
|
|
|
|
|
|
|
Lecturer trefusis = new Lecturer(); |
|
|
|
|
|
trefusis.setName("Donald"); |
|
|
|
|
|
trefusis.setSalary(24199); |
|
|
|
|
|
|
|
|
|
|
|
System.out.println(String.format("At a particular Oxbridge college, we have two people")); |
|
|
|
|
|
System.out.println(String.format("%s\t\t&\t\t%s", adrian, trefusis)); |
|
|
|
|
|
} |
|
|
|
|
|
} |