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 and press the please enter button it just

Hi am encountering error in my javafx application in which after i enter numbers through my keypad and press the please enter button it just clears the text and does nothing else. i will share the codes with you please check the problem i have attached ATM, AtmApp code down below and for reference of other codes of the app i am attaching the images which contains Account.java and BalanceInquiry.java, BankDatabase.java and CashDispenser.java, Deposit.java, DepositSlot.java and Withdrawal.java
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;
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);
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);}
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+"
");
}}
image text in transcribed

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

Step: 3

blur-text-image

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

Visual Basic6 Database Programming

Authors: John W. Fronckowiak, David J. Helda

1st Edition

0764532545, 978-0764532542

More Books

Students also viewed these Databases questions