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

  1. Define in Report abstract class:
    • abstract String getTitle(): returns the report title
    • abstract String getContent(): returns the report body
    • Concrete method generate(): combines title and content for output
  2. generate() outputs in this format:
    • === <title> === (line 1)
    • <content> (line 2)
    • === End === (line 3)
  3. SalesReport returns Sales Report from getTitle() and Total: 1500 from getContent()

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