CheckingAccount.java public class CheckingAccount extends Account { private int numberOfChecks = 0; CheckingAcco

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

CheckingAccount.java public class CheckingAccount extends Account { private int numberOfChecks = 0; CheckingAcco

Post by answerhappygod »

CheckingAccount.java
public class CheckingAccount extends Account {
private int numberOfChecks = 0;
CheckingAccount(String name, double initialBalance){
}
@Override
public boolean withdraw(double amount){//withdraw
from ATM/electronic transactions }
@Override
public void deposit(double amount){ }
public void resetChecks(){ }
public int getChecksUsed(){ }
public boolean withdrawUsingCheck(double
amount){}
public String toString() {
// return the content of Account +
" Checks used: " + xx
}
}
Bank.java
import java.util.ArrayList;
public class Bank {
private ArrayList<Account> accounts;
private double savingsInterestRate;
public Bank(){}
public void setSavingsInterest(double rate) {}
public int numberOfAccounts(){ }
public void printAllAccounts(){ }
public void addAccount(Account a){}
public Account getAccount(String accountID){ }
public boolean deposit(String accountID, double
amount) { }
public boolean withdraw(String accountID, double
amount){}
public boolean writeCheck(String accountID, double
amount){ }
public boolean transfer(String fromAccountID, String
toAccountID, double amount){ }
public void addInterest(){}
public void reset(){}
}
Account.java
import java.text.DecimalFormat;
abstract public class Account {
protected String name;
protected double balance;
//Constructor
public Account(String Name, double balance){}
//required methods
public void setName(String Name){
}
public void setBalance(double balance){
}
public String getName(){}
public double getBalance(){}
public String toString(){
// must return the following
Name: xxxx Balance: $xxx.xx
}
public abstract boolean withdraw(double
amount);
public abstract void deposit(double amount);
}
TestBank.java
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;
public class TestBank {

public static ArrayList<Account>
ReadAccounts()throws IOException{
//Complete the code here
}
public static Scanner openFile()throws
IOException{
//Complete the code here
}
public static void main(String[] arg)throws
IOException {

ArrayList<Account> accounts = new
ArrayList<>();
Account temp;
Bank bank = new Bank();
bank.setBankName("CSUDH Credit Union");
bank.setSavingsInterest(0.025);
accounts = ReadAccounts();
bank.setAccounts(accounts);
Account a3 = new SavingsAccount("Bob The
Builder", 50.00);
bank.addAccount(a3);
Account a4 = new CheckingAccount("Bob The
Builder", 50.00);
bank.addAccount(a4);
System.out.println("Number of accounts: " +
bank.numberOfAccounts());
boolean result = bank.withdraw("Alice Jones",
20.00);
System.out.println(result);
temp = bank.search("Tom Halwin");
System.out.println(temp);
temp = bank.search("None");
if( temp == null)
System.out.println("Account not
found.\n");
result = bank.deposit("Bob The Builder",
20.00);
System.out.println(result);
bank.addInterest();
System.out.println(bank.getAccount("Alice
Jones"));

System.out.println(bank.getAccount("bob"));
bank.addAccount(a3);
bank.deposit("Alice Jones", 100);
bank.withdraw("Bob The Builder", 5000);
bank.writeCheck("Jose Pedia", 130.25);
bank.writeCheck("Nancy Wilson", 150);
System.out.println(bank.getAccount("Bob The
Builder"));
System.out.println(bank.getAccount("Alice
Jones"));
bank.transfer("Alice Jones", "Bob The
Builder", 100);
bank.transfer("Alice Jones", "ABC inc.",
1000);
bank.printTable();
bank.printFile();
}
}
SavingsAccount.java
Checkingaccount Java Public Class Checkingaccount Extends Account Private Int Numberofchecks 0 Checkingacco 1
Checkingaccount Java Public Class Checkingaccount Extends Account Private Int Numberofchecks 0 Checkingacco 1 (81.62 KiB) Viewed 45 times
Abstract Classes, Inheritance (Bank Application) 150 points Make the following modification to part 1 of the project • Modify Bank class by adding o add a name for the bank // o getBankName() // return bank name o setBankName(name) // set the bank name to the name passed to the method o getAccounts() // to return a copy of list of accounts o setAccounts(list) // set the list of account to the passed list to the method o search(name) // given the name of an account holder returns the account or null if not found o printTable() // prints the bank info and the accounts in a tabular form to the monitor see format below o printFile() // prints the bank info and the accounts in a tabular form to a file see format below(make the output file name out.txt) Make the following changes to the TestBank class Add ReadAccounts() // This method will use OpenFile() method to open a file and read the details of all account and stores them in an ListArray of Accounts • Add OpenFile() to prompt user for a file name and check to make sure it opened and there is data in the file. Return the Scanner if file is open otherwise print error message and exit the program. ** Sample input file and format** Name Account code Initial deposit s for savings account, C for checking Tom Halwin S 2300 Jose Pedia C 3400 Nancy Wilson S 1200

** Sample input file and format** Name Account code Initial deposit s for savings account, c for checking Tom Halwin S 2300 Jose Pedia C 3400 Nancy Wilson S 1200 Tabular output format for file and monitor Checks Used Bank Name: CSUDH Credit Union Accounts Information: Account Holder Balance Account Type Tom Halwin $2300.58 Savings Jose Pedia $3269.75 Checking Nancy Wilson $1200.30 Savings 1 Requirements for part 1 of the project. 1. Objectives • The objectives of this assignment is to understand the concept of inheritance and abstract classes in Java. You will develop a simple bank application containing four classes Bank, abstract class Account, Savings Account, and CheckingAccount. A template for each class is provided and you must download it and complete the classes without changing any of the methods, but you may add more methods if it is necessary. 2. Account class Account is an abstract class. &itbr/&at:

2. Account class Account is an abstract class. <br/> • List of attributes: • protected String name; // some form of account holder name • protected double balance; // stores the current balance • Implement the following constructor: • public Account(String name, double balance) o Note that even though the abstract class cannot be directly instantiated, this constructor will be used from a sub-class's constructor • List of methods: • public String getName() // Returns the account id. • public double getBalance0 // Returns the current balance. public String toString0 // Returns a string that contains the id and balance. For example, if the id is "ghosh" and balance is "$120.30" the string returned is as follows identical punctuation and spaces): • Name: Joe Baron, Balance: $120.30. The number of decimal digits must be exactly two. • public abstract boolean withdraw(double amount) // This method will be implemented in the subclasses to allow withdrawal from ATMs as well as other electronic withdrawals (e.g., account to account transfer). • public abstract void deposit(double amount) // This method will be implemented in the subclasses to allow deposits at ATMs as well as other electronic deposits (e.g., account to account transfer). 3. SavingsAccount class SavingsAccount extends Account.

3. SavingsAccount class Savings Account extends Account. • A SavingsAccount requires a minimum of $10 in the account at any time. o This account allows for depositing or withdrawing from ATM machines and electronic transfers. • No fees are charged for depositing. Withdrawing money incurs a transaction fee of $2 per withdrawal that is taken out of the balance. Any withdrawal that causes the balance to go below $10 (because of the amount to be withdrawn plus the fee) is disallowed. • Interest amount is calculated and added to the balance by the bank. <br/> • List of attributes: • No new attributes are needed. Implement the following constructor: • public Savings Account(String name, double initialDeposit): o Assume that the initial deposit passed will be at least $10. If the initial deposit is $10,000 or above, the bank adds an extra $200.00 as part of its ongoing promotion. o You must call super to use the code of the Account superclass. . Note that super must be called before anything else happens in the constructor. • List of methods: • public boolean withdraw(double amount): • Implement the withdraw method to take out the provided amount from the account balance. Incorporate the transaction fee for withdrawals. o A withdrawal that potentially lowers the balance below $10 is not allowed. o The balance remains unchanged but the method returns false. o If the withdrawal succeeds, the method returns true. o Note that using a boolean return value is bad design. A better way would be to throw Java exceptions. • public void deposit(double amount): o The provided amount is added to the account as a result of an ATM transaction. o No transaction fees apply.

public void deposit(double amount): o The provided amount is added to the account as a result of an ATM transaction. o No transaction fees apply. public double addInterest(double rate): o The monthly rate is provided as a percentage by the caller of the method. o The method calculates the interest on the balance and adds the interest to the balance. o The method returns the interest that was calculated. Note that the caller takes care of determining when interest is due to be added. The addinterest method only needs to be aware of the formula to calculate interest (= balance rateinpercent/100). o For example, if the monthly rate of interest is 0.25%, and the balance is $10,000, then the interest is $25, and the new balance becomes $10,025. 4. Checking Account class • CheckingAccount extends Account o This account does not give any interest. o It allows deposit and withdrawals through ATM machines and electronic transactions, both of which incur a fee of $1 per transaction, which is deducted from the balance. o The balance cannot go below $0 using ATM or electronic transaction. Thus, the minimum amount that can be deposited is also $1. • Assume that we will not try to deposit anything less than that. • Checks may be used to make withdrawals. The first three check uses in a month are free, but subsequent uses add a fee of $2 to each check withdrawal. • Checks are allowed to take the balance to -$10 (i.e., an overdraft). One or more checks can bring the balance down to -$10, but not lower. olfa check use potentially lowers the balance below-$10, the check is disallowed. • Tracking how many checks are used in a month requires a new attribute and methods.

• Tracking how many checks are used in a month requires a new attribute and methods. • Implement the following attribute: • private int numberOfChecks Used; • stores the number of checks used every month. Starts at 0, and can be reset using a method below. The constructor should be of the form: public CheckingAccount(String name, double initial Balance): o Assume that the initial balance will not be negative. This constructor should use super to use the code in the superclass. • List of Methods: public boolean withdraw(double amount): o Implement the withdraw method via ATMs to take out the provided amount from the account balance. o Incorporate the transaction fee for ATM/electronic withdrawals. o A withdrawal that potentially lowers the balance below $0 is not allowed. In such cases the balance remains unchanged but the method returns false. The method returns true if the withdrawal is successful. public void deposit(double amount): o The provided amount is added to the account as a result of an ATM transaction. o Applicable transaction fees are deducted from the balance. • public void resetChecksUsed() // This method makes the numberOfChecksUsed zero. • public int getChecks Used() // This method returns the numberOfChecksUsed. public boolean withdrawUsingCheck(double amount): This method allows one to use checks to withdraw cash. o It updates the balance according to the rules described above. o If the balance could fall below -$10 because of the amount and/or fees, the method doesn't change the balance, does not increment the number of checks used but just returns false o A successful withdrawal results in updating the balance and number of checks used, and the method returns true. 5. Bank class The bank class keeps information on all its accounts in an ArrayList. • The bank class can retrieve a particular account using a account ID and perform deposits and withdrawals.

5. Bank class The bank class keeps information on all its accounts in an ArrayList. • The bank class can retrieve a particular account using a account ID and perform deposits and withdrawals. • It can perform monthly maintenance tasks such as resetting the number of checks in CheckingAccounts and adding interest in SavingsAccounts • List of attributes: • private ArrayList<account> accounts; ArrayList of Accounts (including subclasses) • private double savingsInterestRate; o rate of interest for SavingsAccount in percent • Constructors public Banko o initializes the ArrayList with a new one. • List of methods: • public void setSavingsinterest(double rate): o sets the rate in percent • public int numberOfAccounts(): o return the number of accounts active in the bank (not the capacity of the ArrayList accounts) • public void addAccount(Accounta): o add the provided account to the accounts ArrayList public Account getAccount(String accountID) o return the first Account object could be a subclass) corresponding to the accountID. o If the account does not exist for the specified accountID, then return null. • public boolean deposit(String accountID, double amount): o deposit provided amount into the account specified by accountiD. o If account is not found, then return false. Otherwise make the deposit and return true. • public boolean withdraw(String accountID, double amount):

public boolean withdraw(String accountID, double amount): o withdraw provided amount from the account specified by accountld. Returns true if successful, false otherwise (e.g., accountID not found, or withdraw doesn't succeed). public boolean transfer(String from AccountiD, String to AccountiD, double amount): o withdraw from provided from AccountID and deposit to specified to AccountID. If either accountld is not found, the method must return false and no deposit/withdrawal should occur. Both withdraw and deposit must succeed. If withdraw fails, then do not deposit (even it it were to succeed) and vice versa. Return true if both succeed, false otherwise. Note that this method will call the deposit and withdraw methods declared in the abstract Account class. The transaction fees corresponding to concrete implementations of withdraw and deposit will apply. public void addinterest(): o iterate through all accounts and add interest to the eligible accounts (i.e., all Savings Accounts) using the rate set in the class. • public void reset o iterate through all accounts and reset the number of checks for applicable acccounts (i.e., all CheckingAccounts) • public boolean writeCheck(String accountID, double amount): o Allow user to write a check from a checking account. 6. Tips and Miscellaneous Instructions <br/> Formatting strings in Java You can use the following example to understand how to create formatted strings in Java. o double value = 35.5; o String formattedString = String.format("%.2f", value); Preliminary testing . The checkin system performs preliminary testing of your program. o Preliminary testing may test a small subset of the methods using a small number of tests. • Final grading will be performed using a different set of test cases for all the methods. Here is a sample barebones main method for the Bank class. Remember that in its current form, it does not test all the methods. Nor does

Here is a sample barebones main method for the Bank class. Remember that in its current form, it does not test all the methods. Nor does it test for various situations public static void main(String[] args) { Bank bank = new Bank(); bank.setSavings Interest (0.25); Account al = new Savings Account (&quot;alice&quot;, 100.00); Account a2 = new CheckingAccount (&quot;bob&quot;, 50.00); //adding accounts to the bank bank.addAccount (al); bank.addAccount (a2); System.out.println (&quot;Number of accounts: &quot; bank.numberOfAccounts()); boolean result = bank.withdraw (&quot;alice&quot;, 20.00); System.out.println(result); result = bank.deposit (&quot;bob&quoti, 20.00); System.out.println(result); bank.addInterest(); bank.clear(); System.out.println (bank.getAccount (&quot;alice&quot;)); System.out.println (bank.getAccount (&quot;bob&quot;));

} The output must look like: Number of accounts: 2 true true Name: Alice, Balance: $78.19 Name: Bob, Balance: $69.00 Checks used: 0 7. Final testing • A final testing main method is provided for download to test the program completely.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply