016-002-008
Template Method with Abstract Class
Hard
Problem Description
Template method with abstract class
In this problem, you will create a program that defines a template method generate() and abstract methods in the Report abstract class, implements the specific processing in the subclass SalesReport, and displays the result to standard output.
Learning Objective: Understand the Template Method Pattern where a concrete method in an abstract class calls abstract methods
Overview
Create a Report abstract class with a concrete method generate() that defines the processing flow, and abstract methods for each step. SalesReport class implements the specific processing.
Specifications
- Define in
Reportabstract class:abstract String getTitle(): returns the report titleabstract String getContent(): returns the report body- Concrete method
generate(): combines title and content for output
generate()outputs in this format:=== <title> ===(line 1)<content>(line 2)=== End ===(line 3)
SalesReportreturnsSales ReportfromgetTitle()andTotal: 1500fromgetContent()
Output Format
=== Sales Report ===
Total: 1500
=== End ===
Ready to Try Running Code?
Log in to access the code editor and execute your solutions for this problem.
Don't have an account?
Sign Up