Note: The TestBank.java code given in image is different from the code given in the question. provide the output based o

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

Note: The TestBank.java code given in image is different from the code given in the question. provide the output based o

Post by answerhappygod »

Note: The TestBank.java code given in image is
different from the code given in the question. provide the output
based on the image the test code is not editable
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);
}
Bank.java
import java.util.ArrayList;
public class Bank {
private ArrayList 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(){}
}
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
}
}
SavingsAccount.java
public class SavingsAccount extends Account {
public void checkIntDeposit(double initialAmount){}
@Override
public boolean withdraw(double amount){ }
@Override
public void deposit(double amount){ }
public double addInterest(double rate){ }
public String toString() {
// returns the content of Account name and balance
refer to Account toString()
}
}
TestBank.java
import java.util.ArrayList;
public class TestBank {
public static void main(String[] arg) {
Bank bank = new Bank();
bank.setSavingsInterest(0.25);
Account a1 = new SavingsAccount("Alice
Jones", 100.00);
Account a2 = new CheckingAccount("Bob
The Builder", 50.00);
bank.addAccount(a1);
bank.addAccount(a2);

System.out.println("Number of accounts:
" + bank.numberOfAccounts());
boolean result = bank.withdraw("Alice
Jones", 20.00);
System.out.println(result);
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"));
Account a3 = new SavingsAccount("Bob
The Builder", 50.00);
bank.addAccount(a2);
bank.addAccount(a3);
bank.deposit("Alice Jones", 100);
bank.deposit("Bob The Builder",
5000);
System.out.println(bank.getAccount("Bob
The Builder"));

System.out.println(bank.getAccount("Alice Jones"));
result = bank.withdraw("Alice
Jones", -20.00);
bank.writeCheck("Bob The Builder",
230.89);
bank.writeCheck("Alice Jones",
30.89);
System.out.println(result);
bank.printAllAccounts();
}
}
Note The Testbank Java Code Given In Image Is Different From The Code Given In The Question Provide The Output Based O 1
Note The Testbank Java Code Given In Image Is Different From The Code Given In The Question Provide The Output Based O 1 (107.3 KiB) Viewed 58 times
Abstract Classes, Inheritance (Bank Application) 150 points 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 - This is part 1 so you can test your basic operations. - Part 2 will be posted shortly that will do a more complete testing of the classes and requires reading from a file that has the accounts' data. Account class: Account is an abstract class. Details: 1. protected String name; // account holder name 2. protected double balance; // stores the current balance 3. public Account(String name, double balance) // Note that even though the abstract class cannot be directly instantiated, this constructor will be used from a sub-class's constructor. 4. public String getName() // Returns the name. 5. public double getBalance() // Returns the current balance. 6. public String toString0 // Returns a string that contains the id and balance. For example, if the name is "Joe Baron" 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. 7. 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). 8. 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).

SavingsAccount class SavingsAccount extends Account. A Savings Account requires a minimum of $10 in the account at any time. 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. Details: 1. No new attributes are needed. 2. public Savings Account(String name, double initialDeposit): 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. 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. 3. 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. A withdrawal that potentially lowers the balance below $10 is not allowed. The balance remains unchanged but the method returns false. If the withdrawal succeeds, the method returns true. Note that using a boolean return value is bad design. A better way would be to throw Java exceptions. However, since we haven't covered the topic yet, we will not use exceptions. 4. public void deposit(double amount): The provided amount is added to the account as a result of an ATM transaction. No transaction fees apply. 5. public double addinterest(double rate): The monthly rate is provided as a percentage by the caller of the method. The method calculates the interest on the balance and adds the interest to the balance. 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 (= balancetrateinpercent/100). 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.

Checking Account class CheckingAccount extends Account. This account does not give any interest. 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. 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. If a 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. Details: 1. 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: 2. public CheckingAccount(String name, double initialBalance): Assume that the initial balance will not be negative. This constructor should use super to use the code in the superclass. 3. public boolean withdraw(double amount): Implement the withdraw method via ATMs to take out the provided amount from the account balance. Incorporate the transaction fee for ATM/electronic withdrawals. 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. 4. public void deposit(double amount): The provided amount is added to the account as a result of an ATM transaction. Applicable transaction fees are deducted from the balance. 5. public void resetChecksUsed() // This method makes the numberOfChecksUsed zero. 6. public int getChecksUsed) // This method returns the numberOfChecksused. 7. public boolean withdrawUsingCheck(double amount): This method allows one to use checks to withdraw cash. It updates the balance according to the rules described above. 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. A successful withdrawal results in updating the balance and number of checks used, and the method returns true.

ine pank class can retrieve a particular account using a account it 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. Details: • private ArrayList accounts; ArrayList of Accounts (including subclasses) • private double savingsinterestRate; • rate of interest for SavingsAccount in percent • public Bank(): initializes the ArrayList with a new one. • public void set SavingsInterest(double rate): sets the rate in percent • public int numberOfAccounts(): return the number of accounts active in the bank (not the capacity of the ArrayList accounts) public void addAccount(Account a): add the provided account to the accounts ArrayList • public Account getAccount(String accountlD) : return the first Account object could be a subclass) corresponding to the accountld. If the account does not exist for the specified accountID, then return null. public boolean deposit(String accountID, double amount): deposit provided amount into the account specified by accountld. If account is not found, then return false. Otherwise make the deposit and return true. • public boolean withdraw(String accountID, double amount): 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): withdraw from provided from AccountID and deposit to specified to Accountld. 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(): 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(): iterate through all accounts and reset the number of checks for applicable acccounts (i.e., all CheckingAccounts) public boolean writeCheck(String accountID, double amount): Allow user to write a check from a checking account

TestClass Create a test class to test the accounts to make sure everything is working. • Preliminary testing: The checking system performs preliminary testing of your program. 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. Note that we will not test your main method; the methods you implement will be tested directly. Ideally, you should create your own main method, perhaps one in each class, to test each class separately. You can also a main method in the Bank class that tests the four classes together. 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. You should do additional tests and test all methods and possible scenarios public static void main(String[] args) { Bank bank = new Bank(); bank.setSavings Interest(0.25); Account al = new SavingsAccount ("alice", 100.00); Account a2 = new CheckingAccount ("bob", 50.00); //adding accounts to the bank bank.addAccount (al); bank.addAccount (a2); System.out.println("Number of accounts: " + bank.numberOfAccounts()); boolean result = bank.withdraw ("alice", 20.00); System.out.println(result); result = bank.deposit ("bob", 20.00); System.out.println(result);

System.out.println("Number of accounts: " + bank.numberOfAccounts()); boolean result = bank.withdraw("alice", 20.00); System.out.println(result); result = bank.deposit ("bob", 20.00); System.out.println(result); bank.addInterest(); bank.clear(); System.out.println (bank.getAccount ("alice")); System.out.println(bank.getAccount ("bob")); 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.

1: Copy of Copy of Compare output 0/100 Output differs. See highlights below. Your output ends with Number of accounts: 2 true true Name: Alice Jones, Balance: $78.20 null Name: Bob The Builder, Balance: $5068.00 Checks used: 0 Name: Alice Jones, Balance: $178.20 true Name: Alice Jones, Balance: $209.08 Name: Bob The Builder, Balance: $4837.11 Checks used: 1 Number of accounts: 2 true true Name: Alice Jones, Balance: $78.20 bob account does not exist. null Account not added, duplicate ID Account not added, duplicate ID Name: Bob The Builder, Balance: $5068.00 Checks used: 0 Expected output ends with Name: Alice Jones, Balance: $178.20 Withdraw amount can't be negative. Invalid operation for savings accounts. Invalid operation for savings accounts. Invalid operation for savings accounts. false Name: Alice Jones, Name: Bob The Builder, Balance: $178.20 Balance: $4837.11 Checks used: 1
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply