Reputation: 21
I am trying to place interest on bank transactions. The main goal is to try and have 0.05 or 5% on transactions over 2000. 0.02 or 2% as a flat rate for Savings accounts and 0% for a checking account.
So I have a check interest method that is placed before any deposit so the correct interest is given. I cant get the 0% to work without it overriding the other interests. My code looks like this as a default.
public void checkInterest(double amount){
if(balance + amount <= 2000){
interest = 0.02;
}
else{
interest = 0.05;
}
My last attempt was this.
public void checkInterest(double amount){
if(balance + amount <= 2000){
interest = 0.02;
}
else{
interest = 0.05;
}
if(Checking.accountType == "checking"){
interest = 0.00;
}
}
If I do this, whilst running it overrides and gives out a flat 0%. I also tried using Checking.accountType != null, but this also didn't work.
Any pointers? This is just for academic work. (also, I'm just a beginner so go easy)
Upvotes: 1
Views: 114
Reputation: 890
If the account type is a String
, you should compare them like this:
if(Checking.accountType.equals("checking")){
Also, you might want to change your checkInterest
method to return the value of interest
.
public double checkInterest(double amount){
double interest;
// Calculate interest rate here
return interest;
}
Upvotes: 1