019-007-001

Transaction and Rollback: Point Operation Management

Easy

Problem Description

Transaction and Rollback: Point Operation Management

In this problem, you will create a program that manages point card operations (usage and addition) as a transaction using exception handling and a finally clause, rolls back to the initial state when an error occurs during processing, and displays the final result to standard output.

Learning Objective: Learn to understand transaction and rollback concepts using exception handling

Create a program to safely execute a series of point card operations. Execute multiple operations (point usage and addition), and rollback to the pre-operation state if an error occurs. Using a finally clause, always display the final state. This mechanism ensures operation atomicity (all succeed or all fail).

Input

Line 1: Initial points
Line 2: Usage points
Line 3: Addition points

Output

Normal case:

=== Transaction Manager ===
Initial: [initial]pt
Operation 1: Use [usage]pt
Operation 2: Add [addition]pt
━━━━━━━━━━━━━━━━
Transaction: Committed
Final Balance: [final balance]pt
```java

Rollback case:
```java
=== Transaction Manager ===
Initial: [initial]pt
Operation 1: Use [usage]pt
Operation Failed!
━━━━━━━━━━━━━━━━
Transaction: Rolled back
Final Balance: [initial]pt
Error: [error message]

Test Cases

※ Output examples follow programming industry standards

Normal case
Input:
1000
300
500
Expected Output:
=== Transaction Manager ===
Initial: 1000pt
Operation 1: Use 300pt
Operation 2: Add 500pt
━━━━━━━━━━━━━━━━
Transaction: Committed
Final Balance: 1200pt
Normal case
Input:
500
1000
500
Expected Output:
=== Transaction Manager ===
Initial: 500pt
Operation 1: Use 1000pt
Operation Failed!
━━━━━━━━━━━━━━━━
Transaction: Rolled back
Final Balance: 500pt
Error: Insufficient balance

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