Hi I need to create Bank account which would give these values when the tester class is applied:
The tester class is
public class BankAccountTester
{
public static void main(String[] args)
{
BankAccount account = new BankAccount(100);
account.deposit(-100);
System.out.println(account.getBalance());
System.out.println("Expected: 100");
account.withdraw(-50);
System.out.println(account.getBalance());
System.out.println("Expected: 100");
account.withdraw(200);
System.out.println(account.getBalance());
System.out.println("Expected: 100");
}
}
MY CODE IS
/**
A bank account has a balance that can be changed by
deposits and withdrawals.
*/
public class BankAccount
{
private double balance;
private int transaction;
private double minimumBalance;
//define the minimum balance method
/**
Constructs a bank account with a zero balance.
*/
public BankAccount()
{
balance = 0;
}
/**
Constructs a bank account with a given balance.
@param initialBalance the initial balance
*/
public BankAccount(double initialBalance)
{
balance = initialBalance;
}
/**
Deposits money into the bank account.
@param amount the amount to deposit
*/
public void deposit(double amount)
{ if (amount<=0) {
amount=0;
double newbalance= balance +amount*0;
balance=newbalance;
transaction=transaction +1;}
if (amount>=0){
double newBalance = balance + amount;
balance = newBalance;
transaction = transaction +1; }}
/**
Withdraws money from the bank account.
@param amount the amount to withdraw
*/
public void withdraw(double amount)
{ if (amount<=balance){
double newBalance = balance + amount;
balance = newBalance;
transaction = transaction +1;
minimumBalance = Math.min(minimumBalance, balance);
}
if (amount>balance){
double newBalance = balance + amount*0;
balance = newBalance;}}
/**
Gets the current balance of the bank account.
@return the current balance
*/
public double getBalance()
{
return balance;
}
public void endOfMonth(double interestRate)
{
balance= balance - transaction;
double interest = minimumBalance * interestRate / 100 / 12;
transaction= 0;
}
// declare a minimumBlance Method
public double getminimumBalance()
{ return minimumBalance;
}}
My Values comes out to be:
100.0
Expected: 100
50.0
Expected: 100
50.0
Expected: 100
Can anyone inspect my code and tell me whats wrong?

