Hi, I'm new to the whole programing world, so I'm a bit lost.
The problem is:
Enhanace the "BankAccount" class by,
1.) Rejecting negative amounts in the deposit and withdrawl methods.
and
2.) Rejects withdrawals that would result in a negative balance.
(Simply return from the method without modifying the balance when the amount is negative or a withdrawl exceeds the balance.)
**What I've gotten so far is:
if (amount <= balance)
balance = balance - amount;
else
system.out.println("Not enough memory in account")
the class "BankAccount" is below:
public class BankAccount
{
public BankAccount()
{
balance = 0;
}
public BankAccount(double initialBalance)
{
balance = initialBalance;
}
public void deposit(double amount)
{
// ...
double newBalance = balance + amount;
balance = newBalance;
}
public void withdraw(double amount)
{
// ...
double newBalance = balance - amount;
balance = newBalance;
}
public double getBalance()
{
return balance;
}
private double balance;
}