E.g. I have a bank account which has a limit of let's say 500 euros. First I add 400 euros and after that, I add 150 euros. How can I change my code in order to add the 100 euros of my last addition and then print for example; "Your limit has been reached, (leftover 50 euros) of your (original 150 euros) addition cannot be added."
My code as it is right now is like this:
public class Bankaccount {
private double limit;
private String name;
double deposit = 0;
double balance = 0;
int numberOfDeposits = 0;
double afhaling = 0;
public Bankaccount(String name, double limit) // constructor
{
this.name = name;
this.limit = limit;
}
public boolean addDeposit(double deposit){
if(deposit < 0){
balance = balance;
return false;
}
if(deposit > 0){
balance = balance + deposit;
numberOfDeposits ++;
return true;
}
if(balance > limit){
balance = balance;
return false;
}
return false;
}
}