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
1 change: 1 addition & 0 deletions componenti.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Andrea Celotto -> s4676081
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.
5 changes: 5 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,11 @@
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,10 @@
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 +22,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 Down
10 changes: 8 additions & 2 deletions src/Deposit.java → src/code/Business_logic/Deposit.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
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
Expand Down Expand Up @@ -32,10 +37,11 @@ public void execute()
// check whether user entered a deposit amount or canceled
if ( amount != CANCELED )
{
Euro newAmount = new Euro(amount);
// request deposit envelope containing specified amount
screen.displayMessage(
"\nPlease insert a deposit envelope containing " );
screen.displayDollarAmount( amount );
screen.displayDollarAmount( newAmount );
screen.displayMessageLine( "." );

// receive deposit envelope
Expand All @@ -50,7 +56,7 @@ public void execute()
"enclosed cash and your checks clear." );

// credit account to reflect the deposit
bankDatabase.credit( getAccountNumber(), amount );
bankDatabase.credit( getAccountNumber(), newAmount );
} // end if
else // deposit envelope not received
{
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
49 changes: 49 additions & 0 deletions src/code/Business_logic/Euro.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
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,10 @@
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
13 changes: 10 additions & 3 deletions src/Withdrawal.java → src/code/Business_logic/Withdrawal.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
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
Expand All @@ -27,7 +32,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 @@ -42,18 +47,20 @@ public void execute()
// check whether user chose a withdrawal amount or canceled
if ( amount != CANCELED )
{
Euro newAmount = new Euro(amount);

// get available balance of account involved
availableBalance =
bankDatabase.getAvailableBalance( getAccountNumber() );

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

cashDispenser.dispenseCash( amount ); // dispense cash
cashDispensed = true; // cash was dispensed
Expand Down
16 changes: 10 additions & 6 deletions src/BankDatabase.java → src/code/Database/BankDatabase.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package code.Database;
// BankDatabase.java
// Represents the bank account information database

import code.Business_logic.Account;
import code.Business_logic.Euro;

public class BankDatabase
{
private Account accounts[]; // array of Accounts
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/Keypad.java → src/code/GUI/Keypad.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
package code.GUI;
// Keypad.java
// Represents the keypad of the ATM
import java.util.Scanner; // program uses Scanner to obtain user input
Expand Down
7 changes: 5 additions & 2 deletions src/Screen.java → src/code/GUI/Screen.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package code.GUI;
// Screen.java
// Represents the screen of the ATM

import code.Business_logic.Euro;

public class Screen
{
// displays a message without a carriage return
Expand All @@ -16,9 +19,9 @@ 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 );
System.out.printf( amount.stampa() );
} // end method displayDollarAmount
} // end class Screen

Expand Down
Loading