| BankAccount |
|---|
|
double sum String name |
| BankAccount(String name) double balance() void deposit(double amount) void withdraw(double amount) String getName() |
/**
* This class represents a Bank Account
*
* @author Gregory M Kesden
* @version 1.0.0
*/
public class BankAccount {
// not visible in API
private double sum; // Balance in dollar plus cents as decimal fraction
private String name; // The name of the BankAccount used, for example, to label it
/**
* Initializes the bank account's balance account
* to $0.00 and sets its name
*
* @param name The name of the account.
*/
public BankAccount(String name) {
}
/**
* Return the current balance of the account with the amount
* of money specified as a decimal number such that the integer
* represents the dollars and the fractional component the cents.
*
* @return the current balance of the account
*/
public double balance() {
}
/**
* Increase the balance of the account by the specified amount
* of money. The amount of money is specified as a decimal number with
* the integer representing the dollars and the fractional component
* representing the cents.
*
* @param amount amount of money to add to the balance
*/
public void deposit(double amount) {
}
/**
* Decrease the balance of the account by the specified
* amount of money. The amount of money is specified as a decimal number
* with the integer representing the dollars and the fractional component
* representing the cents.
*
* @param amount amount of money to subtract from the balance.
*/
public void withdraw(double amount) {
}
/**
* Returns the name of the account
*
* @return returns the name of the account as a String.
*/
public String getName() {
}
}
| BankAccountApplet |
|---|
| TextField amountField Panel opsPad Panel mainPanel CheckboxGroup ops Checkbox depositBox, withdrawBox, balanceBox Button executeButton Label msgLabel BankAccount acct |
| void init() void actionPerformed(ActionEvent evt) void windowActivated(WindowEvent e) void windowClosed(WindowEvent e) void windowClosing(WindowEvent e) void windowDeactivated(WindowEvent e) void windowDeiconified(WindowEvent e) void windowIconified(WindowEvent e) void windowOpened(WindowEvent e) |
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/**
* This class allow to the user to deposit, withdraw or
* obtain the balance of a bank account
*
* @author Gregory M Kesden
* @version 1.0.0
*/
public class BankAccountApplet extends Applet
implements ActionListener, WindowListener {
/*
* This should allow the user to enter a dollar amount for deposit or
* withdrawel, as display the balance, if requested by the user.
*/
private TextField amountField;
// A panel used to hold the three checkboxes in a vertical configuration.
private Panel opsPad;
// A panel used to hold all of the other panels in position
private Panel mainPanel;
// These are used to allow the user to select the next operation.
private Checkbox depositBox, withdrawBox, balanceBox;
// A panel used to hold the three checkboxes in a vertical configuration.
private CheckboxGroup ops;
// The button that the user presses to initiate the selected operation.
private Button executeButton;
// The label that instructs the user about the proper input format.
private Label msgLabel;
// The bank account that actually keeps track of the money
private BankAccount acct;
/**
* Create and install the GUI components, including the text field,
* the button, the check boxes, and the instruction label, as well
* as create the new bank account object.
*/
public void init() {
// This has to be public, so the browser or appletviewer can call it
}
/*
* Ask the BankAccount object to add the amount specified by the user
* to the account.
*/
private void deposit() {
// Notice that this is private -- it is not directly exposed to the user
}
/*
* Ask the BankAccount object to subtract the amount specified by the
* user from the account.
*/
private void withdraw() {
// Notice that this is private -- it is not directly exposed to the user
}
/*
* Ask the BankAccount object to report the current balance of the account,
* and then display this amount in the text field.
*/
private void balance() {
// Notice that this is private -- it is not directly exposed to the user
}
/**
* Takes one of the three actions described below, depending on the state
* of the operation checkboxes
*
* - deposit
* - withdraw
* - balance
*
* @param evt the event generated
*/
public void actionPerformed(ActionEvent evt) {
/*
* We called this Execute() in our design, but Java requires this
* this name, because it is associated with the GUI component. This isn't
* a problem. It is just one of the details of a real-world environment
* basically, a similar situation to actionPerformed(), above.
*/
}
/**
* method contains empty body
*
* @param e not used
*/
public void windowActivated(WindowEvent e) {}
/**
* method contains empty body
*
* @param e not used
*/
public void windowClosed(WindowEvent e) {}
/**
* When the close box is clicked or the close window menu item
* is chosen, this method causes the application to terminate
*
* @param e not used
*/
public void windowClosing(WindowEvent e) {
}
/**
* method contains empty body
*
* @param e not used
*/
public void windowDeactivated(WindowEvent e) {}
/**
* method contains empty body
*
* @param e not used
*/
public void windowDeiconified(WindowEvent e) {}
/**
* method contains empty body
*
* @param e not used
*/
public void windowIconified(WindowEvent e) {}
/**
* method contains empty body
*
* @param e not used
*/
public void windowOpened(WindowEvent e) {}
}
| Previou page | Next page |