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 : ", "3426: 101.56", b.toString()); }

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!