Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/*.code-snippets

# Local History for Visual Studio Code
.history/

# Built Visual Studio Code Extensions
*.vsix

# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
replay_pid*
Binary file removed bin/ATM.class
Binary file not shown.
Binary file removed bin/ATMCaseStudy.class
Binary file not shown.
Binary file removed bin/Account.class
Binary file not shown.
Binary file removed bin/BalanceInquiry.class
Binary file not shown.
Binary file removed bin/BankDatabase.class
Binary file not shown.
Binary file removed bin/CashDispenser.class
Binary file not shown.
Binary file removed bin/Deposit.class
Binary file not shown.
Binary file removed bin/DepositSlot.class
Binary file not shown.
Binary file removed bin/Keypad.class
Binary file not shown.
Binary file removed bin/Screen.class
Binary file not shown.
Binary file removed bin/Transaction.class
Binary file not shown.
Binary file removed bin/Withdrawal.class
Binary file not shown.
3 changes: 3 additions & 0 deletions componenti.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Stefano Amalberti 5209118
Lorenzo Massone 5198151
Stefano Musso Piantelli 5320921
54 changes: 54 additions & 0 deletions src/Code/Business_logic/Euro.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
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 double getValoreDouble() {
return (double) valore / 100;
}

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";
}
}
69 changes: 32 additions & 37 deletions src/Account.java → src/Code/Database/Account.java
Original file line number Diff line number Diff line change
@@ -1,76 +1,71 @@
package Code.Database;
// Account.java

// Represents a bank account

public class Account
{
import Code.Business_logic.Euro;

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;
totalBalance = theTotalBalance;
} // 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. *
*************************************************************************/
81 changes: 37 additions & 44 deletions src/BankDatabase.java → src/Code/Database/BankDatabase.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
package Code.Database;
// BankDatabase.java

import Code.Business_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

Expand All @@ -29,56 +29,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. *
*************************************************************************/
Loading