Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi am encountering error in my javafx application in which after i enter numbers through my keypad ands press the please enter button it just

Hi am encountering error in my javafx application in which after i enter numbers through my keypad ands press the please enter button it just clears the text and nothing else. i will shaare the codexs with yuou please checjk the problemm
ATM.java
package atm.application;
import javafx.scene.control.TextArea;
public class ATM{
//attributes
private boolean userAuthenticated;
private int currentAccountNumber;
private TextArea text;
private BankDatabase bank;
//Main menu constants
private final static int BALANCE_INQUIRY =1;
private final static int WITHDRAWAL =2;
private final static int DEPOSIT =3;
private final static int EXIT =4;
public ATM(TextArea text){
this.text = text;
userAuthenticated = false;
currentAccountNumber =0;
bank = new BankDatabase();
}
private void authenticateUser(int accNo, int pin){
userAuthenticated = bank.authenticateUser(accNo, pin);
//authentication
if (userAuthenticated){
currentAccountNumber = accNo;
displayMessage("
Welcome");
}
else{
displayMessage("
Invalid accoung number of PIN. Please try again");
}
}
public void performTransactions(int sel){
Transaction currentTransaction = createTransaction(sel);
if (currentTransaction != null ){
currentTransaction.execute();
}
}
private Transaction createTransaction(int type){
Transaction transaction = null;
switch (type){
case BALANCE_INQUIRY:
transaction = new BalanceInquiry(currentAccountNumber,text, bank);
break;
case WITHDRAWAL:
transaction = new Withdrawal(currentAccountNumber,text,bank);
break;
case DEPOSIT:
transaction = new Deposit(currentAccountNumber, text, bank);
break;
}
return transaction;
}
private void displayMainMenu(){
text.clear();
displayMessageLine("
Main Menu");
displayMessageLine("1- View my balance");
displayMessageLine("2- Withdraw cash");
displayMessageLine("3- Deposit funds");
displayMessageLine("4- Exit
");
displayMessage("Enter a choice! ");
}
public void displayMessage(String msg){
text.appendText(msg);
}
public void displayMessageLine(String msg){
text.appendText(msg +"
");
}
}
AtmApp
package atm.application;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import javafx.scene.control.TextArea;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.BorderPane;
import javafx.geometry.Insets;
public static void main(String[] args){
launch(args);
}
@Override
public void start(Stage primarystage){
primarystage.setTitle("Application for ATM");
text = new TextArea();
text.setEditable(false);
Button[] digit = new Button[10];
for(int i =0; i <10; i++){
digit[i]= new Button(String.valueOf(i));
final int dig = i;
digit[i].setOnAction(e->{
String current = text.getText();
text.setText(current + dig);});}
Button enter = new Button("Please enter");
enter.setOnAction(e->{
try{
int in = Integer.parseInt(text.getText().trim());
atm.performTransactions(in);
text.clear();
}
catch(NumberFormatException ex){
displayMessage("Enter a valid input");
}
}
);
GridPane grid = new GridPane();
grid.setPadding(new Insets(20));
grid.setHgap(10);
grid.setVgap(10);
grid.add(text,0,0,3,1);
for(int i =1, dig =1; i <4; i++){
for(int k =0; k <3; k++, dig++){
grid.add(digit[dig],k,i);
}
}
grid.add(digit[0],1,4);
grid.add(enter,2,4);
Scene s = new Scene(grid,500,400);
primarystage.setScene(s);
primarystage.show();
atm = new ATM(text);
}
private void displayMessage(String msg){
text.appendText(msg+"
");
}
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Online Systems For Physicians And Medical Professionals How To Use And Access Databases

Authors: Harley Bjelland

1st Edition

1878487442, 9781878487445

More Books

Students also viewed these Databases questions