0% found this document useful (0 votes)
24 views2 pages

Assignment 1

The document outlines an assignment to create a Java class named `BankAccount` with attributes for account number, balance, and customer name. It includes methods for depositing, withdrawing, and retrieving account information, as well as functionality for calculating interest. The assignment also requires testing the class with multiple account instances and ensuring proper handling of insufficient funds during withdrawals.

Uploaded by

sosinaanteneh844
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views2 pages

Assignment 1

The document outlines an assignment to create a Java class named `BankAccount` with attributes for account number, balance, and customer name. It includes methods for depositing, withdrawing, and retrieving account information, as well as functionality for calculating interest. The assignment also requires testing the class with multiple account instances and ensuring proper handling of insufficient funds during withdrawals.

Uploaded by

sosinaanteneh844
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

Submission Date 29-8-2016

Assignment 1

Part 1: Creating a Bank Account Class


Lab Exercise: Exploring Classes and Objects in Java
Part 1: Creating a Bank Account Class
1. Create a new Java class named `BankAccount`.
2. Define the following attributes (member variables) to represent a bank account:
* `accountNumber` (String)
* `balance` (double)
* `customerName` (String)
3. Implement a constructor that takes three arguments: `accountNumber`,
`customerName`, and an initial `balance`. This constructor initializes the
corresponding attributes of the object.
Part 2: Adding Functionality with Methods
1. Create a method named `deposit` that takes an amount (double) as input and adds
it to the account balance.
2. Create a method named `withdraw` that takes an amount (double) as input and
subtracts it from the account balance, but ensures the balance doesn't go negative
(print an error message if insufficient funds).
3. Create a method named `getAccountInfo` that returns a formatted string
containing the account number, customer name, and current balance.
Part 3: Testing Your BankAccount Class
1. In your `main` method, create two `BankAccount` objects with different account
details and initial balances.
2. Use the `deposit` method to add some amount to each account.
3. Try to withdraw an amount exceeding the balance from one account and observe
the behavior.
4. Use the `getAccountInfo` method to display the account information for both
objects.
Part 4: Adding Interest
1. Modify your class to include an attribute `interestRate` (double).
2. Implement a method named `calculateInterest` that calculates the interest earned
based on the balance and interest rate.
3. Modify the `deposit` method to optionally accept an additional parameter for
interest earned (can be 0.0 by default) and add it to the balance before any other
deposits.

You might also like