013-004-005
Library Wrapper: Time Formatter
Hard
Problem Description
Library Wrapper: Time Formatter
In this problem, you will create a program that implements a TimeFormatter class wrapping SimpleDateFormat, reads two date strings from standard input, and displays the formatted results to standard output.
Learning Objective: Understand how to wrap external libraries to provide easier interfaces
Overview
Create a class that wraps Java's SimpleDateFormat class to make date/time formatting easier to use. A wrapper class hides complex library usage and provides only necessary functionality.
Specifications
Create a TimeFormatter class:
- constructor accepts date/time format pattern
format(Date date)method converts Date to formatted stringparse(String dateStr)method converts string to Date- Uses
SimpleDateFormatinternally
In Main class:
- Read 2 lines from standard input using Scanner
- Line 1: date string to output as "Current Time"
- Line 2: date string to parse and output as "Parsed Time"
- Initialize TimeFormatter with pattern "yyyy-MM-dd HH:mm:ss"
- Parse line 1, format it and print prefixed with "Current Time: "
- Parse line 2, format it and print prefixed with "Parsed Time: "
Input Format
<date string 1 (yyyy-MM-dd HH:mm:ss format)>
<date string 2 (yyyy-MM-dd HH:mm:ss format)>
Output Format
Current Time: <line 1 formatted>
Parsed Time: <line 2 formatted>
Sample Input/Output
Input:
2025-12-30 14:25:00
2025-12-30 14:30:00
Output:
Current Time: 2025-12-30 14:25:00
Parsed Time: 2025-12-30 14:30:00
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