diff --git a/src/org/gh/RunMe.java b/src/org/gh/RunMe.java index cb08158..5091e61 100644 --- a/src/org/gh/RunMe.java +++ b/src/org/gh/RunMe.java @@ -12,6 +12,7 @@ public static void main(String args[]){ System.out.println("Creating a new student and Teacher"); Student objStudent = new Student("Student 1", "GradeA"); Teacher objTeacher = new Teacher("Teacher 1", "Class#1, Class#2"); + Advisor objAdvisor = new Advisor("Folder 1"); // Print details of a student we created above (name - grade) @@ -22,18 +23,25 @@ public static void main(String args[]){ // Print details of a Teacher we created above (name - classes) System.out.println("Print with name (from person) and Classes (from Teacher)"); System.out.println(objTeacher.getName() + " - " + objTeacher.getClasses()); + // Print details of a Teacher we created above (name - classes) + System.out.println("Print with name (from person) and Classes (from Advisor)"); + System.out.println(objAdvisor.getName() + " - " + objAdvisor.getFolder()); // This uses the polymorphism to call printMe and see different results System.out.println("Print the Student and teacher using the printMe method from Printable"); System.out.println(objStudent.printMe()); System.out.println(objTeacher.printMe()); + System.out.println(objAdvisor.printMe()); + // Use the toString method of Student (not overriden from the Parent definition) System.out.println("Use the toString method in person since it's not overridden in the subclasses"); System.out.println(objStudent); System.out.println(objTeacher); + System.out.println(objAdvisor); + // Create a new object and print it diff --git a/src/org/gh/Teacher.java b/src/org/gh/Teacher.java index 4aaa97f..f3b00cd 100644 --- a/src/org/gh/Teacher.java +++ b/src/org/gh/Teacher.java @@ -2,34 +2,34 @@ package org.gh; // extends Parent means we inherit from Parent -// This gives Teacher the ability to use Parent methods and attributes +// This gives Advisor the ability to use Parent methods and attributes // implements Printable means we must override the methods in that interface -public class Teacher extends Person implements Printable{ +public class Advisor extends Person implements Printable{ - // attribute to store teacher's class - private String classes; + // attribute to store advisor's class + private String folder; // Constructor of tacher taking a name and class as input - public Teacher(String name, String classes){ + public Adivsor(String name, String folder){ // Call superclass constructor (in this case Person) super (name); - // Set the class for this teacher - this.setClasses(classes); + // Set the class for this advisor + this.setFolder(folder); } // get Class - public String getClasses(){ - return this.classes; + public String getFolder(){ + return this.folder; } // Set class - public void setClasses(String classes){ - this.classes = classes; + public void setFolder(String folder){ + this.folder = folder; } // Because this class implements Printable, I must override the printMe() method public String printMe(){ - return "Teacher details from printMe() = " + this.getName()+ " - "+this.getClasses(); + return "Advisor details from printMe() = " + this.getName()+ " - "+this.getFolder(); } }