diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..39d4cec --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +bin/code/Account.class +bin/code/BalanceInquiry.class +bin/code/BankDatabase.class +bin/code/Deposit.class +bin/code/Screen.class +bin/code/Withdrawal.class diff --git a/bin/ATM.class b/bin/ATM.class deleted file mode 100644 index 76543bf..0000000 Binary files a/bin/ATM.class and /dev/null differ diff --git a/bin/ATMCaseStudy.class b/bin/ATMCaseStudy.class deleted file mode 100644 index 607c10d..0000000 Binary files a/bin/ATMCaseStudy.class and /dev/null differ diff --git a/bin/Account.class b/bin/Account.class deleted file mode 100644 index 5d2d636..0000000 Binary files a/bin/Account.class and /dev/null differ diff --git a/bin/BalanceInquiry.class b/bin/BalanceInquiry.class deleted file mode 100644 index 48f8e6a..0000000 Binary files a/bin/BalanceInquiry.class and /dev/null differ diff --git a/bin/BankDatabase.class b/bin/BankDatabase.class deleted file mode 100644 index 429aec1..0000000 Binary files a/bin/BankDatabase.class and /dev/null differ diff --git a/bin/CashDispenser.class b/bin/CashDispenser.class deleted file mode 100644 index b8cedba..0000000 Binary files a/bin/CashDispenser.class and /dev/null differ diff --git a/bin/Deposit.class b/bin/Deposit.class deleted file mode 100644 index 57b0c3f..0000000 Binary files a/bin/Deposit.class and /dev/null differ diff --git a/bin/DepositSlot.class b/bin/DepositSlot.class deleted file mode 100644 index a2664ad..0000000 Binary files a/bin/DepositSlot.class and /dev/null differ diff --git a/bin/Keypad.class b/bin/Keypad.class deleted file mode 100644 index 9b066e2..0000000 Binary files a/bin/Keypad.class and /dev/null differ diff --git a/bin/Screen.class b/bin/Screen.class deleted file mode 100644 index a036758..0000000 Binary files a/bin/Screen.class and /dev/null differ diff --git a/bin/Transaction.class b/bin/Transaction.class deleted file mode 100644 index 1330b55..0000000 Binary files a/bin/Transaction.class and /dev/null differ diff --git a/bin/Withdrawal.class b/bin/Withdrawal.class deleted file mode 100644 index 291d645..0000000 Binary files a/bin/Withdrawal.class and /dev/null differ diff --git a/bin/code/Buisness_logic/Account.class b/bin/code/Buisness_logic/Account.class new file mode 100644 index 0000000..0c79b45 Binary files /dev/null and b/bin/code/Buisness_logic/Account.class differ diff --git a/bin/code/Buisness_logic/CashDispenser.class b/bin/code/Buisness_logic/CashDispenser.class new file mode 100644 index 0000000..bf59adc Binary files /dev/null and b/bin/code/Buisness_logic/CashDispenser.class differ diff --git a/bin/code/Buisness_logic/Euro.class b/bin/code/Buisness_logic/Euro.class new file mode 100644 index 0000000..9edeb45 Binary files /dev/null and b/bin/code/Buisness_logic/Euro.class differ diff --git a/bin/code/Buisness_logic/Transaction.class b/bin/code/Buisness_logic/Transaction.class new file mode 100644 index 0000000..b93bff5 Binary files /dev/null and b/bin/code/Buisness_logic/Transaction.class differ diff --git a/bin/code/Database/BankDatabase.class b/bin/code/Database/BankDatabase.class new file mode 100644 index 0000000..c9ec4d2 Binary files /dev/null and b/bin/code/Database/BankDatabase.class differ diff --git a/bin/code/GUI/ATM.class b/bin/code/GUI/ATM.class new file mode 100644 index 0000000..d832ed2 Binary files /dev/null and b/bin/code/GUI/ATM.class differ diff --git a/bin/code/GUI/ATMCaseStudy.class b/bin/code/GUI/ATMCaseStudy.class new file mode 100644 index 0000000..19cfd11 Binary files /dev/null and b/bin/code/GUI/ATMCaseStudy.class differ diff --git a/bin/code/GUI/BalanceInquiry.class b/bin/code/GUI/BalanceInquiry.class new file mode 100644 index 0000000..a92ba14 Binary files /dev/null and b/bin/code/GUI/BalanceInquiry.class differ diff --git a/bin/code/GUI/Deposit.class b/bin/code/GUI/Deposit.class new file mode 100644 index 0000000..1bc032c Binary files /dev/null and b/bin/code/GUI/Deposit.class differ diff --git a/bin/code/GUI/DepositSlot.class b/bin/code/GUI/DepositSlot.class new file mode 100644 index 0000000..63c58c0 Binary files /dev/null and b/bin/code/GUI/DepositSlot.class differ diff --git a/bin/code/GUI/Keypad.class b/bin/code/GUI/Keypad.class new file mode 100644 index 0000000..9b02035 Binary files /dev/null and b/bin/code/GUI/Keypad.class differ diff --git a/bin/code/GUI/Screen.class b/bin/code/GUI/Screen.class new file mode 100644 index 0000000..a835e79 Binary files /dev/null and b/bin/code/GUI/Screen.class differ diff --git a/bin/code/GUI/Withdrawal.class b/bin/code/GUI/Withdrawal.class new file mode 100644 index 0000000..ffa4e32 Binary files /dev/null and b/bin/code/GUI/Withdrawal.class differ diff --git a/componenti.txt b/componenti.txt new file mode 100644 index 0000000..0268bd6 --- /dev/null +++ b/componenti.txt @@ -0,0 +1 @@ +Nikolla Dionis 5196050 \ No newline at end of file diff --git a/lib/hamcrest-core-1.3.jar b/lib/hamcrest-core-1.3.jar new file mode 100644 index 0000000..9d5fe16 Binary files /dev/null and b/lib/hamcrest-core-1.3.jar differ diff --git a/lib/junit-4.13.2.jar b/lib/junit-4.13.2.jar new file mode 100644 index 0000000..6da55d8 Binary files /dev/null and b/lib/junit-4.13.2.jar differ diff --git a/src/Account.java b/src/code/Buisness_logic/Account.java similarity index 57% rename from src/Account.java rename to src/code/Buisness_logic/Account.java index c308eca..25aa8ae 100644 --- a/src/Account.java +++ b/src/code/Buisness_logic/Account.java @@ -1,17 +1,17 @@ +package code.Buisness_logic; // Account.java + // Represents a bank account -public class Account -{ +public class Account { private int accountNumber; // account number private int pin; // PIN for authentication - private double availableBalance; // funds available for withdrawal - private double totalBalance; // funds available + pending deposits + private Euro availableBalance; // funds available for withdrawal + private Euro totalBalance; // funds available + pending deposits // Account constructor initializes attributes - public Account( int theAccountNumber, int thePIN, - double theAvailableBalance, double theTotalBalance ) - { + public Account(int theAccountNumber, int thePIN, + Euro theAvailableBalance, Euro theTotalBalance) { accountNumber = theAccountNumber; pin = thePIN; availableBalance = theAvailableBalance; @@ -19,58 +19,51 @@ public Account( int theAccountNumber, int thePIN, } // end Account constructor // determines whether a user-specified PIN matches PIN in Account - public boolean validatePIN( int userPIN ) - { - if ( userPIN == pin ) + public boolean validatePIN(int userPIN) { + if (userPIN == pin) return true; else return false; } // end method validatePIN - + // returns available balance - public double getAvailableBalance() - { + public Euro getAvailableBalance() { return availableBalance; } // end getAvailableBalance // returns the total balance - public double getTotalBalance() - { + public Euro getTotalBalance() { return totalBalance; } // end method getTotalBalance // credits an amount to the account - public void credit( double amount ) - { - totalBalance += amount; // add to total balance + public void credit(Euro amount) { + totalBalance.somma(amount); // add to total balance } // end method credit // debits an amount from the account - public void debit( double amount ) - { - availableBalance -= amount; // subtract from available balance - totalBalance -= amount; // subtract from total balance + public void debit(Euro amount) { + availableBalance.sottrai(amount); // subtract from available balance + totalBalance.sottrai(amount); // subtract from total balance } // end method debit // returns account number - public int getAccountNumber() - { - return accountNumber; + public int getAccountNumber() { + return accountNumber; } // end method getAccountNumber } // end class Account - /************************************************************************** - * (C) Copyright 1992-2007 by Deitel & Associates, Inc. and * - * Pearson Education, Inc. All Rights Reserved. * - * * - * DISCLAIMER: The authors and publisher of this book have used their * - * best efforts in preparing the book. These efforts include the * - * development, research, and testing of the theories and programs * - * to determine their effectiveness. The authors and publisher make * - * no warranty of any kind, expressed or implied, with regard to these * + * (C) Copyright 1992-2007 by Deitel & Associates, Inc. and * + * Pearson Education, Inc. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * * programs or to the documentation contained in these books. The authors * - * and publisher shall not be liable in any event for incidental or * - * consequential damages in connection with, or arising out of, the * - * furnishing, performance, or use of these programs. * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * *************************************************************************/ \ No newline at end of file diff --git a/src/CashDispenser.java b/src/code/Buisness_logic/CashDispenser.java similarity index 72% rename from src/CashDispenser.java rename to src/code/Buisness_logic/CashDispenser.java index b249faf..c80e6fa 100644 --- a/src/CashDispenser.java +++ b/src/code/Buisness_logic/CashDispenser.java @@ -1,50 +1,46 @@ +package code.Buisness_logic; // CashDispenser.java + // Represents the cash dispenser of the ATM -public class CashDispenser -{ +public class CashDispenser { // the default initial number of bills in the cash dispenser private final static int INITIAL_COUNT = 500; private int count; // number of $20 bills remaining - + // no-argument CashDispenser constructor initializes count to default - public CashDispenser() - { + public CashDispenser() { count = INITIAL_COUNT; // set count attribute to default } // end CashDispenser constructor // simulates dispensing of specified amount of cash - public void dispenseCash( int amount ) - { + public void dispenseCash(int amount) { int billsRequired = amount / 20; // number of $20 bills required count -= billsRequired; // update the count of bills } // end method dispenseCash // indicates whether cash dispenser can dispense desired amount - public boolean isSufficientCashAvailable( int amount ) - { + public boolean isSufficientCashAvailable(int amount) { int billsRequired = amount / 20; // number of $20 bills required - if ( count >= billsRequired ) + if (count >= billsRequired) return true; // enough bills available - else + else return false; // not enough bills available } // end method isSufficientCashAvailable } // end class CashDispenser - - /************************************************************************** - * (C) Copyright 1992-2007 by Deitel & Associates, Inc. and * - * Pearson Education, Inc. All Rights Reserved. * - * * - * DISCLAIMER: The authors and publisher of this book have used their * - * best efforts in preparing the book. These efforts include the * - * development, research, and testing of the theories and programs * - * to determine their effectiveness. The authors and publisher make * - * no warranty of any kind, expressed or implied, with regard to these * + * (C) Copyright 1992-2007 by Deitel & Associates, Inc. and * + * Pearson Education, Inc. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * * programs or to the documentation contained in these books. The authors * - * and publisher shall not be liable in any event for incidental or * - * consequential damages in connection with, or arising out of, the * - * furnishing, performance, or use of these programs. * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * *************************************************************************/ \ No newline at end of file diff --git a/src/DepositSlot.java b/src/code/Buisness_logic/DepositSlot.java similarity index 68% rename from src/DepositSlot.java rename to src/code/Buisness_logic/DepositSlot.java index 64e02c2..33ba1f3 100644 --- a/src/DepositSlot.java +++ b/src/code/Buisness_logic/DepositSlot.java @@ -1,29 +1,27 @@ +package code.Buisness_logic; // DepositSlot.java + // Represents the deposit slot of the ATM -public class DepositSlot -{ - // indicates whether envelope was received (always returns true, +public class DepositSlot { + // indicates whether envelope was received (always returns true, // because this is only a software simulation of a real deposit slot) - public boolean isEnvelopeReceived() - { + public boolean isEnvelopeReceived() { return true; // deposit envelope was received } // end method isEnvelopeReceived } // end class DepositSlot - - /************************************************************************** - * (C) Copyright 1992-2007 by Deitel & Associates, Inc. and * - * Pearson Education, Inc. All Rights Reserved. * - * * - * DISCLAIMER: The authors and publisher of this book have used their * - * best efforts in preparing the book. These efforts include the * - * development, research, and testing of the theories and programs * - * to determine their effectiveness. The authors and publisher make * - * no warranty of any kind, expressed or implied, with regard to these * + * (C) Copyright 1992-2007 by Deitel & Associates, Inc. and * + * Pearson Education, Inc. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * * programs or to the documentation contained in these books. The authors * - * and publisher shall not be liable in any event for incidental or * - * consequential damages in connection with, or arising out of, the * - * furnishing, performance, or use of these programs. * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * *************************************************************************/ \ No newline at end of file diff --git a/src/code/Buisness_logic/Euro.java b/src/code/Buisness_logic/Euro.java new file mode 100644 index 0000000..aa86d5b --- /dev/null +++ b/src/code/Buisness_logic/Euro.java @@ -0,0 +1,54 @@ +package code.Buisness_logic; + +public class Euro { + + private long valore; + + public Euro(long euro, long cent) { + if (euro >= 0) { + valore = euro * 100 + cent; + } else { + valore = euro * 100 - cent; + } + } + + public Euro(double d) { + valore = (long) (d * 100); + } + + public long getValore() { + return valore; + } + + public Euro somma(Euro e) { + this.valore = this.valore + e.getValore(); + return this; + } + + public Euro sottrai(Euro e) { + this.valore = this.valore - e.getValore(); + return this; + } + + public boolean ugualeA(Euro e) { + if (valore == e.getValore()) + return true; + else + return false; + } + + public boolean minoreDi(Euro e) { + if (valore <= e.getValore()) + return true; + else + return false; + } + + public String stampa() { + return (double) valore / 100 + " euro"; + } + + public void setValore(long valore) { + this.valore = valore; + } +} \ No newline at end of file diff --git a/src/Transaction.java b/src/code/Buisness_logic/Transaction.java similarity index 67% rename from src/Transaction.java rename to src/code/Buisness_logic/Transaction.java index 508fea8..bb390b0 100644 --- a/src/Transaction.java +++ b/src/code/Buisness_logic/Transaction.java @@ -1,36 +1,36 @@ +package code.Buisness_logic; // Transaction.java + +import code.Database.BankDatabase; +import code.GUI.*; + // Abstract superclass Transaction represents an ATM transaction -public abstract class Transaction -{ +public abstract class Transaction { private int accountNumber; // indicates account involved private Screen screen; // ATM's screen private BankDatabase bankDatabase; // account info database // Transaction constructor invoked by subclasses using super() - public Transaction( int userAccountNumber, Screen atmScreen, - BankDatabase atmBankDatabase ) - { + public Transaction(int userAccountNumber, Screen atmScreen, + BankDatabase atmBankDatabase) { accountNumber = userAccountNumber; screen = atmScreen; bankDatabase = atmBankDatabase; } // end Transaction constructor - // return account number - public int getAccountNumber() - { - return accountNumber; + // return account number + public int getAccountNumber() { + return accountNumber; } // end method getAccountNumber // return reference to screen - public Screen getScreen() - { + public Screen getScreen() { return screen; } // end method getScreen // return reference to bank database - public BankDatabase getBankDatabase() - { + public BankDatabase getBankDatabase() { return bankDatabase; } // end method getBankDatabase @@ -38,19 +38,17 @@ public BankDatabase getBankDatabase() abstract public void execute(); } // end class Transaction - - /************************************************************************** - * (C) Copyright 1992-2007 by Deitel & Associates, Inc. and * - * Pearson Education, Inc. All Rights Reserved. * - * * - * DISCLAIMER: The authors and publisher of this book have used their * - * best efforts in preparing the book. These efforts include the * - * development, research, and testing of the theories and programs * - * to determine their effectiveness. The authors and publisher make * - * no warranty of any kind, expressed or implied, with regard to these * + * (C) Copyright 1992-2007 by Deitel & Associates, Inc. and * + * Pearson Education, Inc. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * * programs or to the documentation contained in these books. The authors * - * and publisher shall not be liable in any event for incidental or * - * consequential damages in connection with, or arising out of, the * - * furnishing, performance, or use of these programs. * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * *************************************************************************/ \ No newline at end of file diff --git a/src/BankDatabase.java b/src/code/Database/BankDatabase.java similarity index 56% rename from src/BankDatabase.java rename to src/code/Database/BankDatabase.java index 3978497..a92d347 100644 --- a/src/BankDatabase.java +++ b/src/code/Database/BankDatabase.java @@ -1,26 +1,27 @@ +package code.Database; // BankDatabase.java + +import code.Buisness_logic.Account; +import code.Buisness_logic.Euro; + // Represents the bank account information database -public class BankDatabase -{ +public class BankDatabase { private Account accounts[]; // array of Accounts - + // no-argument BankDatabase constructor initializes accounts - public BankDatabase() - { - accounts = new Account[ 2 ]; // just 2 accounts for testing - accounts[ 0 ] = new Account( 12345, 54321, 1000.0, 1200.0 ); - accounts[ 1 ] = new Account( 98765, 56789, 200.0, 200.0 ); + public BankDatabase() { + accounts = new Account[2]; // just 2 accounts for testing + accounts[0] = new Account(12345, 54321, new Euro(1000.0), new Euro(1200.0)); + accounts[1] = new Account(98765, 56789, new Euro(200.0), new Euro(200.0)); } // end no-argument BankDatabase constructor - + // retrieve Account object containing specified account number - private Account getAccount( int accountNumber ) - { + private Account getAccount(int accountNumber) { // loop through accounts searching for matching account number - for ( Account currentAccount : accounts ) - { + for (Account currentAccount : accounts) { // return current account if match found - if ( currentAccount.getAccountNumber() == accountNumber ) + if (currentAccount.getAccountNumber() == accountNumber) return currentAccount; } // end for @@ -29,56 +30,49 @@ private Account getAccount( int accountNumber ) // determine whether user-specified account number and PIN match // those of an account in the database - public boolean authenticateUser( int userAccountNumber, int userPIN ) - { + public boolean authenticateUser(int userAccountNumber, int userPIN) { // attempt to retrieve the account with the account number - Account userAccount = getAccount( userAccountNumber ); + Account userAccount = getAccount(userAccountNumber); // if account exists, return result of Account method validatePIN - if ( userAccount != null ) - return userAccount.validatePIN( userPIN ); + if (userAccount != null) + return userAccount.validatePIN(userPIN); else return false; // account number not found, so return false } // end method authenticateUser // return available balance of Account with specified account number - public double getAvailableBalance( int userAccountNumber ) - { - return getAccount( userAccountNumber ).getAvailableBalance(); + public Euro getAvailableBalance(int userAccountNumber) { + return getAccount(userAccountNumber).getAvailableBalance(); } // end method getAvailableBalance // return total balance of Account with specified account number - public double getTotalBalance( int userAccountNumber ) - { - return getAccount( userAccountNumber ).getTotalBalance(); + public Euro getTotalBalance(int userAccountNumber) { + return getAccount(userAccountNumber).getTotalBalance(); } // end method getTotalBalance // credit an amount to Account with specified account number - public void credit( int userAccountNumber, double amount ) - { - getAccount( userAccountNumber ).credit( amount ); + public void credit(int userAccountNumber, Euro amount) { + getAccount(userAccountNumber).credit(amount); } // end method credit // debit an amount from of Account with specified account number - public void debit( int userAccountNumber, double amount ) - { - getAccount( userAccountNumber ).debit( amount ); + public void debit(int userAccountNumber, Euro amount) { + getAccount(userAccountNumber).debit(amount); } // end method debit } // end class BankDatabase - - /************************************************************************** - * (C) Copyright 1992-2007 by Deitel & Associates, Inc. and * - * Pearson Education, Inc. All Rights Reserved. * - * * - * DISCLAIMER: The authors and publisher of this book have used their * - * best efforts in preparing the book. These efforts include the * - * development, research, and testing of the theories and programs * - * to determine their effectiveness. The authors and publisher make * - * no warranty of any kind, expressed or implied, with regard to these * + * (C) Copyright 1992-2007 by Deitel & Associates, Inc. and * + * Pearson Education, Inc. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * * programs or to the documentation contained in these books. The authors * - * and publisher shall not be liable in any event for incidental or * - * consequential damages in connection with, or arising out of, the * - * furnishing, performance, or use of these programs. * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * *************************************************************************/ \ No newline at end of file diff --git a/src/ATM.java b/src/code/GUI/ATM.java similarity index 61% rename from src/ATM.java rename to src/code/GUI/ATM.java index aa3d187..7ebfe52 100644 --- a/src/ATM.java +++ b/src/code/GUI/ATM.java @@ -1,8 +1,14 @@ +package code.GUI; // ATM.java + +import code.Buisness_logic.CashDispenser; +import code.Buisness_logic.DepositSlot; +import code.Buisness_logic.Transaction; +import code.Database.BankDatabase; + // Represents an automated teller machine -public class ATM -{ +public class ATM { private boolean userAuthenticated; // whether user is authenticated private int currentAccountNumber; // current user's account number private Screen screen; // ATM's screen @@ -18,130 +24,116 @@ public class ATM private static final int EXIT = 4; // no-argument ATM constructor initializes instance variables - public ATM() - { + public ATM() { userAuthenticated = false; // user is not authenticated to start currentAccountNumber = 0; // no current account number to start screen = new Screen(); // create screen - keypad = new Keypad(); // create keypad + keypad = new Keypad(); // create keypad cashDispenser = new CashDispenser(); // create cash dispenser depositSlot = new DepositSlot(); // create deposit slot bankDatabase = new BankDatabase(); // create acct info database } // end no-argument ATM constructor - // start ATM - public void run() - { + // start ATM + public void run() { // welcome and authenticate user; perform transactions - while ( true ) - { + while (true) { // loop while user is not yet authenticated - while ( !userAuthenticated ) - { - screen.displayMessageLine( "\nWelcome!" ); + while (!userAuthenticated) { + screen.displayMessageLine("\nWelcome!"); authenticateUser(); // authenticate user } // end while - - performTransactions(); // user is now authenticated + + performTransactions(); // user is now authenticated userAuthenticated = false; // reset before next ATM session - currentAccountNumber = 0; // reset before next ATM session - screen.displayMessageLine( "\nThank you! Goodbye!" ); - } // end while + currentAccountNumber = 0; // reset before next ATM session + screen.displayMessageLine("\nThank you! Goodbye!"); + } // end while } // end method run // attempts to authenticate user against database - private void authenticateUser() - { - screen.displayMessage( "\nPlease enter your account number: " ); + private void authenticateUser() { + screen.displayMessage("\nPlease enter your account number: "); int accountNumber = keypad.getInput(); // input account number - screen.displayMessage( "\nEnter your PIN: " ); // prompt for PIN + screen.displayMessage("\nEnter your PIN: "); // prompt for PIN int pin = keypad.getInput(); // input PIN - + // set userAuthenticated to boolean value returned by database - userAuthenticated = - bankDatabase.authenticateUser( accountNumber, pin ); - + userAuthenticated = bankDatabase.authenticateUser(accountNumber, pin); + // check whether authentication succeeded - if ( userAuthenticated ) - { + if (userAuthenticated) { currentAccountNumber = accountNumber; // save user's account # } // end if else - screen.displayMessageLine( - "Invalid account number or PIN. Please try again." ); + screen.displayMessageLine( + "Invalid account number or PIN. Please try again."); } // end method authenticateUser // display the main menu and perform transactions - private void performTransactions() - { + private void performTransactions() { // local variable to store transaction currently being processed Transaction currentTransaction = null; - + boolean userExited = false; // user has not chosen to exit // loop while user has not chosen option to exit system - while ( !userExited ) - { + while (!userExited) { // show main menu and get user selection int mainMenuSelection = displayMainMenu(); // decide how to proceed based on user's menu selection - switch ( mainMenuSelection ) - { + switch (mainMenuSelection) { // user chose to perform one of three transaction types - case BALANCE_INQUIRY: - case WITHDRAWAL: + case BALANCE_INQUIRY: + case WITHDRAWAL: case DEPOSIT: // initialize as new object of chosen type - currentTransaction = - createTransaction( mainMenuSelection ); + currentTransaction = createTransaction(mainMenuSelection); currentTransaction.execute(); // execute transaction - break; + break; case EXIT: // user chose to terminate session - screen.displayMessageLine( "\nExiting the system..." ); + screen.displayMessageLine("\nExiting the system..."); userExited = true; // this ATM session should end break; default: // user did not enter an integer from 1-4 - screen.displayMessageLine( - "\nYou did not enter a valid selection. Try again." ); + screen.displayMessageLine( + "\nYou did not enter a valid selection. Try again."); break; } // end switch } // end while } // end method performTransactions - + // display the main menu and return an input selection - private int displayMainMenu() - { - screen.displayMessageLine( "\nMain menu:" ); - screen.displayMessageLine( "1 - View my balance" ); - screen.displayMessageLine( "2 - Withdraw cash" ); - screen.displayMessageLine( "3 - Deposit funds" ); - screen.displayMessageLine( "4 - Exit\n" ); - screen.displayMessage( "Enter a choice: " ); + private int displayMainMenu() { + screen.displayMessageLine("\nMain menu:"); + screen.displayMessageLine("1 - View my balance"); + screen.displayMessageLine("2 - Withdraw cash"); + screen.displayMessageLine("3 - Deposit funds"); + screen.displayMessageLine("4 - Exit\n"); + screen.displayMessage("Enter a choice: "); return keypad.getInput(); // return user's selection } // end method displayMainMenu - + // return object of specified Transaction subclass - private Transaction createTransaction( int type ) - { + private Transaction createTransaction(int type) { Transaction temp = null; // temporary Transaction variable - - // determine which type of Transaction to create - switch ( type ) - { + + // determine which type of Transaction to create + switch (type) { case BALANCE_INQUIRY: // create new BalanceInquiry transaction - temp = new BalanceInquiry( - currentAccountNumber, screen, bankDatabase ); + temp = new BalanceInquiry( + currentAccountNumber, screen, bankDatabase); break; case WITHDRAWAL: // create new Withdrawal transaction - temp = new Withdrawal( currentAccountNumber, screen, - bankDatabase, keypad, cashDispenser ); - break; + temp = new Withdrawal(currentAccountNumber, screen, + bankDatabase, keypad, cashDispenser); + break; case DEPOSIT: // create new Deposit transaction - temp = new Deposit( currentAccountNumber, screen, - bankDatabase, keypad, depositSlot ); + temp = new Deposit(currentAccountNumber, screen, + bankDatabase, keypad, depositSlot); break; } // end switch @@ -149,19 +141,17 @@ private Transaction createTransaction( int type ) } // end method createTransaction } // end class ATM - - /************************************************************************** - * (C) Copyright 1992-2007 by Deitel & Associates, Inc. and * - * Pearson Education, Inc. All Rights Reserved. * - * * - * DISCLAIMER: The authors and publisher of this book have used their * - * best efforts in preparing the book. These efforts include the * - * development, research, and testing of the theories and programs * - * to determine their effectiveness. The authors and publisher make * - * no warranty of any kind, expressed or implied, with regard to these * + * (C) Copyright 1992-2007 by Deitel & Associates, Inc. and * + * Pearson Education, Inc. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * * programs or to the documentation contained in these books. The authors * - * and publisher shall not be liable in any event for incidental or * - * consequential damages in connection with, or arising out of, the * - * furnishing, performance, or use of these programs. * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * *************************************************************************/ \ No newline at end of file diff --git a/src/ATMCaseStudy.java b/src/code/GUI/ATMCaseStudy.java similarity index 60% rename from src/ATMCaseStudy.java rename to src/code/GUI/ATMCaseStudy.java index b9033bd..a77abfa 100644 --- a/src/ATMCaseStudy.java +++ b/src/code/GUI/ATMCaseStudy.java @@ -1,29 +1,27 @@ +package code.GUI; // ATMCaseStudy.java + // Driver program for the ATM case study -public class ATMCaseStudy -{ +public class ATMCaseStudy { // main method creates and runs the ATM - public static void main( String[] args ) - { - ATM theATM = new ATM(); + public static void main(String[] args) { + ATM theATM = new ATM(); theATM.run(); } // end main -} // end class ATMCaseStudy - - +} // end class ATMCaseStudy /************************************************************************** - * (C) Copyright 1992-2007 by Deitel & Associates, Inc. and * - * Pearson Education, Inc. All Rights Reserved. * - * * - * DISCLAIMER: The authors and publisher of this book have used their * - * best efforts in preparing the book. These efforts include the * - * development, research, and testing of the theories and programs * - * to determine their effectiveness. The authors and publisher make * - * no warranty of any kind, expressed or implied, with regard to these * + * (C) Copyright 1992-2007 by Deitel & Associates, Inc. and * + * Pearson Education, Inc. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * * programs or to the documentation contained in these books. The authors * - * and publisher shall not be liable in any event for incidental or * - * consequential damages in connection with, or arising out of, the * - * furnishing, performance, or use of these programs. * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * *************************************************************************/ \ No newline at end of file diff --git a/src/BalanceInquiry.java b/src/code/GUI/BalanceInquiry.java similarity index 51% rename from src/BalanceInquiry.java rename to src/code/GUI/BalanceInquiry.java index d45fa6a..19762d0 100644 --- a/src/BalanceInquiry.java +++ b/src/code/GUI/BalanceInquiry.java @@ -1,53 +1,52 @@ +package code.GUI; // BalanceInquiry.java + +import code.Buisness_logic.Euro; +import code.Buisness_logic.Transaction; +import code.Database.BankDatabase; + // Represents a balance inquiry ATM transaction -public class BalanceInquiry extends Transaction -{ +public class BalanceInquiry extends Transaction { // BalanceInquiry constructor - public BalanceInquiry( int userAccountNumber, Screen atmScreen, - BankDatabase atmBankDatabase ) - { - super( userAccountNumber, atmScreen, atmBankDatabase ); + public BalanceInquiry(int userAccountNumber, Screen atmScreen, + BankDatabase atmBankDatabase) { + super(userAccountNumber, atmScreen, atmBankDatabase); } // end BalanceInquiry constructor // performs the transaction - public void execute() - { + public void execute() { // get references to bank database and screen BankDatabase bankDatabase = getBankDatabase(); Screen screen = getScreen(); // get the available balance for the account involved - double availableBalance = - bankDatabase.getAvailableBalance( getAccountNumber() ); + Euro availableBalance = bankDatabase.getAvailableBalance(getAccountNumber()); // get the total balance for the account involved - double totalBalance = - bankDatabase.getTotalBalance( getAccountNumber() ); - + Euro totalBalance = bankDatabase.getTotalBalance(getAccountNumber()); + // display the balance information on the screen - screen.displayMessageLine( "\nBalance Information:" ); - screen.displayMessage( " - Available balance: " ); - screen.displayDollarAmount( availableBalance ); - screen.displayMessage( "\n - Total balance: " ); - screen.displayDollarAmount( totalBalance ); - screen.displayMessageLine( "" ); + screen.displayMessageLine("\nBalance Information:"); + screen.displayMessage(" - Available balance: "); + screen.displayDollarAmount(availableBalance); + screen.displayMessage("\n - Total balance: "); + screen.displayDollarAmount(totalBalance); + screen.displayMessageLine(""); } // end method execute } // end class BalanceInquiry - - /************************************************************************** - * (C) Copyright 1992-2007 by Deitel & Associates, Inc. and * - * Pearson Education, Inc. All Rights Reserved. * - * * - * DISCLAIMER: The authors and publisher of this book have used their * - * best efforts in preparing the book. These efforts include the * - * development, research, and testing of the theories and programs * - * to determine their effectiveness. The authors and publisher make * - * no warranty of any kind, expressed or implied, with regard to these * + * (C) Copyright 1992-2007 by Deitel & Associates, Inc. and * + * Pearson Education, Inc. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * * programs or to the documentation contained in these books. The authors * - * and publisher shall not be liable in any event for incidental or * - * consequential damages in connection with, or arising out of, the * - * furnishing, performance, or use of these programs. * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * *************************************************************************/ \ No newline at end of file diff --git a/src/Deposit.java b/src/code/GUI/Deposit.java similarity index 52% rename from src/Deposit.java rename to src/code/GUI/Deposit.java index 916ef70..b3355e4 100644 --- a/src/Deposit.java +++ b/src/code/GUI/Deposit.java @@ -1,20 +1,25 @@ +package code.GUI; // Deposit.java + +import code.Buisness_logic.DepositSlot; +import code.Buisness_logic.Euro; +import code.Buisness_logic.Transaction; +import code.Database.BankDatabase; + // Represents a deposit ATM transaction -public class Deposit extends Transaction -{ - private double amount; // amount to deposit +public class Deposit extends Transaction { + private Euro amount; // amount to deposit private Keypad keypad; // reference to keypad private DepositSlot depositSlot; // reference to deposit slot private final static int CANCELED = 0; // constant for cancel option // Deposit constructor - public Deposit( int userAccountNumber, Screen atmScreen, - BankDatabase atmBankDatabase, Keypad atmKeypad, - DepositSlot atmDepositSlot ) - { + public Deposit(int userAccountNumber, Screen atmScreen, + BankDatabase atmBankDatabase, Keypad atmKeypad, + DepositSlot atmDepositSlot) { // initialize superclass variables - super( userAccountNumber, atmScreen, atmBankDatabase ); + super(userAccountNumber, atmScreen, atmBankDatabase); // initialize references to keypad and deposit slot keypad = atmKeypad; @@ -22,81 +27,74 @@ public Deposit( int userAccountNumber, Screen atmScreen, } // end Deposit constructor // perform transaction - public void execute() - { + public void execute() { BankDatabase bankDatabase = getBankDatabase(); // get reference Screen screen = getScreen(); // get reference - amount = promptForDepositAmount(); // get deposit amount from user + amount = new Euro(promptForDepositAmount()); // get deposit amount from user // check whether user entered a deposit amount or canceled - if ( amount != CANCELED ) - { + if (amount.getValore() != CANCELED) { // request deposit envelope containing specified amount - screen.displayMessage( - "\nPlease insert a deposit envelope containing " ); - screen.displayDollarAmount( amount ); - screen.displayMessageLine( "." ); + screen.displayMessage( + "\nPlease insert a deposit envelope containing "); + screen.displayDollarAmount(amount); + screen.displayMessageLine("."); // receive deposit envelope boolean envelopeReceived = depositSlot.isEnvelopeReceived(); // check whether deposit envelope was received - if ( envelopeReceived ) - { - screen.displayMessageLine( "\nYour envelope has been " + - "received.\nNOTE: The money just deposited will not " + - "be available until we verify the amount of any " + - "enclosed cash and your checks clear." ); - + if (envelopeReceived) { + screen.displayMessageLine("\nYour envelope has been " + + "received.\nNOTE: The money just deposited will not " + + "be available until we verify the amount of any " + + "enclosed cash and your checks clear."); + // credit account to reflect the deposit - bankDatabase.credit( getAccountNumber(), amount ); + bankDatabase.credit(getAccountNumber(), amount); } // end if else // deposit envelope not received { - screen.displayMessageLine( "\nYou did not insert an " + - "envelope, so the ATM has canceled your transaction." ); + screen.displayMessageLine("\nYou did not insert an " + + "envelope, so the ATM has canceled your transaction."); } // end else - } // end if + } // end if else // user canceled instead of entering amount { - screen.displayMessageLine( "\nCanceling transaction..." ); + screen.displayMessageLine("\nCanceling transaction..."); } // end else } // end method execute - // prompt user to enter a deposit amount in cents - private double promptForDepositAmount() - { + // prompt user to enter a deposit amount in cents + private double promptForDepositAmount() { Screen screen = getScreen(); // get reference to screen // display the prompt - screen.displayMessage( "\nPlease enter a deposit amount in " + - "CENTS (or 0 to cancel): " ); + screen.displayMessage("\nPlease enter a deposit amount in " + + "CENTS (or 0 to cancel): "); int input = keypad.getInput(); // receive input of deposit amount - + // check whether the user canceled or entered a valid amount - if ( input == CANCELED ) + if (input == CANCELED) return CANCELED; - else - { - return ( double ) input / 100; // return dollar amount + else { + return (double) input / 100; // return dollar amount } // end else } // end method promptForDepositAmount } // end class Deposit - - /************************************************************************** - * (C) Copyright 1992-2007 by Deitel & Associates, Inc. and * - * Pearson Education, Inc. All Rights Reserved. * - * * - * DISCLAIMER: The authors and publisher of this book have used their * - * best efforts in preparing the book. These efforts include the * - * development, research, and testing of the theories and programs * - * to determine their effectiveness. The authors and publisher make * - * no warranty of any kind, expressed or implied, with regard to these * + * (C) Copyright 1992-2007 by Deitel & Associates, Inc. and * + * Pearson Education, Inc. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * * programs or to the documentation contained in these books. The authors * - * and publisher shall not be liable in any event for incidental or * - * consequential damages in connection with, or arising out of, the * - * furnishing, performance, or use of these programs. * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * *************************************************************************/ \ No newline at end of file diff --git a/src/Keypad.java b/src/code/GUI/Keypad.java similarity index 63% rename from src/Keypad.java rename to src/code/GUI/Keypad.java index cd035c7..0ecdee9 100644 --- a/src/Keypad.java +++ b/src/code/GUI/Keypad.java @@ -1,37 +1,34 @@ +package code.GUI; + // Keypad.java // Represents the keypad of the ATM import java.util.Scanner; // program uses Scanner to obtain user input -public class Keypad -{ +public class Keypad { private Scanner input; // reads data from the command line - + // no-argument constructor initializes the Scanner - public Keypad() - { - input = new Scanner( System.in ); + public Keypad() { + input = new Scanner(System.in); } // end no-argument Keypad constructor - // return an integer value entered by user - public int getInput() - { - return input.nextInt(); // we assume that user enters an integer + // return an integer value entered by user + public int getInput() { + return input.nextInt(); // we assume that user enters an integer } // end method getInput -} // end class Keypad - - +} // end class Keypad /************************************************************************** - * (C) Copyright 1992-2007 by Deitel & Associates, Inc. and * - * Pearson Education, Inc. All Rights Reserved. * - * * - * DISCLAIMER: The authors and publisher of this book have used their * - * best efforts in preparing the book. These efforts include the * - * development, research, and testing of the theories and programs * - * to determine their effectiveness. The authors and publisher make * - * no warranty of any kind, expressed or implied, with regard to these * + * (C) Copyright 1992-2007 by Deitel & Associates, Inc. and * + * Pearson Education, Inc. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * * programs or to the documentation contained in these books. The authors * - * and publisher shall not be liable in any event for incidental or * - * consequential damages in connection with, or arising out of, the * - * furnishing, performance, or use of these programs. * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * *************************************************************************/ \ No newline at end of file diff --git a/src/Screen.java b/src/code/GUI/Screen.java similarity index 56% rename from src/Screen.java rename to src/code/GUI/Screen.java index 44d3f30..3a4335a 100644 --- a/src/Screen.java +++ b/src/code/GUI/Screen.java @@ -1,40 +1,38 @@ +package code.GUI; // Screen.java + +import code.Buisness_logic.Euro; + // Represents the screen of the ATM -public class Screen -{ +public class Screen { // displays a message without a carriage return - public void displayMessage( String message ) - { - System.out.print( message ); + public void displayMessage(String message) { + System.out.print(message); } // end method displayMessage // display a message with a carriage return - public void displayMessageLine( String message ) - { - System.out.println( message ); + public void displayMessageLine(String message) { + System.out.println(message); } // end method displayMessageLine // display a dollar amount - public void displayDollarAmount( double amount ) - { - System.out.printf( "$%,.2f", amount ); - } // end method displayDollarAmount + public void displayDollarAmount(Euro amount) { + System.out.printf("$%,.2f", (double) amount.getValore()); + } // end method displayDollarAmount } // end class Screen - - /************************************************************************** - * (C) Copyright 1992-2007 by Deitel & Associates, Inc. and * - * Pearson Education, Inc. All Rights Reserved. * - * * - * DISCLAIMER: The authors and publisher of this book have used their * - * best efforts in preparing the book. These efforts include the * - * development, research, and testing of the theories and programs * - * to determine their effectiveness. The authors and publisher make * - * no warranty of any kind, expressed or implied, with regard to these * + * (C) Copyright 1992-2007 by Deitel & Associates, Inc. and * + * Pearson Education, Inc. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * * programs or to the documentation contained in these books. The authors * - * and publisher shall not be liable in any event for incidental or * - * consequential damages in connection with, or arising out of, the * - * furnishing, performance, or use of these programs. * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * *************************************************************************/ \ No newline at end of file diff --git a/src/Withdrawal.java b/src/code/GUI/Withdrawal.java similarity index 55% rename from src/Withdrawal.java rename to src/code/GUI/Withdrawal.java index 6e0af62..12763c9 100644 --- a/src/Withdrawal.java +++ b/src/code/GUI/Withdrawal.java @@ -1,8 +1,14 @@ +package code.GUI; // Withdrawal.java + +import code.Buisness_logic.CashDispenser; +import code.Buisness_logic.Euro; +import code.Buisness_logic.Transaction; +import code.Database.BankDatabase; + // Represents a withdrawal ATM transaction -public class Withdrawal extends Transaction -{ +public class Withdrawal extends Transaction { private int amount; // amount to withdraw private Keypad keypad; // reference to keypad private CashDispenser cashDispenser; // reference to cash dispenser @@ -11,120 +17,110 @@ public class Withdrawal extends Transaction private final static int CANCELED = 6; // Withdrawal constructor - public Withdrawal( int userAccountNumber, Screen atmScreen, - BankDatabase atmBankDatabase, Keypad atmKeypad, - CashDispenser atmCashDispenser ) - { + public Withdrawal(int userAccountNumber, Screen atmScreen, + BankDatabase atmBankDatabase, Keypad atmKeypad, + CashDispenser atmCashDispenser) { // initialize superclass variables - super( userAccountNumber, atmScreen, atmBankDatabase ); - + super(userAccountNumber, atmScreen, atmBankDatabase); + // initialize references to keypad and cash dispenser keypad = atmKeypad; cashDispenser = atmCashDispenser; } // end Withdrawal constructor // perform transaction - public void execute() - { + public void execute() { boolean cashDispensed = false; // cash was not dispensed yet - double availableBalance; // amount available for withdrawal + Euro availableBalance; // amount available for withdrawal // get references to bank database and screen - BankDatabase bankDatabase = getBankDatabase(); + BankDatabase bankDatabase = getBankDatabase(); Screen screen = getScreen(); // loop until cash is dispensed or the user cancels - do - { - // obtain a chosen withdrawal amount from the user + do { + // obtain a chosen withdrawal amount from the user amount = displayMenuOfAmounts(); - + // check whether user chose a withdrawal amount or canceled - if ( amount != CANCELED ) - { + if (amount != CANCELED) { // get available balance of account involved - availableBalance = - bankDatabase.getAvailableBalance( getAccountNumber() ); - - // check whether the user has enough money in the account - if ( amount <= availableBalance ) - { + availableBalance = bankDatabase.getAvailableBalance(getAccountNumber()); + + // check whether the user has enough money in the account + if (amount <= availableBalance.getValore()) { // check whether the cash dispenser has enough money - if ( cashDispenser.isSufficientCashAvailable( amount ) ) - { + if (cashDispenser.isSufficientCashAvailable(amount)) { // update the account involved to reflect withdrawal - bankDatabase.debit( getAccountNumber(), amount ); - - cashDispenser.dispenseCash( amount ); // dispense cash + bankDatabase.debit(getAccountNumber(), new Euro(amount)); + + cashDispenser.dispenseCash(amount); // dispense cash cashDispensed = true; // cash was dispensed // instruct user to take cash - screen.displayMessageLine( - "\nPlease take your cash now." ); + screen.displayMessageLine( + "\nPlease take your cash now."); } // end if else // cash dispenser does not have enough cash - screen.displayMessageLine( - "\nInsufficient cash available in the ATM." + - "\n\nPlease choose a smaller amount." ); + screen.displayMessageLine( + "\nInsufficient cash available in the ATM." + + "\n\nPlease choose a smaller amount."); } // end if else // not enough money available in user's account { - screen.displayMessageLine( - "\nInsufficient funds in your account." + - "\n\nPlease choose a smaller amount." ); + screen.displayMessageLine( + "\nInsufficient funds in your account." + + "\n\nPlease choose a smaller amount."); } // end else } // end if - else // user chose cancel menu option + else // user chose cancel menu option { - screen.displayMessageLine( "\nCanceling transaction..." ); + screen.displayMessageLine("\nCanceling transaction..."); return; // return to main menu because user canceled } // end else - } while ( !cashDispensed ); + } while (!cashDispensed); } // end method execute // display a menu of withdrawal amounts and the option to cancel; // return the chosen amount or 0 if the user chooses to cancel - private int displayMenuOfAmounts() - { + private int displayMenuOfAmounts() { int userChoice = 0; // local variable to store return value Screen screen = getScreen(); // get screen reference - + // array of amounts to correspond to menu numbers int amounts[] = { 0, 20, 40, 60, 100, 200 }; // loop while no valid choice has been made - while ( userChoice == 0 ) - { + while (userChoice == 0) { // display the menu - screen.displayMessageLine( "\nWithdrawal Menu:" ); - screen.displayMessageLine( "1 - $20" ); - screen.displayMessageLine( "2 - $40" ); - screen.displayMessageLine( "3 - $60" ); - screen.displayMessageLine( "4 - $100" ); - screen.displayMessageLine( "5 - $200" ); - screen.displayMessageLine( "6 - Cancel transaction" ); - screen.displayMessage( "\nChoose a withdrawal amount: " ); + screen.displayMessageLine("\nWithdrawal Menu:"); + screen.displayMessageLine("1 - $20"); + screen.displayMessageLine("2 - $40"); + screen.displayMessageLine("3 - $60"); + screen.displayMessageLine("4 - $100"); + screen.displayMessageLine("5 - $200"); + screen.displayMessageLine("6 - Cancel transaction"); + screen.displayMessage("\nChoose a withdrawal amount: "); int input = keypad.getInput(); // get user input through keypad // determine how to proceed based on the input value - switch ( input ) - { - case 1: // if the user chose a withdrawal amount + switch (input) { + case 1: // if the user chose a withdrawal amount case 2: // (i.e., chose option 1, 2, 3, 4 or 5), return the case 3: // corresponding amount from amounts array case 4: case 5: - userChoice = amounts[ input ]; // save user's choice - break; + userChoice = amounts[input]; // save user's choice + break; case CANCELED: // the user chose to cancel userChoice = CANCELED; // save user's choice break; default: // the user did not enter a value from 1-6 - screen.displayMessageLine( - "\nIvalid selection. Try again." ); + screen.displayMessageLine( + "\nIvalid selection. Try again."); } // end switch } // end while @@ -132,19 +128,17 @@ private int displayMenuOfAmounts() } // end method displayMenuOfAmounts } // end class Withdrawal - - /************************************************************************** - * (C) Copyright 1992-2007 by Deitel & Associates, Inc. and * - * Pearson Education, Inc. All Rights Reserved. * - * * - * DISCLAIMER: The authors and publisher of this book have used their * - * best efforts in preparing the book. These efforts include the * - * development, research, and testing of the theories and programs * - * to determine their effectiveness. The authors and publisher make * - * no warranty of any kind, expressed or implied, with regard to these * + * (C) Copyright 1992-2007 by Deitel & Associates, Inc. and * + * Pearson Education, Inc. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * * programs or to the documentation contained in these books. The authors * - * and publisher shall not be liable in any event for incidental or * - * consequential damages in connection with, or arising out of, the * - * furnishing, performance, or use of these programs. * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * *************************************************************************/ \ No newline at end of file diff --git a/src/test/AccountTest.java b/src/test/AccountTest.java new file mode 100644 index 0000000..c0a428d --- /dev/null +++ b/src/test/AccountTest.java @@ -0,0 +1,37 @@ +package test; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +import code.Buisness_logic.Account; +import code.Buisness_logic.Euro; + +public class AccountTest { + @Test + public void testCredit() { + Account primoACC = new Account(12345, 54321, new Euro(200.0), new Euro(1000.0)); + primoACC.credit(new Euro(500.0)); + assertEquals(150000, primoACC.getTotalBalance().getValore()); + } + + @Test + public void testDebit() { + Account primoACC = new Account(12345, 54321, new Euro(200.0), new Euro(1000.0)); + primoACC.debit(new Euro(500.0)); + assertEquals(50000, primoACC.getTotalBalance().getValore()); + } + + @Test + public void testGetAvailableBalance() { + Account primoACC = new Account(12345, 54321, new Euro(200.0), new Euro(1000.0)); + assertEquals(20000, primoACC.getAvailableBalance().getValore()); + } + + @Test + public void testGetTotalBalance() { + Account primoACC = new Account(12345, 54321, new Euro(200.0), new Euro(1000.0)); + assertEquals(100000, primoACC.getTotalBalance().getValore()); + } + +} diff --git a/src/test/BankDatabaseTest.java b/src/test/BankDatabaseTest.java new file mode 100644 index 0000000..e588c9a --- /dev/null +++ b/src/test/BankDatabaseTest.java @@ -0,0 +1,35 @@ +package test; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +import code.Buisness_logic.Euro; +import code.Database.BankDatabase; + +public class BankDatabaseTest { + @Test + public void testAuthenticateUser() { + BankDatabase user = new BankDatabase(); + assertEquals(true, user.authenticateUser(12345, 54321)); + } + + @Test + public void testDebit() { + BankDatabase database = new BankDatabase(); + database.debit(12345, new Euro(500.0)); + assertEquals(70000, database.getTotalBalance(12345).getValore()); + } + + @Test + public void testGetAvailableBalance() { + BankDatabase database = new BankDatabase(); + assertEquals(100000, database.getAvailableBalance(12345).getValore()); + } + + @Test + public void testGetTotalBalance() { + BankDatabase database = new BankDatabase(); + assertEquals(120000, database.getTotalBalance(12345).getValore()); + } +} diff --git a/src/test/EuroTest.java b/src/test/EuroTest.java new file mode 100644 index 0000000..e3bbdcf --- /dev/null +++ b/src/test/EuroTest.java @@ -0,0 +1,57 @@ +package test; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +import code.Buisness_logic.Euro; + +public class EuroTest { + @Test + public void testGetValore() { + Euro testval = new Euro(60); + assertEquals(6000, testval.getValore()); + } + + @Test + public void testMinoreDi() { + Euro primo = new Euro(5); + Euro secondo = new Euro(2); + assertEquals(true, secondo.minoreDi(primo)); + } + + @Test + public void testSetValore() { + + } + + @Test + public void testSomma() { + Euro primo = new Euro(10); + Euro secondo = new Euro(5); + secondo.somma(primo); + assertEquals(1500, secondo.getValore()); + } + + @Test + public void testSottrai() { + Euro primo = new Euro(10); + Euro secondo = new Euro(5); + primo.sottrai(secondo); + assertEquals(500, secondo.getValore()); + } + + @Test + public void testStampa() { + Euro primo = new Euro(50); + String testString = "50.0 euro"; + assertEquals(testString, primo.stampa()); + } + + @Test + public void testUgualeA() { + Euro primo = new Euro(5); + Euro secondo = new Euro(5); + assertEquals(true, secondo.ugualeA(primo)); + } +}