Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

read information from a interface

  Asked By: Bakir    Date: Aug 28    Category: Java    Views: 633
  

i have a problem with a Lab i am doing.In the lab i am required to
read information from a interface and then display it. well the
problem is that when a client makes a transaction, lets say decides to
withdrawal money for a Account type - Cheque they are charged a small
bank fee.
i manage to get it working but, when i enter an amount of say $10
which is the balance, then withdrawal $9.80 i should also be charged a
$0.10 fee but instead i seem to get some funny figures.

here is the code.i've also put the Cheque class along with what i have
in the interface.


//here is the cheque class
public class Cheque extends Account {


//could have a private string for withdrawal so check that will need
//i could put it in the transaction class


// constructor that'll initialise n set parameters

Cheque () { }

//constructor that will use the super class

Cheque(String aType, String aNo, double aBal, double aRate ){
super(aType, aNo, aBal, aRate);

//should i have this for the set the interest rate to 2%
//public void setIntRate(double a) {
super.setIntRate(0.02);
}

public void perfTranx(double a) {
double b = getBalance();
if (getBalance() < 0.0) {
double x = b - 0.10;
setBalance(x);
} // get equal what it was double then add it and then - 10c


} // end of constructor initialise n set parameters
}


//here is the interface code bit
if (obj == btnAddData) {


if (! txtClientNo.getText().equals("")) {
Clt = new Client(txtClientNo.getText(), txtFirstname.getText(),
txtSurname.getText(), txtClientAge.getText());
if (accountType.getSelectedCheckbox().getLabel().equals("Cheque
Account")) {

double InterestRate = Double.parseDouble(txtInterestRate.getText());
double AccountBalance =
Double.parseDouble(txtAccountBalance.getText());

Acc = new Cheque(promptAccType.getText(),txtAccountNo.getText(),
AccountBalance, InterestRate);

System.out.println("\nNew Cheque created");
//to check that this is wrkn the if cheque bit

} else if (accountType.getSelectedCheckbox().getLabel().equals("EFT
Account")) {

double InterestRate = Double.parseDouble(txtInterestRate.getText());
double AccountBalance =
Double.parseDouble(txtAccountBalance.getText());

Acc = new EFTCard(promptAccType.getText(),txtAccountNo.getText(),
AccountBalance, InterestRate);
System.out.println("\nNew Cheque created");
//to check that this is wrkn the if eft is clikd bit

} // THIS closes the if statement of the if equals bit

Brh = new Branch
(branchArray[availableBranches.getSelectedIndex()].getBranchName(),
branchArray[availableBranches.getSelectedIndex()].getBranchCode());
} else {

results.setText("PLEASE ENTER A CLIENT NUMBER");
// no client number

}

} // end of if for btnAddData

/*********************************************************************
* if new transaction button is clicked then *
* then do the bits required to *
* read data from text fields and set the transaction object val *
* *
*********************************************************************/

if ( obj == btnNewTranx) {


if (!txtTranxAmount.getText().equals("")) {
double TrnAmt = Double.parseDouble(txtTranxAmount.getText());

if (Acc instanceof Cheque) {
Cheq.setBalance(Cheq.getBalance() + TrnAmt );


} else if (Acc instanceof Cheque) {
Eft.setBalance(Cheq.getBalance() + TrnAmt );

} //end of the if it was eftcard

} //this will close the transaction bit if the client does enter an
amount
}

/*********************************************************************
* if display button is clicked then *
* display values from text fields and text area *
* *
*********************************************************************/

if (obj == btnDisplay) {

results.setText(" First Name: " + Clt.getFirstName());
results.append("\n Surname: " + Clt.getSurname());
results.append("\n Customer Number: " + Clt.getClientNo());
results.append("\n Customer Age: " + Clt.getAge());


if (Acc instanceof Cheque) {

Cheq = (Cheque) Acc;

results.append("\n \n Account Type: " + Cheq.getAccType());
results.append("\n Account Number: " + Cheq.getAccNo());
results.append("\n Account Balance: " + Cheq.getBalance());
results.append("\n Account Interest Rate: " + Cheq.getIntRate());
results.append("\n Branch Name: " + Brh.getBranchName() + " " +
Brh.getBranchCode());

} else {
Eft = (EFTCard) Acc;

results.append("\n \n Account Type: " + Eft.getAccType());
results.append("\n Account Number: " + Eft.getAccNo());
results.append("\n Account Balance: " + Eft.getBalance());
results.append("\n Account Interest Rate: " + Eft.getIntRate());
results.append("\n Branch Name: " + Brh.getBranchName() + " " +
Brh.getBranchCode());

}//end of if for displaying the correct Acc type

} // end of if for btnDisplay

/*********************************************************************
* 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("");
txtClientNo.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

Share: 

 

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

 
Didn't find what you were looking for? Find more on read information from a interface Or get search suggestion and latest updates.




Tagged: