015-005-007
Type-specific Processing Method with instanceof
Hard
Problem Description
Type-specific Processing method with instanceof
In this problem, you will create a program that uses the instanceof operator to identify the actual type of a Payment object (CashPayment, CardPayment, or PointPayment), performs different processing for each subtype in a single process(Payment) method, and displays the result to standard output.
Learning Objective: Design a method that performs different processing based on object type using instanceof
Overview
Create a method that receives parent class type as parameter and performs different processing based on actual type.
Specifications
- Define Payment class and its subclasses (CashPayment, CardPayment, PointPayment)
- Implement process(Payment) method in PaymentProcessor class
- Read payment information from standard input, process according to payment method, and output result
Input Format
cash amount (integer)
card amount (integer) card number (16-digit string)
point amount (integer)
Input Example
1000
2500 1234567890123456
500
Output Format
Processing cash payment: 1000 yen
Processing card payment: 2500 yen (Card: 1234-****)
Processing point payment: 500 points
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