016-003-003

Polymorphism with Abstract Class: Payment Processing

Medium

Problem Description

polymorphism with abstract class: Payment Processing

In this problem, you will create a program that implements CashPayment and CardPayment classes extending an abstract Payment class, calculates fees based on the payment method, and displays the total amount to standard output.

Learning Objective: Implement polymorphism using abstract class

Implement payment system that performs different processing based on payment method.

Input

Line 1: Payment method (cash or card)
Line 2: Amount

Output

Payment method: [method]
Amount: [amount]
Fee: [fee]
Total: [total]

Example

Input:

card
1000

Output:

Payment method: Card
Amount: 1000
Fee: 30
Total: 1030

Test Cases

※ Output examples follow programming industry standards

Input:
card
1000
Expected Output:
Payment method: Card
Amount: 1000
Fee: 30
Total: 1030
Input:
cash
500
Expected Output:
Payment method: Cash
Amount: 500
Fee: 0
Total: 500
Input:
c
0
Expected Output:
Payment method: Card
Amount: 0
Fee: 30
Total: 30
Input:
card
-1
Expected Output:
Payment method: Card
Amount: -1
Fee: 30
Total: 29
❌ Some tests failed
❌ エラー発生

Your Solution

Current Mode: My Code
Payment.java🔒
CashPayment.java🔒
CardPayment.java🔒
Main.java🔒
4/6 ファイル229B
⚠️警告
  • No main method found
import java.util.Scanner;

abstract class Payment {
}
0 B / 5 MB

You have 6 free executions remaining