Question
need help debug public void test_constructorWithBalance() { BankAccount b = new BankAccount(50.0); assertEquals(Unexpected balance,50.0,b.getBalance(), 0.00001); String actualAccountNumber = b.getAccountNumber(); assertEquals(Account number should have exactly length
need help debug
public void test_constructorWithBalance() { BankAccount b = new BankAccount(50.0); assertEquals("Unexpected balance",50.0,b.getBalance(), 0.00001);
String actualAccountNumber = b.getAccountNumber(); assertEquals("Account number should have exactly length 4 (4 digits)", 4, actualAccountNumber.length()); int num = Integer.parseInt(actualAccountNumber); assertTrue("Account number should be a number between 1 and 9999 (inclusive)", 1 <= num && num <= 9999); } @Test public void test_constructorWithBalance_negative() { BankAccount b = new BankAccount(-50.0); assertEquals("Unexpected balance",-50.0,b.getBalance(), 0.00001);
String actualAccountNumber = b.getAccountNumber(); assertEquals("Account number should have exactly length 4 (4 digits)", 4, actualAccountNumber.length()); int num = Integer.parseInt(actualAccountNumber); assertTrue("Account number should be a number between 1 and 9999 (inclusive)", 1 <= num && num <= 9999); }
@Test public void test_constructorWithBalance_negative() { BankAccount b = new BankAccount(-50.0); assertEquals("Unexpected balance",-50.0,b.getBalance(), 0.00001);
String actualAccountNumber = b.getAccountNumber(); assertEquals("Account number should have exactly length 4 (4 digits)", 4, actualAccountNumber.length()); int num = Integer.parseInt(actualAccountNumber); assertTrue("Account number should be a number between 1 and 9999 (inclusive)", 1 <= num && num <= 9999); }
public void test_creation(){ BankAccount b = new BankAccount(); assertEquals("Expected initial balance to be 0.0", 0.0, b.getBalance(), 0.00001); String actualAccountNumber = b.getAccountNumber(); assertEquals("Account number should have exactly length 4 (4 digits)", 4, actualAccountNumber.length()); int num = Integer.parseInt(actualAccountNumber); assertTrue("Account number should be a number between 1 and 9999 (inclusive)", 1 <= num && num <= 9999); }
@Test public void test_toString() { BankAccount b = new BankAccount(101.56, "3426"); assertEquals("Expected to string to return
my code:
public class BankAccount { private double balance; private String accountNumber; public BankAccount() { accountNumber = ""; balance = 0.0; }
public BankAccount(double d) { if(d>0) balance = d; } public BankAccount(double b, String n){ accountNumber = n; balance = b; }
public double getBalance() { return balance; } public String getAccountNumber() { return accountNumber; } public String toString() { return accountNumber+":"+balance; } public void deposit(double amount){ if (amount > 0.0) { balance = balance + amount; } } public void withdraw(double amount){ if (amount > 0.0 && amount <= balance) { balance = balance - amount; } } }
requirements:
Create a class called BankAccount that has
- Two instance variables: balance of type double and accountNumber of type String.
- Accessor (getter) Methods:
- getBalance() which returns the value of the instance variable balance.
- getAccountNumber() which returns the value in the instance variable accountNumber.
- toString() which returns the information in the instance variables in the following format:
:
- Mutator (setter) Methods:
- deposit and withdraw. Each takes a double as an argument and don't return anything.
- Constructors:
- Default (no arguments)
- One that takes a start balance.
- One that takes a start balance and account number
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