Resource Management: Point Card Information Reading
Problem Description
Resource Management: Point Card Information Reading
Learning Objective: Learn to safely manage resources using try-with-resources statement
In this problem, you will create a program that uses try-with-resources statement (try (Scanner sc = new Scanner(System.in)) {...}) to automatically close a Scanner, reads point card information (card ID, owner name, and points) from standard input, and displays the result in a specified format to standard output.
By instantiating the Scanner inside the try-with-resources declaration (inside the parentheses), Java automatically calls close() when exiting the try block. This prevents resource leaks and eliminates the need to manually write close processing in a finally block.
Example 1: Standard Card Information (ID: 12345, Owner: Tanaka, Points: 1000)
Read 3 lines of data from standard input. With try-with-resources statement, Scanner is automatically closed when exiting try block.
Input:
12345
Tanaka
1000
Output:
=== Point Card Reader ===
Card ID: 12345
Owner: Tanaka
Points: 1000pt
━━━━━━━━━━━━━━━━
Resource: Closed automatically
Status: Reading completed
```java
### Example 2: Another Card Information (ID: 67890, Owner: Suzuki, Points: 2500)
Similarly read 3 lines of data, Scanner is automatically closed. Programmer does not need to explicitly write resource close processing.
```java
Input:
67890
Suzuki
2500
Output:
=== Point Card Reader ===
Card ID: 67890
Owner: Suzuki
Points: 2500pt
━━━━━━━━━━━━━━━━
Resource: Closed automatically
Status: Reading completed
```java
### Example 3: Boundary Values (ID: 1, Owner: A, Points: 0)
Works correctly even with minimum card ID and 0 points boundary values. Try-with-resources statement safely manages resources with any values.
```java
Input:
1
A
0
Output:
=== Point Card Reader ===
Card ID: 1
Owner: A
Points: 0pt
━━━━━━━━━━━━━━━━
Resource: Closed automatically
Status: Reading completed
```java
## Input
Card information from standard input:
Line 1: Card ID (integer)
Line 2: Owner name
Line 3: Point balance (integer)
## Output
```java
=== Point Card Reader ===
Card ID: [ID]
Owner: [name]
Points: [points]pt
━━━━━━━━━━━━━━━━
Resource: Closed automatically
Status: Reading completed
Test Cases
※ Output examples follow programming industry standards
54321 Sato 3000
=== Point Card Reader === Card ID: 54321 Owner: Sato Points: 3000pt ━━━━━━━━━━━━━━━━ Resource: Closed automatically Status: Reading completed
11111 Kobayashi 750
=== Point Card Reader === Card ID: 11111 Owner: Kobayashi Points: 750pt ━━━━━━━━━━━━━━━━ Resource: Closed automatically Status: Reading completed
Your Solution
You have 10 free executions remaining
