Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Java transaction code

  Asked By: Leona    Date: Dec 03    Category: Java    Views: 1845
  

I need help on processing a transaction amount.

Im not sure how to do this question.
this is my task:
The transaction amount is given as a positive number if a deposit is
being made and a negative number when funds are to be withdrawn.
This data is not processed unless the account number is given and a
valid amount is entered for the transaction (e.g entering- 300 when
the account has only $200 available is not valid)

This is the code for the interface
import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public classAssignment2 extends Applet
implements ActionListener {

// create an array to hold upto ten branch objects
private Branch branchArray[] = new Branch[10];

// declare and initialise variable to keep count of
// howmany branches there are
private int branchCount = 0;

// Declare variables for each type of component required for this
applet

// Buttons for client processing
Button btnNewClient, btnUpdateClient, btnDeleteClient;
Button btnSearchClient, btnNextClient, btnPreviousClient;

// Buttons for account and transaction processing
Button btnNewAccount, btnUpdateAccount, btnDeleteAccount;
Button btnSearchAccount, btnNextAccount, btnPreviousAccount;
Button btnNewTranx, btnPrintStatement;

// Buttons for misc processing
Button btnClear;

// declare variables for checkboxes and a checkbox group
Checkbox chequeAccount, EFTAccount;
CheckboxGroup accountType;

// choice list to hold branches that can be selected from
Choice availableBranches;

// labels and textfields for client processing
Label clientHeading;
Label promptSName, promptFName, promptClientPh, promptClientAge;
TextField txtSurname, txtFirstname, txtClientPh, txtClientAge;

// labels and textfields for account processing
Label accountHeading, accountTip;
Label promptAccNo, promptAccBalance, promptAccInterest,
promptAccType;
TextField txtAccountNo, txtAccountBalance, txtInterestRate,
txtTranxAmount;
Label promptTranxAmount, promptSelectBranch;

// general labels and text fields
Label header, footer;
TextArea results;

// panels for client processing
Panel pTextFields, pClientButtons, pClientStuff;

// account processing panels
Panel pAccountFields, pAccountButtons, pAccountStuff;

// miscelaneous panels used for formatting user interface
Panel pTop, pCentre, pBottom, pAllTextFields;
Panel pCheckBoxes, pBranches, pLists;

// variable used to create output string
String msg = "";


/***** init() method
*************************************************
* This method will create all required objects, add them to
the *
* applet, and register interest in events on some objects
through *
* listener
classes *

**********************************************************************
*/

public void init() {
resize(700,590);
setLayout(new BorderLayout(5, 5));

// create buttons for client processing
btnNewClient = new Button("New Client");
btnUpdateClient = new Button("Update Client");
btnDeleteClient = new Button("Delete Client");
btnSearchClient = new Button("Search Clients");
btnNextClient = new Button("Next>>");
btnPreviousClient = new Button("<<Previous");

// create account processing buttons
btnNewAccount = new Button("New Acct");
btnUpdateAccount= new Button("Update Acct");
btnDeleteAccount = new Button("Delete Acct");
btnSearchAccount = new Button("Search Accts");
btnNextAccount = new Button("Next>>");
btnPreviousAccount = new Button("<<Previous");
btnNewTranx = new Button("Perform Transaction");
btnPrintStatement = new Button("Print Statement");

// button to clear the form values
btnClear = new Button("Clear All");

accountType = new CheckboxGroup();
chequeAccount = new Checkbox("Cheque Account", accountType,
false);
EFTAccount = new Checkbox("EFT Account", accountType, true);

header = new Label("Client and Account Management Information
System", Label.CENTER);
footer = new Label("");

// create six default branch objects and add them to the branch
array
// and set counter to show howmany branches there are - assumes
the
// the appropriate constructor has been defined in the Branch
class
branchArray[0] = new Branch("Perth", "036060");
branchArray[1] = new Branch("Fremantle", "036080");
branchArray[2] = new Branch("Joondalup", "036989");
branchArray[3] = new Branch("Churchlands", "036018");
branchArray[4] = new Branch("MtLawley", "036605");
branchArray[5] = new Branch("Booragoon", "036090");
branchCount = 6;

// now add the default branch names and codes to choice list
// NOTE: you may have to change the getName() and getCode()
methods to match
// those you have defined in your Branch class
availableBranches = new Choice();
for (int indx = 0; indx < branchCount; indx++) {
availableBranches.add(branchArray[indx].getName() + " " +
branchArray[indx].getCode() );
} // end of for loop to add branch names and codes

// create labels and text fields required for client processing
clientHeading = new Label("Client Processing");
promptSName = new Label("Surname: ", Label.RIGHT);
promptFName = new Label("First Name: ", Label.RIGHT);
promptClientPh = new Label("Client Number: ", Label.RIGHT);
promptClientAge = new Label("Client Age: ", Label.RIGHT);
txtFirstname = new TextField(20);
txtSurname = new TextField(20);
txtClientPh = new TextField(18);
txtClientAge = new TextField(3);

// create account processing labels and text fields
accountHeading = new Label("Bank Account Processing");
accountTip = new Label("Client must exist before account is
created");
promptAccNo = new Label("Account Number: ", Label.RIGHT);
promptAccBalance = new Label("Balance: ", Label.RIGHT);
promptAccInterest = new Label("Interest Rate: ", Label.RIGHT);
promptTranxAmount = new Label("Transaction Amount $",
Label.RIGHT);

promptAccType = new Label("Account Type: ");
txtAccountNo = new TextField(20);
txtAccountBalance = new TextField(20);
txtInterestRate = new TextField(10);
txtTranxAmount = new TextField(10);
results = new TextArea(8, 40);


// start adding components to applet

add(header, BorderLayout.NORTH);

pCentre = new Panel();
pCentre.setLayout(new BorderLayout(5, 5));

// set up client information panel
pTextFields = new Panel();
pTextFields.setLayout(new GridLayout(3, 4));
pTextFields.add(clientHeading);
pTextFields.add(new Canvas());
pTextFields.add(new Canvas());
pTextFields.add(new Canvas());
pTextFields.add(promptSName);
pTextFields.add(txtSurname);
pTextFields.add(promptFName);
pTextFields.add(txtFirstname);
pTextFields.add(promptClientPh);
pTextFields.add(txtClientPh);
pTextFields.add(promptClientAge);
pTextFields.add(txtClientAge);

pClientButtons = new Panel();
pClientButtons.add(btnNewClient);
pClientButtons.add(btnUpdateClient);
pClientButtons.add(btnDeleteClient);
pClientButtons.add(btnSearchClient);
pClientButtons.add(btnPreviousClient);
pClientButtons.add(btnNextClient);

pClientStuff = new Panel();
pClientStuff.setLayout(new GridLayout(2, 1));
pClientStuff.add(pTextFields);
pClientStuff.add(pClientButtons);

// set up account and transaction information panel
pAccountFields = new Panel();
pAccountFields.setLayout(new GridLayout(3, 4));
pAccountFields.add(accountHeading);
pAccountFields.add(new Canvas());
pAccountFields.add(new Canvas());
pAccountFields.add(new Canvas());
pAccountFields.add(promptAccNo);
pAccountFields.add(txtAccountNo);
pAccountFields.add(promptAccBalance);
pAccountFields.add(txtAccountBalance);
pAccountFields.add(promptAccInterest);
pAccountFields.add(txtInterestRate);
pAccountFields.add(promptTranxAmount);
pAccountFields.add(txtTranxAmount);

pAccountButtons = new Panel();
pAccountButtons.add(btnNewAccount);
pAccountButtons.add(btnUpdateAccount);
pAccountButtons.add(btnDeleteAccount);
pAccountButtons.add(btnSearchAccount);
pAccountButtons.add(btnPreviousAccount);
pAccountButtons.add(btnNextAccount);

pAccountButtons.add(btnNewTranx);

pAccountStuff = new Panel();
pAccountStuff.setLayout(new GridLayout(2,1));
pAccountStuff.add(pAccountFields);
pAccountStuff.add(pAccountButtons);

pAllTextFields = new Panel();
pAllTextFields.setLayout(new GridLayout(2,1));
pAllTextFields.add(pAccountStuff);
pAllTextFields.add(pClientStuff);

// set up the panel that will hold the checkboxes and list of
branches
pCheckBoxes = new Panel();
pCheckBoxes.setLayout(new GridLayout(3, 1));
pCheckBoxes.add(promptAccType);
pCheckBoxes.add(EFTAccount);
pCheckBoxes.add(chequeAccount);

pBranches = new Panel();
pBranches.setLayout(new GridLayout(3, 1));
promptSelectBranch = new Label("Select Branch: ");
pBranches.add(promptSelectBranch);
pBranches.add(availableBranches);

pLists = new Panel();
pLists.setLayout(new GridLayout(1, 3));
pLists.add(pCheckBoxes);
pLists.add(pBranches);
pLists.add(new Canvas());


// add all the above panels to the panel that will be added to
the
// centre of the applet
pCentre.add(pLists, BorderLayout.NORTH);
pCentre.add(pAllTextFields, BorderLayout.CENTER);
pCentre.add(results, BorderLayout.SOUTH);

add(pCentre, BorderLayout.CENTER);

//add general processing buttons to panel, then add panel to
applet
pBottom = new Panel();
pBottom.add(btnPrintStatement);
pBottom.add(btnClear);

add(pBottom, BorderLayout.SOUTH);

add(new Label(" "), BorderLayout.EAST);
add(new Label(" "), BorderLayout.WEST);

// add listeners for client buttons
btnNewClient.addActionListener(this);
btnUpdateClient.addActionListener(this);
btnDeleteClient.addActionListener(this);
btnSearchClient.addActionListener(this);
btnNextClient.addActionListener(this);
btnPreviousClient.addActionListener(this);

btnNewAccount.addActionListener(this);
btnUpdateAccount.addActionListener(this);
btnDeleteAccount.addActionListener(this);
btnSearchAccount.addActionListener(this);
btnNewTranx.addActionListener(this);
btnNextAccount.addActionListener(this);
btnPreviousAccount.addActionListener(this);

btnPrintStatement.addActionListener(this);
btnClear.addActionListener(this);

} //end of init method


/***** actionPerformed() method
**************************************
* Method is called when an event occurs on any of the object
that *
* have been registered as an action
listener *

**********************************************************************
*/

public void actionPerformed (ActionEvent e) {
Object obj = e.getSource();


/****************************************************************
*****
* if new client button is clicked
then *
* create new client
object *
* read data from text fields and set the client object's
values *
* add this client object to array of client
objects *

*********************************************************************/
if (obj == btnNewClient) {

} // end of if for new client button


/*

... you need to add the rest of the code to
respond to the other buttons being clicked ...

... hope you didn't expect me to do all the work!!!!!

*/


/****************************************************************
*****
* if clear button is clicked
then *
* clear values from text fields and text
area *
* reset other form components to default
values *

*********************************************************************/
if (obj == btnClear) {
txtFirstname.setText("");
txtSurname.setText("");
txtClientPh.setText("");
txtClientAge.setText("");
txtAccountNo.setText("");
txtAccountBalance.setText("");
txtInterestRate.setText("");
txtTranxAmount.setText("");
results.setText("");
availableBranches.select(0);
accountType.setSelectedCheckbox(EFTAccount);
} // end of if for clear button

} //end of actionPerformed method

} //end of applet

Share: 

 

No Answers Found. Be the First, To Post Answer.

 
Didn't find what you were looking for? Find more on Java transaction code Or get search suggestion and latest updates.




Tagged: