Question
Hello this is hw the over draft is calculated for the first over draft is 20 but for the second over draftand all other after
Hello this is hw the over draft is calculated for the first over draft is 20 but for the second over draftand all other after that is 30 dollars. Yes then output show here has a miscalculation because there was a bug in the output or so he said, but is supposeto be like that. He also, sai is a short code t be ableto finish this. This is your program's required output. Notice how the first overdraft has a penalty of $20, but the second and third overdrafts have penalties of $30 each.
Hello, I really appreciate if someone can help me solve this exercise correctly. Thanks a lot in advance.
Complete Exercise E9.3 (checking account problem).
What to turn in: A zip file containing ONLY 3 java source code.files (BankAccount.java, BudgetCheckingAccount.java, and CheckingAccount.java). NO FOLDERS may be included in your zip file, or I will simply reject it. You are not giving me the AccountDemo.java file, because I have my own copy, and you are not permitted to modify it. Also, the package statement must be correct, as explained later in the assignment description.
You have to do it a bit differently from the way described in the book. Create a new subclass named BudgetCheckingAccount that extends CheckingAccount, and override the withdrawal method to implement the penalty mentioned in the exercise specification. Also, prevent the actual withdrawal from creating a negative balance. (The penalty, on the other hand CAN create a negative balance.) YOU ARE NOT PERMITTED TO MODIFY THE CheckingAccount class. (Companies often sell you their code library without giving you access to the source code.) Of course, you will have to make appropriate changes to the startup class, named AccountDemo. DO NOT MODIFY IT, not even the package statement!
Right-click to download a ZIP file (named Asg 2 start.zip) containing the classes you need for this assignment.
Make sure all our .java files have this statement on the first line:
package ch09.exercises_E9_3;
Hello this is hw the over draft is calculated for the first over draft is 20 but for the second over draftand all other after that is 30 dollars. Yes then output show here has a miscalculation because there was a bug in the output or so he said, but is supposeto be like that. He also, sai is a short code t be ableto finish this. This is your program's required output. Notice how the first overdraft has a penalty of $20, but the second and third overdrafts have penalties of $30 each.
ACOUNT DEMO
package ch09.exercises_E9_3; import java.util.Scanner; /** This program simulates a bank with checking and savings accounts. */ public class AccountDemo { public static void main(String[] args) { // Create accounts final int ACCOUNTS_SIZE = 5; BankAccount[] accounts = new BankAccount[ACCOUNTS_SIZE]; for (int i = 0; i < accounts.length; i++) { accounts[i] = new BudgetCheckingAccount(); } // Create some test cases int id; double amount; id = 1; amount = 50.0; accounts[id].deposit(500); System.out.printf("Account %d balance = %.2f ", id, accounts[id].getBalance()); System.out.printf("Attempting to withdraw %.2f from Account %d ", amount, id); accounts[id].withdraw(amount); // first valid withdrawal System.out.printf("Account %d balance = %.2f ", id, accounts[id].getBalance()); amount = 40; System.out.printf("Attempting to withdraw %.2f from Account %d ", amount, id); accounts[id].withdraw(amount); // first valid withdrawal System.out.printf("Account %d balance = %.2f ", id, accounts[id].getBalance()); amount = 500; System.out.printf("Attempting to withdraw %.2f from Account %d ", amount, id); accounts[id].withdraw(amount); // first valid withdrawal System.out.printf("Account %d balance = %.2f ", id, accounts[id].getBalance()); amount = 391; System.out.printf("Attempting to withdraw %.2f from Account %d ", amount, id); accounts[id].withdraw(amount); // first valid withdrawal System.out.printf("Account %d balance = %.2f ", id, accounts[id].getBalance()); amount = 370; System.out.printf("Attempting to withdraw %.2f from Account %d ", amount, id); accounts[id].withdraw(amount); // first valid withdrawal System.out.printf("Account %d balance = %.2f ", id, accounts[id].getBalance()); } // main }
BANK ACCOUNT
package ch09.exercises_E9_3; /** A bank account has a balance and a mechanism for applying interest or fees at the end of the month. */ public class BankAccount { private double balance; /** Constructs a bank account with zero balance. */ public BankAccount() { balance = 0; } /** Makes a deposit into this account. @param amount the amount of the deposit */ public void deposit(double amount) { balance = balance + amount; } /** Makes a withdrawal from this account, or charges a penalty if sufficient funds are not available. @param amount the amount of the withdrawal */ public void withdraw(double amount) { balance = balance - amount; } /** Carries out the end of month processing that is appropriate for this account. */ public void monthEnd() { } /** Gets the current balance of this bank account. @return the current balance */ public double getBalance() { return balance; } }
CHEKING ACCOUNT
package ch09.exercises_E9_3; /** A checking account has a limited number of free deposits and withdrawals. */ public class CheckingAccount extends BankAccount { private int withdrawals; /** Constructs a checking account with a zero balance. */ public CheckingAccount() { withdrawals = 0; } public void withdraw(double amount) { final int FREE_WITHDRAWALS = 3; final int WITHDRAWAL_FEE = 1; super.withdraw(amount); withdrawals++; if (withdrawals > FREE_WITHDRAWALS) { super.withdraw(WITHDRAWAL_FEE); } } public void monthEnd() { withdrawals = 0; } }
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