Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. [50] (On your way to become an employee) Consider the following UML Diagram: Employee fullName: String - age: int departmentName: String - supervisor: Employee

image text in transcribed
1. [50] (On your way to become an employee) Consider the following UML Diagram: Employee fullName: String - age: int departmentName: String - supervisor: Employee | null > Comparable // constructor // getters and setters + toString( + compute Salary(): double RegularEmployee HourlyEmployee - baseSalary: double - conveyances: double avgWorkingHour: double - deduction: double hourlySalary: double // constructor // constructor / getters and setters / getters and setters Employee is an abstract class. It has two abstract methods: toString ( ) and computeSalary ( ). It also implements the built-in Comparable interface. Two employees are compared in terms of their annual salary. For regular employee, annual salary = (base salary + conveyances - deduction) * 12. For hourly employee, annual salary = hourly salary * average working hour * 5 * 52 computeSalary( ) method calculates and returns the annual salary for the particular employee. Create a driver class after implementation of the class hierarchy and demonstrate that all functionalities work as intended by creating at least 4 total objects of RegularEmployee and HourlyEmployee classes combined. 2. [50] (Poly-wrath) Consider the following text that describes the specifications of a class: (Geometry: n-sided regular polygon) In an n-sided regular polygon, all sides have the same length and all angles have the same degree (i.e., the polygon is both equilateral and equiangular). Design a class named RegularPolygon that contains: A private int data field named n that defines the number of sides in the poly- gon with default value 3. A private double data field named side that stores the length of the side with default value 1. A private double data field named x that defines the x-coordinate of the poly- gon's center with default value 0. A private double data field named y that defines the y-coordinate of the poly- gon's center with default value 0. A no-arg constructor that creates a regular polygon with default values. A constructor that creates a regular polygon with the specified number of sides and length of side, centered at (0, 0). A constructor that creates a regular polygon with the specified number of sides, length of side, and x- and y-coordinates. The accessor and mutator methods for all data fields. The method getPerimeter () that returns the perimeter of the polygon. The method getArea () that returns the area of the polygon. The formula for computing the area of a regular polygon is Area = n X $2 4 X tan Make the RegularPolygon class abstract. Include an additional method toString () , which will be abstract. getPerimeter() and getArea( ) methods are also abstract methods. Create three child classes Pentagon, Hexagon and Heptagon of the RegularPolygon class. The only thing that changes in these classes is the number of sides. Override the toString ( ) methods accordingly, printing out the name of the class, number of sides, their area and perimeter. Implement the Comparable interface in the RegularPolygon class. Make sure that the compareTo() method only compares similar type of objects (e.g. Hexagon with Hexagon but not Hexagon with Heptagon) based on the perimeter of the objects. Create a driver class to test out all the methods. Create six objects, each having reference type RegularPolygon but object types are to be Pentagon, Hexagon and Heptagon. Invoke the tostring() and compareTo() methods and verify the results

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intermediate Microeconomics and Its Application

Authors: walter nicholson, christopher snyder

11th edition

9781111784300, 324599102, 1111784302, 978-0324599107

More Books

Students also viewed these Economics questions

Question

Define and apply the concept of authority

Answered: 1 week ago