Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/org/gh/RunMe.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
24 changes: 12 additions & 12 deletions src/org/gh/Teacher.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you rename "Teacher" class to "Advisor" you'll need to also update the file name from Teacher.java to Advisor.java. That's at least the first error.

// 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();
}
}