# Bank account supporting deposit, withdrawal, and interest

This is my completed code I was wondering whether it needs a correction

This is my first class

public class Account
{
private double balance; //STATE
private double interestRate; //STATE
private double rate;//STATE

public Account()
{
balance = 0;
interestRate = 0;
}

public Account(double amount, double interestRate)
{
balance = amount;
rate = interestRate;

}

public void deposit(double amount)
{
balance=balance+amount;
}

public void withdraw(double amount)
{
balance = balance - amount;
}

public void setInterest(double rate)
{
balance = balance + balance * rate;
//this.setInterst = setInterest;
//setInterest = InterestRate / 12;
}

public double computeInterest(int n)
{
balance=Math.pow(balance*(1+rate),n/12);
return balance;
}

public double getsetInterest()
{
return rate;
}

public double getBalance()
{
return balance;
}

public void close()
{
balance =0;
}

}


This is my second class

public class TestAccountInterest
{
public static void main (String[] args)
{
Account acc1 = new Account(500, 0.1);//0.10);
Account acc2 = new Account(400, 0.2); //0.20);

/*************************************
ACC1 ACCOUNT BELOW
*************************************/
acc1.deposit(500);
acc1.withdraw(300);
acc1.computeInterest(12);
System.out.println(acc1.computeInterest(12));

/**************************************
ACC2 ACCOUNT BELOW
**************************************/
acc2.withdraw(200);
acc2.deposit(800);
acc2.computeInterest(24);
System.out.println(acc2.computeInterest(24));

}

}


Can anyone see whether I would be able to make the code more compact and is the way that I have coded perfectly valid. The code is about an Accounts class with a test account class for the second class it is supposed to calculate the compute interest of 12 months for the first one and for the second one is supposed to be about 24 months.

Well, this is really vague.

Regarding Account :

Your Account class looks like a anemic class except the computeInterest method. For this one, you should rename the n parameter to reveal his role.

I does not understand your getsetInterest method.

One thing that seems wrong is your close method. When an Account is closed it cannot be used anymore. You may maintains another state to know if the account is closed. Or create another ClosedAccount.

For TestAccountInterest :

You should have a look at a test framework that will run your tests and report failures.

Your class is called TestAccountInterest but you are doing more than testing the interest, you are also testing the deposit and withdraw methods.