011-003-001

Constructor Chain: Account Initialization

Easy

Problem Description

constructor Chain: Account Initialization

In this problem, you will create a program that reads a username, initializes an account's balance to a default value (0 yen) using constructor chaining with this(), and displays the result to standard output.

Learning Objective: Call another constructor with this()

Define an Account class with two fields: username (String) and balance (int). Implement a full-parameter constructor and a single-parameter constructor that sets the default balance to 0. Use this(username, 0) inside the single-parameter constructor to chain them together.

Input

Line 1: Username (string)

Output

Username: [username]
Balance: 0 yen

Test Cases

※ Output examples follow programming industry standards

Normal case
Input:
Taro
Expected Output:
Username: Taro
Balance: 0 yen
Normal case
Input:
Hanako
Expected Output:
Username: Hanako
Balance: 0 yen

Your Solution

Current Mode: My Code
Account.java🔒
Solution.java🔒
2/6 ファイル96B
⚠️警告
  • No main method found
import java.util.Scanner;

class Account {
}
0 B / 5 MB

You have 10 free executions remaining