Page 1 of 1

This project will involve creating a BankAccount class with the following properties below: The BankAccount class will b

Posted: Thu Jul 14, 2022 2:10 pm
by answerhappygod
This project will involve creating a BankAccount class with thefollowing properties below:The BankAccount class will be used to set up multiple clientaccounts (different name & ID), it will also beused to keeps track of a user's available balance, along with thenumber of transactions (deposits and/or withdrawals) which aremade.
public class BankAccount { Private String name private String id; private double balance; private int numTransactions;
// Accessors and Mutatorfunctions....
// Additional methods // Deposit - Adds amount to balance. Also countsas 1 transaction. public void deposit(double amount) // Subtracts amount from balance if user hasenough money. Counts as 1 transaction. public void withdraw(double amount) // Rememberto verify client has sufficient funds prior to withdrawal, and ifnot output a message.}
1) Please write the Accessor (Getters) and Mutators (Setters)methods for the 4 instance variables above. 2) Also create the method definitions for the methods deposit() andwithdraw().
//Example of using this class when using the defaultcontructor:BankAccount savings = new BankAccount();savings.setName ("Jimmy"); // can also use this method whenthe default constructor is used.savings.setId(12345); // canalso use this method when the default constructor is used.savings.setBalance(50.00);
savings.deposit(10.00);savings.deposit(50.00);savings.deposit(10.00);savings.deposit(70.00); savings.withdraw(100.00);System.out.println("Balance = "+savings.getBalance()); // Balance = $90, with 5 transactionsSystem.out.println("Number of Transactions ="+savings.getNumTransactions());
// Example using 2 parameter constructorBankAccount savings2 = new BankAccount("John", 6789, 100.00);
savings2.deposit(20.00);savings2.withdraw(10.00);System.out.println("Balance = "+savings2.getBalance()); // Balance = $110, with 2 transactionsSystem.out.println("Number of Transactions ="+savings2.getNumTransactions());
3) Create two constructors for your class: the default and 3parameter constructors. The three parameter constructor will allow a user toset the name, id and initial balance when instantiating theobject.
4) Please create the the BankAccount class in one java file(BankAccount.java) and the test/demo with main in a second java file (BankAccountDemo.java). 5) Please test all methods for the class and insert your testingscreenshots in ONE MS Word file. Therefore each student should upload ONLY 3 files: 2JAVA files and 1 MS Word document (testing code). Any files other than these, will not be looked at andwill not be graded.
6) Some code requirements: a) Withdrawal amount should be tested toensure there are sufficient funds present. b) setBalance should check whether thedeposited amount is in the valid range 0-10,000 (inclusive) c) setNumTransactions should not allowsetting to a negative value. d) Don't worry about testing for validname, id.
Rubric grading criterior, ensure code: has appropriatecomments, uses good coding styles(proper indenting), proper naming conventions, no literals (useConstants) as has been shown in class. has been tested properly.