Question
The goal of this test assignment is to give you experience writing classes and using objects based on the class you created. Requirements: You need
The goal of this test assignment is to give you experience writing classes and using objects based on the class you created.
Requirements:
You need to create a BankAccount class with methods for operating on bank accounts.
Your class must have the following elements with the exact names as described below, so I can test it when grading the assignment.
BankAccount Class Requirements:
The name of the class should be BankAccount. The BankAccount class should store a persons name, account number, pin, and balance.
1. These data stores should be private fields (class variables) and only accessed using getter and setter methods.
2. Create Getter and Setter methods to access the data (instance variables).
-getName() used to return the value stored in the name field.
-setName(value) used to set the value of the name field.
-getAccountNumber() used to return the value stored in the accountNumber field.
-setAccountNumber(value) used to set the value of the accountNumber field.
-getPIN() used to return the value stored in the pin field.
-setPIN(value) used to set the value of the pin field.
-getBalance() used to return the value stored in the balance field.
-setBalance(value) used to set the value of the balance field.
3. You need to create constructors for the class.
-One constructor should take an int parameter for the bank account number and an int for the PIN number to set the values for those fields when constructing a new object.
-You need to create a default constructor that takes no parameters and gives each field an initial startup value when constructing a new object.
-Example: BankAccount myAccount = new BankAccount(5263234552100, 1234); BankAccount anotherAccount = new BankAccount(); //default constructor
4. You need to create methods for working with bank accounts.
-withdrawal(amount) used to decrease an accounts balance by an amount.
-deposit(amount) used to increase an accounts balance by an amount.
-transferFunds (amount, toBankAccount) used to transfer funds from one bank account to another bank account. (This is the trickiest method because it accepts another BankAccount object as a parameter to the method. The object that the method is being called on is one object, which can be reference using the this keyword, and the toBankAccount object passed into the method is another object that will have funds transferred to it.)
5. Create a toString() method in the BankAccount class that returns a string representation of a BankAccount object. Its common to convert an object with data to a string for data communication over a network, or data storage for storing in a text file or the database.
Suggested string format: {id:12345, name:some name, pin:1234, balance:$123.56}
6. Make sure your BankAccount class methods do some level of checking for invalid values. For example, the setBalance(value) method shouldnt set the balance to a negative value. Think about this when creating all your methods. There are a few methods that may not work properly when the user passes invalid data. Hence, the reason a number of the methods need some value checking.
Test Program Requirements:
A. Create a simple BankAccountTest class that creates several BankAccount objects, stores values in these objects, test to make sure the methods operate properly on these values.
B. Test you methods thoroughly to ensure the methods are working properly.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started