011-001-009

Constructor: Bank Account Initialization

Hard

Problem Description

constructor: Bank Account Initialization

In this problem, you will create a program that reads bank account information (account number, owner name, and balance) from standard input using Scanner, initializes a BankAccount object using a constructor, and displays the result.

Learning Objective: Understand object initialization using constructors

Overview

Create a BankAccount class representing a bank account. Using a constructor allows setting initial values when creating an instance, producing consistent objects.

Specifications

BankAccount class

  • Fields:
    • String accountNumber (account number)
    • String ownerName (owner name)
    • int balance (balance)
  • Constructor: BankAccount(String accountNumber, String ownerName, int balance)
    • Assign received arguments to fields
  • method: void displayInfo()
    • Display in format "Account: [accountNumber], Owner: [ownerName], Balance: [balance]"

Main Class

  • Read the following from standard input using Scanner
    • Line 1: account number (String)
    • Line 2: owner name (String)
    • Line 3: balance (int)
  • Create BankAccount instance using constructor
  • Call displayInfo() method

Input Format

accountNumber
ownerName
balance

Output Format

Account: [accountNumber], Owner: [ownerName], Balance: [balance]

Sample I/O

Input:
123-456
Alice
10000

Output:
Account: 123-456, Owner: Alice, Balance: 10000

Ready to Try Running Code?

Log in to access the code editor and execute your solutions for this problem.

Don't have an account?

Sign Up