019-004-001

Exception Propagation: Point Usage Validation System

Easy

Problem Description

Exception Propagation: Point Usage Validation System

In this problem, you will create a program that reads balance points and usage points from standard input, throws IllegalArgumentException in validatePointUsage() when usage exceeds balance, propagates the exception through usePoints() to main(), and displays the result to standard output.

Learning Objective: Learn to understand how exceptions propagate through method calls

Create a point card usage validation system. When usage points exceed balance points, throw IllegalArgumentException in the validatePointUsage() method, and observe how the exception propagates through the usePoints() method up to the main() method. Without explicitly catching the exception in each intermediate method, it automatically propagates to the caller.

Input

Line 1: Balance points
Line 2: Usage points

Output

=== Point Usage Validation ===
Balance: [balance]pt
Usage: [usage]pt
Validation: Success
━━━━━━━━━━━━━━━━
Status: Points used successfully

Or when exception occurs:

=== Point Usage Validation ===
Balance: [balance]pt
Usage: [usage]pt
Validation: Failed
━━━━━━━━━━━━━━━━
Error: Usage exceeds balance (required: [usage], available: [balance])

Examples

Example 1: Normal Point Usage (500/1000)

Input:

1000
500

Output:

=== Point Usage Validation ===
Balance: 1000pt
Usage: 500pt
Validation: Success
━━━━━━━━━━━━━━━━
Status: Points used successfully

Example 2: Balance Exceeded Error (1000/500)

Input:

500
1000

Output:

=== Point Usage Validation ===
Balance: 500pt
Usage: 1000pt
Validation: Failed
━━━━━━━━━━━━━━━━
Error: Usage exceeds balance (required: 1000, available: 500)

Example 3: Boundary Value (1000/1000)

Input:

1000
1000

Output:

=== Point Usage Validation ===
Balance: 1000pt
Usage: 1000pt
Validation: Success
━━━━━━━━━━━━━━━━
Status: Points used successfully

Test Cases

※ Output examples follow programming industry standards

Normal case
Input:
1000
500
Expected Output:
=== Point Usage Validation ===
Balance: 1000pt
Usage: 500pt
Validation: Success
━━━━━━━━━━━━━━━━
Status: Points used successfully
Error case
Input:
500
1000
Expected Output:
=== Point Usage Validation ===
Balance: 500pt
Usage: 1000pt
Validation: Failed
━━━━━━━━━━━━━━━━
Error: Usage exceeds balance (required: 1000, available: 500)
Boundary case
Input:
1000
1000
Expected Output:
=== Point Usage Validation ===
Balance: 1000pt
Usage: 1000pt
Validation: Success
━━━━━━━━━━━━━━━━
Status: Points used successfully
Error case
Input:
0
100
Expected Output:
=== Point Usage Validation ===
Balance: 0pt
Usage: 100pt
Validation: Failed
━━━━━━━━━━━━━━━━
Error: Usage exceeds balance (required: 100, available: 0)

Your Solution

Current Mode: My Code
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// Write your code here

sc.close();
}
}
0 B / 5 MB

You have 10 free executions remaining