008-001-013

Method Definition: Using Fields

Medium

Problem Description

Method Definition: Using Fields

In this problem, you will create a program that defines methods to manipulate the balance field of a BankAccount class, handling deposits and balance retrieval.

Learning Objective: Understand how to use fields within methods

Overview

Create methods that perform calculations using field values.

Specifications

  • Create a BankAccount class
  • int field balance (account balance)
  • constructor sets initial balance
  • deposit(int amount) adds to balance
  • getBalance() returns current balance

Input Format

initial balance (integer)
deposit amount (integer)

Output Format

balance after deposit

Input/Output Examples

Input:
1000
500

Output:
1500
Input:
0
200

Output:
200

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