CECS 475 LAB ASSIGNMENT 7
Assigned date: 4/17
Due date: 4/24
15 points
Create a event-driven GUI application to process a bank account withdraw and deposit.
Implement the event listener with two different approaches:
Partial coding for the UI bank account application
import javax.swing.JFrame;
/**
A GUI for manipulating a bank account.
*/
public class BankAccountViewer
{
private static final double INITIAL_BALANCE = 1000;
public static void main(String[] args)
{
BankAccount account = new BankAccount(INITIAL_BALANCE);
// construct the frame
JFrame frame = new BankAccountFrame(account);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
___________________
/**
A bank account has a balance that can be changed by
deposits and withdrawals.
*/
public class BankAccount implements Comparable<BankAccount>
{
private double balance;
/**
Constructs a bank account with a zero balance.
*/
public BankAccount()
{
balance = 0;
}
/**
Constructs a bank account with a given balance.
@param initialBalance the initial balance
*/
public BankAccount(double initialBalance)
{
balance = initialBalance;
}
/**
Deposits money into the bank account.
@param amount the amount to deposit
*/
public void deposit(double amount)
{
double newBalance = balance + amount;
balance = newBalance;
}
/**
Withdraws money from the bank account.
@param amount the amount to withdraw
*/
public void withdraw(double amount)
{
double newBalance = balance - amount;
balance = newBalance;
}
/**
Gets the current balance of the bank account.
@return the current balance
*/
public double getBalance()
{
return balance;
}
public int compareTo(BankAccount other)
{
double d = balance - other.balance;
if (d < 0)
return -1;
if (d > 0)
return 1;
return 0;
}
}
Grading