Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Project #1 This project will involve creating a BankAccount class with the following properties below: The BankAccount class will be used to set up multiple

Project #1 This project will involve creating a BankAccount class with the following properties below: The BankAccount class will be used to set up multiple client accounts (different name & ID), it will also be used to keeps track of a user's available balance, along with the number of transactions (deposits and/or withdrawals) which are made. public class BankAccount { Private String name private String id; private double balance; private int numTransactions; // Accessors and Mutator functions.... // Additional methods // Deposit - Adds amount to balance. Also counts as 1 transaction. public void deposit(double amount) // Subtracts amount from balance if user has enough money. Counts as 1 transaction. public void withdraw(double amount) // Remember to verify client has sufficient funds prior to withdrawal, and if not 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() and withdraw(). //Example of using this class when using the default contructor: BankAccount savings = new BankAccount(); savings.setName ("Jimmy"); // can also use this method when the default constructor is used. savings.setId(12345); // can also 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 transactions System.out.println("Number of Transactions = "+savings.getNumTransactions()); // Example using 2 parameter constructor BankAccount 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 transactions System.out.println("Number of Transactions = "+savings2.getNumTransactions()); 3) Create two constructors for your class: the default and 3 parameter constructors. The three parameter constructor will allow a user to set the name, id and initial balance when instantiating the object. 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 testing screenshots in ONE MS Word file. Therefore each student should upload ONLY 3 files: 2 JAVA files and 1 MS Word document (testing code). Any files other than these, will not be looked at and will not be graded. 6) Some code requirements: a) Withdrawal amount should be tested to ensure there are sufficient funds present. b) setBalance should check whether the deposited amount is in the valid range 0-10,000 (inclusive) c) setNumTransactions should not allow setting to a negative value. d) Don't worry about testing for valid name, id. Rubric grading criterior, ensure code: has appropriate comments, uses good coding styles (proper indenting), proper naming conventions, no literals (use Constants) as has been shown in class. has been tested properly. Note that this assignment is to be worked on individually and not in groups.

pls just do the project #2 because you don't have to post number 1 just post project number 2

BackAccount add-ons: Using your project #1, please add the following add-ons. 1) Create a Private Static instance variable (numAccounts), which keeps track of how many savings accounts created in the system. - The idea is each time you instantiate a "New" BankAccount, this static variable increases to reflect that. - Of course we will need an accessor method (getNumAccounts) to retrieve this value. Don't need a mutator method, since this will be initialized to zero at startup. 2) Add some range checking for some of the previous instance variables: - for name, just trim the string to remove blanks before/after string, id (00001 - 99999), setting balance (10,000 dep limit) and withdrawal (2000 withdr limit) amount - for any out of range values, your program should output an error message to the screen and NOT count it as a transaction. 3) Add a NEW class instance variable - an integer array to hold the last 5 transactions. - Basically when a valid Deposit or Withdrawal amount is specified, you store it in the array. You only need to store the values (pos for deposits and negative for withdrawal). - Add one method (getRecentTransactions)to the class which will output the last 5 transactions. - for example, if for a particular savings account, the transactions are: savings1.deposit(10.00); savings1.deposit(50.00); savings1.withdraw(100.00); - then getRecentTransactions() will output the last 5 transactions: 10, 50, -100 - array elements get filled beginning at element 0...to 4. Since the array is of size 5, there may be a scenerio where there are more than 5 transactions. You decide how to handle this case, but please document how you will handle it. some choices are: store only the first 5 and ignore any remaining; or wrap-around and begin to overwrite the array. - note that you will need another private instance variable, which will used for the next available index to use in the array (since the array.length gives you the max size) but you will also need to know which is the next element to be filled. We had a lab on arrays which showed how to do this. As always, please perform tests of the above add-ons, showing these new added features, taking screenshots and storing all in one work-document. Please DO NOT submit ZIP files, only submit 3 files: the java class, the java demo class and the word document with screenshots.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

A Complete Guide To Data Science Essentials

Authors: Miguel

1st Edition

9358684992, 978-9358684995

More Books

Students also viewed these Databases questions