Question: Create a class Student and another class Instructor. [ Details are unimportant at this stage, and yes, this will be very poor O - O

Create a class Student and another class Instructor. [Details are unimportant at this stage, and yes, this will be very poor O-O design!]. Let each class have a single instance variable name that contains a full name. Class Student is shown at right. [Remember to use Eclipse "source" shortcuts to create these classes very quickly!]
Suppose we want to require a behavior that displays a "role" as part of the name. For example:
Student
-name:String //full name
+Student(String n)
+getName(): String
toString():String
Stephen Weissman, instructor
Susan Holly, student
Create an interface RoleDisplayable to require a void method displayNameAndRole()
a. Code a default method for displayNameAndRole() that makes all Student instances display the name with ", Student" after the name.
b. Important: if it's not a Student, let's make the default method do nothing. [Maybe not great design, but it will make this lab more interesting!] How will you do this??
c. Also important: if you try to invoke getName() from your default method, you'll get a compile error! [Remember static and dynamic types? getName() is in the dynamic type Student!] To solve this problem, we'll need to add a cast before the dot and method call something like this: ((Student) this)
Make class Student implement RoleDisplayable.
Write a test driver (in main()) that
a. builds an ArrayList of
 Create a class Student and another class Instructor. [Details are unimportant

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!