Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 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
StudentString
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
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started