Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Main
- ==========================================================================================================================================
- package sample;
- import javafx.application.Application;
- import javafx.event.ActionEvent;
- import javafx.event.EventHandler;
- import javafx.geometry.Pos;
- import javafx.scene.Scene;
- import javafx.scene.control.Button;
- import javafx.scene.control.TextField;
- import javafx.scene.control.PasswordField;
- import javafx.scene.control.Label;
- import javafx.scene.layout.GridPane;
- import javafx.scene.layout.StackPane;
- import javafx.scene.text.Font;
- import javafx.stage.Stage;
- public class Main<Textfield> extends Application {
- //Logic Code Objects
- Transactions trans = new Transactions();
- History setTrue = new History();
- Queue list = new Queue();
- Stage stage1,stage2;
- Scene scene1,scene2;
- //scene 1 objects
- Button loginButton= new Button();
- Label cardNumberLabel;
- PasswordField cardNumberField;
- //scene 2 objects
- Button depositButton = new Button("Deposit");
- Button withdrawButton = new Button("Withdraw");
- Button balanceButton = new Button("Balance Inquiry");
- Button nextButton = new Button("Next Transaction");
- Button prevButton = new Button("Previous Transaction");
- Button transactionsButton = new Button("Last 5 Transactions");
- Button logoutButton = new Button("Logout");
- Label label = new Label();
- public static void main(String[] args) {
- launch(args);
- }
- @Override
- public void start(Stage primaryStage) throws Exception {
- primaryStage.setTitle("Automated Teller Machine");
- LoginAuthentication authentication = new LoginAuthentication();
- //AlertBox alertBox = new AlertBox();
- cardNumberLabel = new Label("Card Number: ");
- cardNumberField = new PasswordField();
- loginButton.setText("Login");
- Label validationLabel = new Label();
- GridPane grid1,grid2;
- grid2 = new GridPane();
- //scene 1 appearance
- grid1 = new GridPane();
- grid1.add(cardNumberLabel,0,0);
- grid1.add(cardNumberField,1,0);
- grid1.add(loginButton,1,1);
- grid1.add(validationLabel,1,2);
- grid1.setAlignment(Pos.CENTER);
- //scene 2 appearance
- grid2.add(depositButton,0,0);
- grid2.add(withdrawButton,0,1);
- grid2.add(balanceButton,0,2);
- grid2.add(logoutButton,2,3);
- grid2.add(nextButton,1,0);
- grid2.add(prevButton,1,1);
- grid2.add(transactionsButton,2,0);
- grid2.add(label,1,2);
- grid2.setVgap(35);
- grid2.setHgap(35);
- scene1 = new Scene(grid1,450,250);
- scene2 = new Scene(grid2,450,250);
- loginButton.setOnAction(new EventHandler<ActionEvent>() {
- @Override
- public void handle(ActionEvent event) {
- String cardNumber = cardNumberField.getText();
- boolean valid = authentication.validate(cardNumber);
- if (valid)
- primaryStage.setScene(scene2);
- else
- AlertBox.displayLoginError();
- }
- });
- logoutButton.setOnAction(e->{
- primaryStage.setScene(scene1);
- AlertBox.displayExit();
- });
- depositButton.setOnAction(e->{
- double value = AlertBox.displayNumbers();
- trans.setDeposit(value);
- setTrue.setDeposit(true);
- list.push(value);
- label.setText("Successful operation.");
- setTrue.setDeposit(false);
- });
- withdrawButton.setOnAction(e->{
- double value = Validation.checkValidity();
- trans.setWithdraw(value);
- setTrue.setWithdraw(true);
- list.push(value);
- label.setText("Successful operation.");
- setTrue.setWithdraw(false);
- });
- balanceButton.setOnAction(e-> label.setText("Current Balance: "+trans.getBalance()+"$"));
- nextButton.setOnAction(e->{
- if(((list.getPtr()%5)+1)!=4){
- if(list.queue[(list.getPtr()+2)%5].equals(" ") || list.queue[(list.getPtr()+2)%5].isEmpty()){
- label.setText("Current balance: "+Transactions.getBalance()+"$");
- nextButton.setDisable(true);
- }
- else
- label.setText(list.showNext());
- }
- else
- AlertBox.displayNextPrevError();
- });
- prevButton.setOnAction(e->{
- if(((list.getPtr()%5)+1) ==0)
- AlertBox.displayNextPrevError();
- else{
- label.setText(list.showPrev());
- nextButton.setDisable(false);
- }
- });
- transactionsButton.setOnAction(e-> AlertBox.displayTransactions());
- primaryStage.setScene(scene1);
- primaryStage.show();
- }
- }
- //TODO SET VALUE OF DEPOSIT AND WITHDRAW TO TRUE
- ==========================================================================================================================================
- Transactions
- ==========================================================================================================================================
- package sample;
- public class Transactions
- {
- private static double deposit,withdraw,balance=0;
- public void setDeposit(double deposit) { balance = balance + deposit; }
- public void setWithdraw(double withdraw)
- {
- balance = balance - withdraw;
- }
- public static double getBalance()
- {
- return balance;
- }
- }
- ==========================================================================================================================================
- Queue
- ==========================================================================================================================================
- package sample;
- public class Queue
- {
- History lastTransaction = new History();
- static String queue[] = new String[]{" "," "," "," "," "};
- public int getPtr() {
- return ptr-1;
- }
- int ptr=0;
- int rear=0; // to insert
- int size=0;
- int index=-1;
- public void push(double data)
- {
- if(lastTransaction.isWithdraw())
- {
- queue[rear%5] = " Withdraw: "+data+"$";
- rear = (rear + 1) % 5;
- size++;
- ++ptr;
- ++index;
- }
- else if (lastTransaction.isDeposit())
- {
- queue[rear%5] =" Deposit: "+data+"$";
- rear++;
- size++;
- ++ptr;
- ++index;
- }
- }
- public int getSize()
- {
- if (size>5)
- size=5;
- return size;
- }
- public String showPrev(){ return queue[(--ptr)%5]; }
- public String showNext(){ return queue[(++ptr)%5]; }
- }
- ==========================================================================================================================================
- History
- ==========================================================================================================================================
- package sample;
- public class History
- {
- private static boolean deposit = false;
- private static boolean withdraw = false;
- public static boolean isDeposit()
- {
- return deposit;
- }
- public static void setDeposit(boolean d)
- { deposit = d; }
- public static boolean isWithdraw()
- { return withdraw; }
- public static void setWithdraw(boolean w)
- { withdraw = w; }
- }
- ==========================================================================================================================================
- LoginAuthentication
- ==========================================================================================================================================
- package sample;
- import java.util.HashMap;
- public class LoginAuthentication {
- public boolean validate(String password){
- boolean validationResult=false;
- if (password.equals("1111"))
- validationResult=true;
- return validationResult;
- }
- }
- ==========================================================================================================================================
- AlertBox
- ==========================================================================================================================================
- package sample;
- import javafx.scene.paint.Color;
- import javafx.scene.text.Font;
- import javafx.stage.*;
- import javafx.scene.*;
- import javafx.scene.layout.*;
- import javafx.scene.control.*;
- import javafx.geometry.*;
- import javafx.event.ActionEvent;
- public class AlertBox {
- public static void displayLoginError(){
- Stage window1 = new Stage();
- window1.setTitle("Error!");
- window1.initModality(Modality.APPLICATION_MODAL);
- window1.setMinWidth(300);
- window1.setMinHeight(200);
- Label label = new Label();
- label.setText("Incorrect entry!\nRetry.");
- label.setFont(new Font("Verdana",15));
- label.setTextFill(Color.web("#b22222"));
- Button closeButton = new Button("Close");
- closeButton.setOnAction(e -> window1.close());
- VBox layout = new VBox(10);
- layout.getChildren().addAll(label,closeButton);
- layout.setAlignment(Pos.CENTER);
- Scene scene = new Scene(layout);
- window1.setScene(scene);
- window1.showAndWait();
- }
- public static void displayNextPrevError(){
- Stage window1 = new Stage();
- window1.setTitle("Error!");
- window1.initModality(Modality.APPLICATION_MODAL);
- window1.setMinWidth(300);
- window1.setMinHeight(200);
- Label label = new Label();
- label.setText("No further records!");
- label.setFont(new Font("Verdana",15));
- label.setTextFill(Color.web("#b22222"));
- Button closeButton = new Button("Close");
- closeButton.setOnAction(e -> window1.close());
- VBox layout = new VBox(10);
- layout.getChildren().addAll(label,closeButton);
- layout.setAlignment(Pos.CENTER);
- Scene scene = new Scene(layout);
- window1.setScene(scene);
- window1.showAndWait();
- }
- public static double displayNumbers() {
- Stage window = new Stage();
- GridPane grid = new GridPane();
- window.initModality(Modality.APPLICATION_MODAL);
- window.setMinHeight(200);
- window.setMinWidth(300);
- window.setTitle("Transactions");
- TextField textField = new TextField();
- Button one = new Button("1");
- Button two = new Button("2");
- Button three = new Button("3");
- Button four = new Button("4");
- Button five = new Button("5");
- Button six = new Button("6");
- Button seven = new Button("7");
- Button eight = new Button("8");
- Button nine = new Button("9");
- Button zero = new Button("0");
- Button enterButton = new Button("Enter");
- Label label = new Label("Enter value: ");
- grid.add(one, 0, 0);
- grid.add(two, 1, 0);
- grid.add(three, 2, 0);
- grid.add(four, 0, 1);
- grid.add(five, 1, 1);
- grid.add(six, 2, 1);
- grid.add(seven, 0, 2);
- grid.add(eight, 1, 2);
- grid.add(nine, 2, 2);
- grid.add(zero, 1, 3);
- grid.add(textField,3,2);
- grid.add(enterButton, 3, 3);
- grid.add(label,3,1);
- grid.setVgap(10);
- grid.setHgap(10);
- one.setOnAction(e-> textField.setText(textField.getText()+"1"));
- two.setOnAction(e-> textField.setText(textField.getText()+"2"));
- three.setOnAction(e-> textField.setText(textField.getText()+"3"));
- four.setOnAction(e-> textField.setText(textField.getText()+"4"));
- five.setOnAction(e-> textField.setText(textField.getText()+"5"));
- six.setOnAction(e-> textField.setText(textField.getText()+"6"));
- seven.setOnAction(e-> textField.setText(textField.getText()+"7"));
- eight.setOnAction(e-> textField.setText(textField.getText()+"8"));
- nine.setOnAction(e-> textField.setText(textField.getText()+"9"));
- zero.setOnAction(e-> textField.setText(textField.getText()+"0"));
- Scene scene = new Scene(grid);
- window.setScene(scene);
- enterButton.setOnAction(e -> window.close());
- window.showAndWait();
- String value = textField.getText();
- if(value == null || value.isEmpty()) { value = "0"; }
- return Double.valueOf(value);
- }
- public static void displayExit(){
- Stage window1 = new Stage();
- window1.setTitle("Thank you!");
- window1.initModality(Modality.APPLICATION_MODAL);
- window1.setMinWidth(300);
- window1.setMinHeight(200);
- Label label = new Label();
- label.setText("Thank you for using our services.\n Please do not forget your card!");
- label.setFont(new Font("Verdana",15));
- label.setTextFill(Color.web("#0000ff"));
- Button closeButton = new Button("Close");
- closeButton.setOnAction(e -> window1.close());
- VBox layout = new VBox(10);
- layout.getChildren().addAll(label,closeButton);
- layout.setAlignment(Pos.CENTER);
- Scene scene = new Scene(layout);
- window1.setScene(scene);
- window1.showAndWait();
- }
- public static void displayTransactions(){
- Queue lastTransactions = new Queue();
- Button closeButton = new Button("Close");
- Label label0 = new Label(lastTransactions.queue[0]);
- Label label1 = new Label(lastTransactions.queue[1]);
- Label label2 = new Label(lastTransactions.queue[2]);
- Label label3 = new Label(lastTransactions.queue[3]);
- Label label4 = new Label(lastTransactions.queue[4]);
- label0.setVisible(true);
- label1.setVisible(true);
- label2.setVisible(true);
- label3.setVisible(true);
- label4.setVisible(true);
- Stage stage = new Stage();
- stage.setTitle("Last Five Transaction");
- stage.initModality(Modality.APPLICATION_MODAL);
- stage.setMinWidth(320);
- stage.setMinHeight(250);
- GridPane grid = new GridPane();
- grid.add(label0,0,0);
- grid.add(label1,0,1);
- grid.add(label2,0,2);
- grid.add(label3,0,3);
- grid.add(label4,0,4);
- grid.add(closeButton,1,5);
- grid.setHgap(15);
- grid.setVgap(15);
- closeButton.setOnAction(e -> stage.close());
- Scene scene = new Scene(grid);
- stage.setScene(scene);
- stage.showAndWait();
- }
- public static void displayNegativeBalanceChecker(){
- Stage window1 = new Stage();
- window1.setTitle("Error!");
- window1.initModality(Modality.APPLICATION_MODAL);
- window1.setMinWidth(300);
- window1.setMinHeight(200);
- Label label = new Label();
- label.setText("Insufficient amount!\nCurrent balance: "+ String.valueOf(Transactions.getBalance()));
- label.setFont(new Font("Verdana",15));
- label.setTextFill(Color.web("#b22222"));
- Button closeButton = new Button("Close");
- closeButton.setOnAction(e -> window1.close());
- VBox layout = new VBox(10);
- layout.getChildren().addAll(label,closeButton);
- layout.setAlignment(Pos.CENTER);
- Scene scene = new Scene(layout);
- window1.setScene(scene);
- window1.showAndWait();
- }
- }
- ==========================================================================================================================================
- Validation
- ==========================================================================================================================================
- package sample;
- import javafx.scene.control.Alert;
- public class Validation {
- public static boolean isFlag() {
- return flag;
- }
- public static void setFlag(boolean flag) {
- Validation.flag = flag;
- }
- private static boolean flag = false;
- private static boolean disableFlag = false;
- static double value;
- public static double checkValidity(){
- do{
- value = AlertBox.displayNumbers();
- if(value<Transactions.getBalance()||value==0)
- setFlag(true);
- else
- AlertBox.displayNegativeBalanceChecker();
- }while(!isFlag());
- setFlag(false);
- return value;
- }
- }
- ==========================================================================================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement