Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

package com.techelevator; public class CheckingAccount extends BankAccount { private static final int OVERDRAFT _ FEE = 1 0 ; / / Constructor with three arguments

package com.techelevator;
public class CheckingAccount extends BankAccount {
private static final int OVERDRAFT_FEE =10;
// Constructor with three arguments
public CheckingAccount(String accountHolderName, String accountNumber, int balance){
super(accountHolderName, accountNumber, balance); // Call superclass constructor
}
// Constructor with two arguments
public CheckingAccount(String accountHolderName, String accountNumber){
super(accountHolderName, accountNumber, 0); // Initialize balance to zero
}
@Override
public int withdraw(int amount){
int currentBalance = getBalance(); // Get the current balance
System.out.println("Current balance: "+ currentBalance);
int newBalance = currentBalance - amount; // Calculate the new balance after withdrawal
System.out.println("New balance after withdrawal: "+ newBalance);
// Check if the withdrawal amount exceeds the balance
if (newBalance <0){
// If the new balance is negative, apply the overdraft fee
newBalance -= OVERDRAFT_FEE;
System.out.println("Applied overdraft fee. New balance after fee: "+ newBalance);
}
// Update the balance indirectly using the deposit method to ensure fee is applied
deposit(currentBalance - newBalance);
return newBalance;
}
}"C:\Program Files\Eclipse Adoptium\jdk-11.0.23.9-hotspot\bin\java.exe" -ea -Didea.test.cyclic.buffer.size=1048576"-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2024.1\lib\idea_rt.jar=57493:C:\Program Files\JetBrains\IntelliJ IDEA 2024.1\bin"-Dfile.encoding=UTF-8-classpath "C:\Users
ayel\.m2\repository\org\junit\platform\junit-platform-launcher\1.9.1\junit-platform-launcher-1.9.1.jar;C:\Program Files\JetBrains\IntelliJ IDEA 2024.1\lib\idea_rt.jar;C:\Program Files\JetBrains\IntelliJ IDEA 2024.1\plugins\junit\lib\junit5-rt.jar;C:\Program Files\JetBrains\IntelliJ IDEA 2024.1\plugins\junit\lib\junit-rt.jar;C:\Users
ayel\OneDrive\Desktop\meritAmerica\ismael-romero-student-exercises\11_Inheritance\exercise\target\test-classes;C:\Users
ayel\OneDrive\Desktop\meritAmerica\ismael-romero-student-exercises\11_Inheritance\exercise\target\classes;C:\Users
ayel\.m2\repository\org\junit\jupiter\junit-jupiter-api\5.9.1\junit-jupiter-api-5.9.1.jar;C:\Users
ayel\.m2\repository\org\opentest4j\opentest4j\1.2.0\opentest4j-1.2.0.jar;C:\Users
ayel\.m2\repository\org\junit\platform\junit-platform-commons\1.9.1\junit-platform-commons-1.9.1.jar;C:\Users
ayel\.m2\repository\org\apiguardian\apiguardian-api\1.1.2\apiguardian-api-1.1.2.jar;C:\Users
ayel\.m2\repository\org\junit\jupiter\junit-jupiter-engine\5.9.1\junit-jupiter-engine-5.9.1.jar;C:\Users
ayel\.m2\repository\org\junit\platform\junit-platform-engine\1.9.1\junit-platform-engine-1.9.1.jar;C:\Users
ayel\.m2\repository\org\junit\vintage\junit-vintage-engine\5.9.1\junit-vintage-engine-5.9.1.jar;C:\Users
ayel\.m2\repository\junit\junit\4.13.2\junit-4.13.2.jar;C:\Users
ayel\.m2\repository\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar" com.intellij.rt.junit.JUnitStarter -ideVersion5-junit5 @w@C:\Users
ayel\AppData\Local\Temp\idea_working_dirs_junit.tmp @C:\Users
ayel\AppData\Local\Temp\idea_junit.tmp -socket57492
Current balance: 100
New balance after withdrawal: 78
Current balance: 100
New balance after withdrawal: -1
Applied overdraft fee. New balance after fee: -11
java.lang.AssertionError: CheckingAccount withdraw method fails to decrease balance by correct amount. Starting balance: 100, withdraw: 101, new balance should be -11(-1 is greater than -100,10 fee incurred). expected:<-11> but was:<211>
Expected :-11
Actual :211
at org.junit.Assert.fail(Assert.java:89)
at org.junit.Assert.failNotEquals(Assert.java:835)
at org.junit.Assert.assertEquals(Assert.java:120)
at com.techelevator.CheckingAccountTest.test03_EdgeCase_Tests(CheckingAccountTest.java:99)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
at org.junit.runners.ParentRunner

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions