diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index e112a70..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "java.project.sourcePaths": ["src"], - "java.project.outputPath": "bin", - "java.project.referencedLibraries": [ - "lib/**/*.jar" - ] -} diff --git a/bin/ATMCaseStudy.class b/bin/ATMCaseStudy.class index 607c10d..5d03234 100644 Binary files a/bin/ATMCaseStudy.class and b/bin/ATMCaseStudy.class 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/ATM.class b/bin/code/ATM.class similarity index 50% rename from bin/ATM.class rename to bin/code/ATM.class index 76543bf..919b4b2 100644 Binary files a/bin/ATM.class and b/bin/code/ATM.class differ diff --git a/bin/code/ATMCaseStudy.class b/bin/code/ATMCaseStudy.class new file mode 100644 index 0000000..cff8483 Binary files /dev/null and b/bin/code/ATMCaseStudy.class differ diff --git a/bin/code/Account.class b/bin/code/Account.class new file mode 100644 index 0000000..8d6e1e7 Binary files /dev/null and b/bin/code/Account.class differ diff --git a/bin/code/BalanceInquiry.class b/bin/code/BalanceInquiry.class new file mode 100644 index 0000000..92c33ae Binary files /dev/null and b/bin/code/BalanceInquiry.class differ diff --git a/bin/code/BankDatabase.class b/bin/code/BankDatabase.class new file mode 100644 index 0000000..c1ed7ee Binary files /dev/null and b/bin/code/BankDatabase.class differ diff --git a/bin/code/CashDispenser.class b/bin/code/CashDispenser.class new file mode 100644 index 0000000..ff77593 Binary files /dev/null and b/bin/code/CashDispenser.class differ diff --git a/bin/code/Deposit.class b/bin/code/Deposit.class new file mode 100644 index 0000000..0dc2ca1 Binary files /dev/null and b/bin/code/Deposit.class differ diff --git a/bin/code/DepositSlot.class b/bin/code/DepositSlot.class new file mode 100644 index 0000000..8c24a54 Binary files /dev/null and b/bin/code/DepositSlot.class differ diff --git a/bin/code/Keypad.class b/bin/code/Keypad.class new file mode 100644 index 0000000..4e59e06 Binary files /dev/null and b/bin/code/Keypad.class differ diff --git a/bin/code/Screen.class b/bin/code/Screen.class new file mode 100644 index 0000000..e693401 Binary files /dev/null and b/bin/code/Screen.class differ diff --git a/bin/code/Transaction.class b/bin/code/Transaction.class new file mode 100644 index 0000000..f5d9f1c Binary files /dev/null and b/bin/code/Transaction.class differ diff --git a/bin/code/Withdrawal.class b/bin/code/Withdrawal.class new file mode 100644 index 0000000..771f341 Binary files /dev/null and b/bin/code/Withdrawal.class differ diff --git a/componenti.txt b/componenti.txt new file mode 100644 index 0000000..1fd2e09 --- /dev/null +++ b/componenti.txt @@ -0,0 +1,6 @@ +Componenti del gruppo: +1) ArunRaj Mathiyalakan (S4954688) +2) Samuel Cavicchia (S5225277) +3) Romano Yuri (S5231931) + +Nota: se nei commit vede un universik15 รจ un altro account di Cavicchia. \ No newline at end of file diff --git a/lib/hamcrest-core 1.jar b/lib/hamcrest-core 1.jar new file mode 100644 index 0000000..9d5fe16 Binary files /dev/null and b/lib/hamcrest-core 1.jar differ 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/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/ATMCaseStudy.java b/src/ATMCaseStudy.java index b9033bd..3995757 100644 --- a/src/ATMCaseStudy.java +++ b/src/ATMCaseStudy.java @@ -1,3 +1,5 @@ +import code.GUI.ATM; + // ATMCaseStudy.java // Driver program for the ATM case study diff --git a/src/CashDispenser.java b/src/code/Business_logic/CashDispenser.java similarity index 98% rename from src/CashDispenser.java rename to src/code/Business_logic/CashDispenser.java index b249faf..529f530 100644 --- a/src/CashDispenser.java +++ b/src/code/Business_logic/CashDispenser.java @@ -1,3 +1,5 @@ +package code.Business_logic; + // CashDispenser.java // Represents the cash dispenser of the ATM diff --git a/src/DepositSlot.java b/src/code/Business_logic/DepositSlot.java similarity index 97% rename from src/DepositSlot.java rename to src/code/Business_logic/DepositSlot.java index 64e02c2..f52ae5b 100644 --- a/src/DepositSlot.java +++ b/src/code/Business_logic/DepositSlot.java @@ -1,3 +1,5 @@ +package code.Business_logic; + // DepositSlot.java // Represents the deposit slot of the ATM diff --git a/src/code/Business_logic/Euro.java b/src/code/Business_logic/Euro.java new file mode 100644 index 0000000..9dc2edb --- /dev/null +++ b/src/code/Business_logic/Euro.java @@ -0,0 +1,42 @@ +package code.Business_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 -= 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"; + } +} diff --git a/src/Account.java b/src/code/Database/Account.java similarity index 75% rename from src/Account.java rename to src/code/Database/Account.java index c308eca..6ed7ce0 100644 --- a/src/Account.java +++ b/src/code/Database/Account.java @@ -1,3 +1,7 @@ +package code.Database; + +import code.Business_logic.Euro; + // Account.java // Represents a bank account @@ -5,12 +9,11 @@ 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 ) + Euro theAvailableBalance, Euro theTotalBalance ) { accountNumber = theAccountNumber; pin = thePIN; @@ -21,35 +24,33 @@ public Account( int theAccountNumber, int thePIN, // determines whether a user-specified PIN matches PIN in Account public boolean validatePIN( int userPIN ) { - if ( userPIN == pin ) - return true; - else - return false; + 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 ) + public void credit( Euro amount ) { - totalBalance += amount; // add to total balance + totalBalance = totalBalance.somma(amount); // add to total balance } // end method credit // debits an amount from the account - public void debit( double amount ) + public void debit( Euro amount ) { - availableBalance -= amount; // subtract from available balance - totalBalance -= amount; // subtract from total balance + availableBalance.sottrai(amount); // subtract from available balance + totalBalance.sottrai(amount); // subtract from total balance } // end method debit // returns account number diff --git a/src/BankDatabase.java b/src/code/Database/BankDatabase.java similarity index 87% rename from src/BankDatabase.java rename to src/code/Database/BankDatabase.java index 3978497..914fcd9 100644 --- a/src/BankDatabase.java +++ b/src/code/Database/BankDatabase.java @@ -1,3 +1,7 @@ +package code.Database; + +import code.Business_logic.Euro; + // BankDatabase.java // Represents the bank account information database @@ -9,8 +13,8 @@ public class BankDatabase 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 ); + 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 @@ -42,25 +46,25 @@ public boolean authenticateUser( int userAccountNumber, int userPIN ) } // end method authenticateUser // return available balance of Account with specified account number - public double getAvailableBalance( int userAccountNumber ) + 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 ) + 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 ) + 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 ) + public void debit( int userAccountNumber, Euro amount ) { getAccount( userAccountNumber ).debit( amount ); } // end method debit diff --git a/src/Deposit.java b/src/code/Database/Deposit.java similarity index 89% rename from src/Deposit.java rename to src/code/Database/Deposit.java index 916ef70..5d72540 100644 --- a/src/Deposit.java +++ b/src/code/Database/Deposit.java @@ -1,9 +1,16 @@ +package code.Database; + +import code.Business_logic.DepositSlot; +import code.Business_logic.Euro; +import code.GUI.Keypad; +import code.GUI.Screen; + // Deposit.java // Represents a deposit ATM transaction public class Deposit extends Transaction { - private double amount; // amount to deposit + 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 @@ -30,12 +37,12 @@ public void execute() amount = 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.displayDollarAmount( new Euro(amount.getValore()) ); screen.displayMessageLine( "." ); // receive deposit envelope @@ -65,7 +72,7 @@ public void execute() } // end method execute // prompt user to enter a deposit amount in cents - private double promptForDepositAmount() + private Euro promptForDepositAmount() { Screen screen = getScreen(); // get reference to screen @@ -76,10 +83,10 @@ private double promptForDepositAmount() // check whether the user canceled or entered a valid amount if ( input == CANCELED ) - return CANCELED; + return new Euro(CANCELED); else { - return ( double ) input / 100; // return dollar amount + return new Euro(input / 100); // return dollar amount } // end else } // end method promptForDepositAmount } // end class Deposit diff --git a/src/Transaction.java b/src/code/Database/Transaction.java similarity index 97% rename from src/Transaction.java rename to src/code/Database/Transaction.java index 508fea8..fc0c9fe 100644 --- a/src/Transaction.java +++ b/src/code/Database/Transaction.java @@ -1,3 +1,7 @@ +package code.Database; + +import code.GUI.Screen; + // Transaction.java // Abstract superclass Transaction represents an ATM transaction diff --git a/src/ATM.java b/src/code/GUI/ATM.java similarity index 97% rename from src/ATM.java rename to src/code/GUI/ATM.java index aa3d187..0aa2a88 100644 --- a/src/ATM.java +++ b/src/code/GUI/ATM.java @@ -1,3 +1,11 @@ +package code.GUI; + +import code.Business_logic.CashDispenser; +import code.Business_logic.DepositSlot; +import code.Database.BankDatabase; +import code.Database.Deposit; +import code.Database.Transaction; + // ATM.java // Represents an automated teller machine diff --git a/src/BalanceInquiry.java b/src/code/GUI/BalanceInquiry.java similarity index 87% rename from src/BalanceInquiry.java rename to src/code/GUI/BalanceInquiry.java index d45fa6a..39cfe1e 100644 --- a/src/BalanceInquiry.java +++ b/src/code/GUI/BalanceInquiry.java @@ -1,3 +1,9 @@ +package code.GUI; + +import code.Business_logic.Euro; +import code.Database.BankDatabase; +import code.Database.Transaction; + // BalanceInquiry.java // Represents a balance inquiry ATM transaction @@ -18,19 +24,19 @@ public void execute() Screen screen = getScreen(); // get the available balance for the account involved - double availableBalance = + Euro availableBalance = bankDatabase.getAvailableBalance( getAccountNumber() ); // get the total balance for the account involved - double totalBalance = + Euro totalBalance = bankDatabase.getTotalBalance( getAccountNumber() ); // display the balance information on the screen screen.displayMessageLine( "\nBalance Information:" ); screen.displayMessage( " - Available balance: " ); - screen.displayDollarAmount( availableBalance ); + screen.displayDollarAmount( new Euro(availableBalance.getValore()) ); screen.displayMessage( "\n - Total balance: " ); - screen.displayDollarAmount( totalBalance ); + screen.displayDollarAmount( new Euro(totalBalance.getValore()) ); screen.displayMessageLine( "" ); } // end method execute } // end class BalanceInquiry diff --git a/src/Keypad.java b/src/code/GUI/Keypad.java similarity index 98% rename from src/Keypad.java rename to src/code/GUI/Keypad.java index cd035c7..6c6cd2a 100644 --- a/src/Keypad.java +++ b/src/code/GUI/Keypad.java @@ -1,3 +1,5 @@ +package code.GUI; + // Keypad.java // Represents the keypad of the ATM import java.util.Scanner; // program uses Scanner to obtain user input @@ -5,7 +7,6 @@ public class Keypad { private Scanner input; // reads data from the command line - // no-argument constructor initializes the Scanner public Keypad() { diff --git a/src/Screen.java b/src/code/GUI/Screen.java similarity index 94% rename from src/Screen.java rename to src/code/GUI/Screen.java index 44d3f30..e083412 100644 --- a/src/Screen.java +++ b/src/code/GUI/Screen.java @@ -1,3 +1,7 @@ +package code.GUI; + +import code.Business_logic.Euro; + // Screen.java // Represents the screen of the ATM @@ -16,7 +20,7 @@ public void displayMessageLine( String message ) } // end method displayMessageLine // display a dollar amount - public void displayDollarAmount( double amount ) + public void displayDollarAmount( Euro amount ) { System.out.printf( "$%,.2f", amount ); } // end method displayDollarAmount diff --git a/src/Withdrawal.java b/src/code/GUI/Withdrawal.java similarity index 94% rename from src/Withdrawal.java rename to src/code/GUI/Withdrawal.java index 6e0af62..f9dec69 100644 --- a/src/Withdrawal.java +++ b/src/code/GUI/Withdrawal.java @@ -1,3 +1,10 @@ +package code.GUI; + +import code.Business_logic.CashDispenser; +import code.Business_logic.Euro; +import code.Database.BankDatabase; +import code.Database.Transaction; + // Withdrawal.java // Represents a withdrawal ATM transaction @@ -27,7 +34,7 @@ public Withdrawal( int userAccountNumber, Screen atmScreen, 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(); @@ -47,13 +54,13 @@ public void execute() bankDatabase.getAvailableBalance( getAccountNumber() ); // check whether the user has enough money in the account - if ( amount <= availableBalance ) + if ( amount <= availableBalance.getValore() ) { // check whether the cash dispenser has enough money if ( cashDispenser.isSufficientCashAvailable( amount ) ) { // update the account involved to reflect withdrawal - bankDatabase.debit( getAccountNumber(), amount ); + bankDatabase.debit( getAccountNumber(), new Euro(amount) ); cashDispenser.dispenseCash( amount ); // dispense cash cashDispensed = true; // cash was dispensed diff --git a/src/test/AccountTest.java b/src/test/AccountTest.java new file mode 100644 index 0000000..8b41293 --- /dev/null +++ b/src/test/AccountTest.java @@ -0,0 +1,53 @@ +package test; + +import org.junit.Test; +import static org.junit.Assert.*; + +import code.Database.Account; +import code.Business_logic.Euro; + + +public class AccountTest { + @Test + public void testGetAvailableBalance() { + Euro initialBalance = new Euro(10, 0); + Account account = new Account(1, 1234, initialBalance, initialBalance); + assertEquals(1000, account.getAvailableBalance().getValore()); + } + + @Test + public void testValidatePIN() { + Account account = new Account(1, 1234, new Euro(10, 0), new Euro(10, 0)); + assertTrue(account.validatePIN(1234)); + assertFalse(account.validatePIN(1111)); + } + + @Test + public void testCredit() { + Euro initialBalance = new Euro(10, 0); + Account account = new Account(1, 1234, initialBalance, initialBalance); + account.credit(new Euro(5, 0)); + assertEquals(1500, account.getTotalBalance().getValore()); + } + + @Test + public void testGetAccountNumber() { + Account account = new Account(1, 1234, new Euro(10, 0), new Euro(10, 0)); + assertEquals(1, account.getAccountNumber()); + } + + @Test + public void testGetTotalBalance() { + Euro initialBalance = new Euro(10, 0); + Account account = new Account(1, 1234, initialBalance, initialBalance); + assertEquals(1000, account.getTotalBalance().getValore()); + } + + @Test + public void testDebit() { + Account account = new Account(1, 1234, new Euro(10, 0), new Euro(10, 0)); + account.debit(new Euro(5, 0)); + assertEquals(500, account.getAvailableBalance().getValore()); + assertEquals(500, account.getTotalBalance().getValore()); + } +} diff --git a/src/test/BankDatabaseTest.java b/src/test/BankDatabaseTest.java new file mode 100644 index 0000000..db892d1 --- /dev/null +++ b/src/test/BankDatabaseTest.java @@ -0,0 +1,49 @@ +package test; + +import org.junit.Test; +import org.junit.Before; +import static org.junit.Assert.*; + +import code.Business_logic.Euro; +import code.Database.BankDatabase; + +public class BankDatabaseTest { + private BankDatabase bankDatabase; + + @Before + public void setUp() { + bankDatabase = new BankDatabase(); + } + + @Test + public void testAuthenticateUser() { + assertTrue(bankDatabase.authenticateUser(12345, 54321)); + assertFalse(bankDatabase.authenticateUser(12345, 9999)); + assertFalse(bankDatabase.authenticateUser(9999, 54321)); + } + + @Test + public void testGetAvailableBalance() { + assertEquals(100000, bankDatabase.getAvailableBalance(12345).getValore()); + assertEquals(20000, bankDatabase.getAvailableBalance(98765).getValore()); + } + + @Test + public void testGetTotalBalance() { + assertEquals(120000, bankDatabase.getTotalBalance(12345).getValore()); + assertEquals(20000, bankDatabase.getTotalBalance(98765).getValore()); + } + + @Test + public void testCredit() { + bankDatabase.credit(12345, new Euro(500.0)); + assertEquals(170000, bankDatabase.getTotalBalance(12345).getValore()); + } + + @Test + public void testDebit() { + bankDatabase.debit(98765, new Euro(100.0)); + assertEquals(10000, bankDatabase.getAvailableBalance(98765).getValore()); + assertEquals(10000, bankDatabase.getTotalBalance(98765).getValore()); + } +} diff --git a/src/test/EuroTest.java b/src/test/EuroTest.java new file mode 100644 index 0000000..75c7b04 --- /dev/null +++ b/src/test/EuroTest.java @@ -0,0 +1,70 @@ +package test; + +import org.junit.Test; +import static org.junit.Assert.*; + +import code.Business_logic.Euro; + +public class EuroTest { + @Test + public void testCostruttoreConDueParametriPositivi() { + Euro euro = new Euro(5, 50); + assertEquals(550, euro.getValore()); + } + + @Test + public void testCostruttoreConDueParametriDiCuiEuroNegativo() { + Euro euro = new Euro(-5, 50); + assertEquals(-550, euro.getValore()); + } + + @Test + public void testCostruttoreConSingoloParametro() { + Euro euro = new Euro(5.50); + assertEquals(550, euro.getValore()); + } + + @Test + public void testSomma() { + Euro euro1 = new Euro(5, 50); + Euro euro2 = new Euro(3, 75); + + Euro risultato = euro1.somma(euro2); + assertEquals(925, risultato.getValore()); + } + + @Test + public void testSottrai() { + Euro euro1 = new Euro(5, 50); + Euro euro2 = new Euro(3, 75); + + Euro risultato = euro1.sottrai(euro2); + assertEquals(175, risultato.getValore()); + } + + @Test + public void testUgualeA() { + Euro euro1 = new Euro(5, 50); + Euro euro2 = new Euro(5, 50); + assertTrue(euro1.ugualeA(euro2)); + + Euro euro3 = new Euro(8, 25); + assertFalse(euro1.ugualeA(euro3)); + } + + @Test + public void testMinoreDi() { + Euro euro1 = new Euro(5, 50); + Euro euro2 = new Euro(8, 25); + assertTrue(euro1.minoreDi(euro2)); + + Euro euro3 = new Euro(3, 75); + assertFalse(euro1.minoreDi(euro3)); + } + + @Test + public void testStampa() { + Euro euro = new Euro(5, 50); + assertEquals("5.5 euro", euro.stampa()); + } +}