001-004-007

Variable Value Update: Point Update

Easy

Problem Description

Variable Value Update: Point Update

Learning Objective: Understand how to change variable values later

Create a point card app. Input your initial points and add points from two shopping trips. Display points after each shopping trip.

Input

Line 1: Initial points (integer, pt)
Line 2: Points earned from first shopping trip (integer, pt)
Line 3: Points earned from second shopping trip (integer, pt)

Output

================================
     Point Update Card
================================
Initial Points: [initial points]pt
After 1st Shopping: [updated points]pt
After 2nd Shopping: [final points]pt
================================
```java

## Examples

### Example 1: 100pt plus 50pt and 30pt
Input:
```java
100
50
30
```java
Output:
```java
================================
     Point Update Card
================================
Initial Points: 100pt
After 1st Shopping: 150pt
After 2nd Shopping: 180pt
================================

Test Cases

※ Output examples follow programming industry standards

Input:
100
50
30
Expected Output:
================================
  Point Update Card
================================
Initial Points: 100pt
After 1st Shopping: 150pt
After 2nd Shopping: 180pt
================================
Input:
0
100
200
Expected Output:
================================
  Point Update Card
================================
Initial Points: 0pt
After 1st Shopping: 100pt
After 2nd Shopping: 300pt
================================
Input:
500
0
0
Expected Output:
================================
  Point Update Card
================================
Initial Points: 500pt
After 1st Shopping: 500pt
After 2nd Shopping: 500pt
================================
❌ Some tests failed
❌ エラー発生

Your Solution

Current Mode: My Code
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
// キーボードからのユーザー入力を読むためのScannerオブジェクトを準備
Scanner sc = new Scanner(System.in);
// ユーザーから初期ポイント値を受け取る
int points = sc.nextInt();
// 比較用に初期ポイントを記録(表示用)
int initialPoints = points;
// 最初の買い物から獲得ポイントを受け取る
int earned1 = sc.nextInt();
// 新しい計算でポイント値を更新する(重要: 同じ変数に新しい値を代入)
points = points + earned1;
// 最初の買い物後のポイントを記録
int afterFirst = points;
// 2番目の買い物から獲得ポイントを受け取る
int earned2 = sc.nextInt();
// 1. 計算結果で再度ポイント値を更新
points = points + earned2;
// 2. 現在の状態でポイント更新カードを表示
System.out.println("================================");
// [出力処理] 結果を画面に表示
System.out.println(" Point Update Card");
// [出力処理] 結果を画面に表示
System.out.println("================================");
// [出力処理] 結果を画面に表示
System.out.println("Initial Points: " + initialPoints + "pt");
// [出力処理] 結果を画面に表示
System.out.println("After 1st Shopping: " + afterFirst + "pt");
// [出力処理] 結果を画面に表示
System.out.println("After 2nd Shopping: " + points + "pt");
// [出力処理] 結果を画面に表示
System.out.println("================================");
}
}

0 B / 5 MB

You have 10 free executions remaining