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
24 changes: 24 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# 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*
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ Avviando il main() della classe ATMCaseStudy, viene richiesto l’inserimento de
- Numero di conto = 98765, PIN = 56789

---------------------------------------------------------------------------

Stiamo per fare un conflitto
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.
2 changes: 2 additions & 0 deletions componenti.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Lorenzo Mecca - 5317293
Carlo Arturo Zecca - 5228599
Binary file added lib/hamcrest-core-1.3.jar
Binary file not shown.
Binary file added lib/junit-4.13.2.jar
Binary file not shown.
6 changes: 6 additions & 0 deletions src/ATM.java → src/code/Business_logic/ATM.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package code.Business_logic;
// ATM.java
// Represents an automated teller machine

import code.Database.BankDatabase;

import code.GUI.Keypad;
import code.GUI.Screen;

public class ATM
{
private boolean userAuthenticated; // whether user is authenticated
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
package code.Business_logic;
// ATMCaseStudy.java
// Driver program for the ATM case study

Expand Down
21 changes: 11 additions & 10 deletions src/Account.java → src/code/Business_logic/Account.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package code.Business_logic;
// Account.java
// Represents a bank 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 )
Euro theAvailableBalance, Euro theTotalBalance )
{
accountNumber = theAccountNumber;
pin = thePIN;
Expand All @@ -28,28 +29,28 @@ public boolean validatePIN( int userPIN )
} // 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.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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package code.Business_logic;
// BalanceInquiry.java
// Represents a balance inquiry ATM transaction

import code.Database.BankDatabase;

import code.GUI.Screen;

public class BalanceInquiry extends Transaction
{
// BalanceInquiry constructor
Expand All @@ -18,11 +23,11 @@ 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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
package code.Business_logic;
// CashDispenser.java
// Represents the cash dispenser of the ATM

Expand All @@ -14,18 +15,18 @@ public CashDispenser()
} // end CashDispenser constructor

// simulates dispensing of specified amount of cash
public void dispenseCash( int amount )
public void dispenseCash( Euro amount )
{
int billsRequired = amount / 20; // number of $20 bills required
int billsRequired = (int)(amount.getValore() / 20) / 100; // 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( Euro amount )
{
int billsRequired = amount / 20; // number of $20 bills required
int billsRequired = (int)(amount.getValore() / 20) / 100; // number of $20 bills required

if ( count >= billsRequired )
if ( count >= billsRequired)
return true; // enough bills available
else
return false; // not enough bills available
Expand Down
16 changes: 11 additions & 5 deletions src/Deposit.java → src/code/Business_logic/Deposit.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package code.Business_logic;
// Deposit.java
// Represents a deposit ATM transaction

import code.Database.BankDatabase;

import code.GUI.Keypad;
import code.GUI.Screen;

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
Expand All @@ -30,7 +36,7 @@ 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(
Expand Down Expand Up @@ -65,7 +71,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

Expand All @@ -76,10 +82,10 @@ private double promptForDepositAmount()

// check whether the user canceled or entered a valid amount
if ( input == CANCELED )
return CANCELED;
return new Euro(0, CANCELED);
else
{
return ( double ) input / 100; // return dollar amount
return new Euro(input / 100, input % 100); // return dollar amount
} // end else
} // end method promptForDepositAmount
} // end class Deposit
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
package code.Business_logic;
// DepositSlot.java
// Represents the deposit slot of the ATM

Expand Down
47 changes: 47 additions & 0 deletions src/code/Business_logic/Euro.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
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 = 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";
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package code.Business_logic;
// Transaction.java
// Abstract superclass Transaction represents an ATM transaction

import code.Database.BankDatabase;

import code.GUI.Screen;

public abstract class Transaction
{
private int accountNumber; // indicates account involved
Expand Down
33 changes: 20 additions & 13 deletions src/Withdrawal.java → src/code/Business_logic/Withdrawal.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
package code.Business_logic;
// Withdrawal.java
// Represents a withdrawal ATM transaction


import code.Database.BankDatabase;

import code.GUI.Keypad;
import code.GUI.Screen;

public class Withdrawal extends Transaction
{
private int amount; // amount to withdraw
private Euro amount; // amount to withdraw
private Keypad keypad; // reference to keypad
private CashDispenser cashDispenser; // reference to cash dispenser

Expand All @@ -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();
Expand All @@ -40,22 +47,22 @@ public void execute()
amount = displayMenuOfAmounts();

// check whether user chose a withdrawal amount or canceled
if ( amount != CANCELED )
if (!amount.ugualeA(new Euro(CANCELED)))
{
// get available balance of account involved
availableBalance =
bankDatabase.getAvailableBalance( getAccountNumber() );
bankDatabase.getAvailableBalance(getAccountNumber());

// check whether the user has enough money in the account
if ( amount <= availableBalance )
if ( amount.minoreDi(availableBalance))
{
// 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 );
bankDatabase.debit(getAccountNumber(), amount);

cashDispenser.dispenseCash( amount ); // dispense cash
cashDispenser.dispenseCash(amount); // dispense cash
cashDispensed = true; // cash was dispensed

// instruct user to take cash
Expand Down Expand Up @@ -85,17 +92,17 @@ public void 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 Euro displayMenuOfAmounts()
{
int userChoice = 0; // local variable to store return value
Euro userChoice = new Euro(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.ugualeA(new Euro(0)))
{
// display the menu
screen.displayMessageLine( "\nWithdrawal Menu:" );
Expand All @@ -117,10 +124,10 @@ private int displayMenuOfAmounts()
case 3: // corresponding amount from amounts array
case 4:
case 5:
userChoice = amounts[ input ]; // save user's choice
userChoice = new Euro(amounts[input]); // save user's choice
break;
case CANCELED: // the user chose to cancel
userChoice = CANCELED; // save user's choice
userChoice = new Euro(CANCELED); // save user's choice
break;
default: // the user did not enter a value from 1-6
screen.displayMessageLine(
Expand Down
Loading