CSU Global Campus
ITS320 Basic Programming
Dr. Biswajit Panja
Final
February 26, 2015
/* * Program number: University – ITS-320 – Basic Programming * Name * Date: 02/26/2015 * */
public class NegativeAmountException extends Exception {
private static final long serialVersionUID = 1L;
public NegativeAmountException(String msg) { super(msg); }
public NegativeAmountException() { }
public String toString() { return "NegativeAmountException"; }
}
public class InsufficientFundsException extends Exception {
private static final long serialVersionUID = 1L;
public InsufficientFundsException(String msg) { super(msg); }
public InsufficientFundsException() { }
public String toString() { return "InsufficientFundsException"; }
}
public class BankAccount {
private String name; private double balance;
public BankAccount(String name, double balance) throws NegativeAmountException { setName(name); // throw exception if balance is negative if (balance < 0) { throw new NegativeAmountException("Negative amount"); } setBalance(balance); }
public BankAccount(String name) throws NegativeAmountException { setName(name); setBalance(0); }
public void setBalance(double balance) throws NegativeAmountException {
this.balance = balance; }
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public double getBalance() { return balance; }
/** * Deposit * @param balance */ public void deposit(double balance) throws NegativeAmountException { // throw exception if deposit is negative if (balance < 0) { throw new NegativeAmountException("Negative amount"); } this.balance +=