Sale!

63 Consider the Employee class hierarchy from the beginning of Chapter 6 Use the Template Method

(4 customer reviews)

Original price was: $10.00.Current price is: $5.00.

Download button will appear immediately after successful payment.

Full support will be provided with necessary files installation.

Get impeccable customized solution within 24 hours, hassle-free.

Description

6.3 Consider the Employee class hierarchy from the beginning of Chapter 6. Use the Template Method design pattern to implement a Template Method for the Employee class: String toJson() {} that generates a JSON string with the employee’s name, base salary (the salary field), and the total salary (as returned by getSalary()).

Example:

Employee sarah = new Employee(“Sarah”);

sarah.setSalary(50000);

Manager sandy = new Manager(“Sandy”);

sandy.setSalary(100000);

sandy.setBonus(1234);

System.out.println(sarah.toJson()); // prints {“class”:”Employee”, “name”:”Sarah”, “salary”: 50000}

System.out.println(sandy.toJson()); // prints {“class”: “Manager”, “name”: “Sandy”, “salary”: 101234, “bonus”:1234}

a) Describe the mappings (table) from the pattern context to the Employee problem domain.

b) Show the UML class diagram. The diagram needs to describe the relationship between the base class Employee and subclass Manager. Include attributes and methods involved in implementing the method toJson().

c) Write the Java code for classes Employee and Manager. Include a main() method in class Manager where you illustrate how toJson() is used for objects of both classes.

You may also like…

Billing details

Additional information

Your order

Product
Quantity
Total
Cart Subtotal $0.00
Order Total $0.00