Answered step by step
Verified Expert Solution
Question
1 Approved Answer
in java Step 1 : Person 1 . Write a class called Person ( this class cannot be instantiated ) . Now add the following
in java
Step : Person
Write a class called Person this class cannot be instantiated Now add the following fields and mark them private:
firstName, lastName String
age int
Add a constructor that takes the first and last name and age as parameters and initializes the fields above.
Add an abstract method, goAboutDay, that takes no parameters and returns nothing void
Add a toString that renders the Person like so:
Person: firstNamelastName age: age
Step : ISalaried
Create an interface, ISalaried, that exports a single abstract method: getSalary with a return type of double.
Step : Student
Now write a Student class this class can be able to be instantiated Make the class extend Person.
Add a constructor that takes the same parameters as Person and super them up via a super call in the constructor.
Override the goAboutDay method and make it print: "studying, class, beer, bed"
Step : GraduateStudent
Create a class GraduateStudent that can be instantiated. Make the class extend Student.
Make the constructor accept a first name, last name, an age, and a list of courses of type List store the courses into a field and super up the rest to the student class constructor.
Now make this class implement ISalaried.
when you go implement the getSalary method required by the interface, the implementation for should return $ if they are teaching or more courses, $ otherwise.
Override the goAboutDay method and have it print: "bed, writing, reading, teaching, class"
Step : Instructor
Create an instructor class that extends Person and implements Salaried. This class should be able to be instantiated.
Add two private fields:
yearlySalary type: double
activeCourses type: List
Add a constructor that matches the superclass constructor and adds parameters for the yearlySalary and List containing the courses being actively taught by the instructor. Initialize the two fields above using these parameters.
Override the getSalary method. If the activeCourses list is empty, make the method return $; otherwise make it return yearlySalary.
Override the goAboutDay method and make it print: "teaching, grading, tv bed"
Step : Tester
Create a Tester class with a main method. Instantiate a GraduateStudent and an Instructor make the declared type for these variables ISalaried Print out each variables salary by calling the getSalary method.
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