Skip to content
Open
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.
Binary file added bin/code/Business_logic/Account.class
Binary file not shown.
Binary file added bin/code/Business_logic/Euro.class
Binary file not shown.
Binary file added bin/code/Business_logic/Transaction.class
Binary file not shown.
Binary file added bin/code/Database/BankDatabase.class
Binary file not shown.
Binary file added bin/code/GUI/ATM.class
Binary file not shown.
Binary file added bin/code/GUI/ATMCaseStudy.class
Binary file not shown.
Binary file added bin/code/GUI/BalanceInquiry.class
Binary file not shown.
Binary file added bin/code/GUI/CashDispenser.class
Binary file not shown.
Binary file added bin/code/GUI/Deposit.class
Binary file not shown.
Binary file added bin/code/GUI/DepositSlot.class
Binary file not shown.
Binary file added bin/code/GUI/Keypad.class
Binary file not shown.
Binary file added bin/code/GUI/Screen.class
Binary file not shown.
Binary file added bin/code/GUI/Withdrawal.class
Binary file not shown.
Binary file added bin/test/TestAccount.class
Binary file not shown.
Binary file added bin/test/TestBankDatabase.class
Binary file not shown.
Binary file added bin/test/TestEuro.class
Binary file not shown.
Binary file added lib/junit-platform-console-standalone-1.10.1.jar
Binary file not shown.
29 changes: 20 additions & 9 deletions src/Account.java → src/code/Business_logic/Account.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
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 )
{
accountNumber = theAccountNumber;
pin = thePIN;
availableBalance = new Euro(theAvailableBalance);
totalBalance = new Euro(theTotalBalance);
} // end Account constructor

// Account constructor initializes attributes
public Account( int theAccountNumber, int thePIN,
Euro theAvailableBalance, Euro theTotalBalance )
{
accountNumber = theAccountNumber;
pin = thePIN;
Expand All @@ -28,28 +39,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
52 changes: 52 additions & 0 deletions src/code/Business_logic/Euro.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
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 getValoreD(){
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";
}
}
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
12 changes: 8 additions & 4 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 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
4 changes: 4 additions & 0 deletions src/ATM.java → src/code/GUI/ATM.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package code.GUI;
// ATM.java
// Represents an automated teller machine

import code.Business_logic.Transaction;
import code.Database.BankDatabase;

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

Expand Down
9 changes: 7 additions & 2 deletions src/BalanceInquiry.java → src/code/GUI/BalanceInquiry.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package code.GUI;
// BalanceInquiry.java
// Represents a balance inquiry ATM transaction

import code.Business_logic.Transaction;
import code.Business_logic.Euro;
import code.Database.BankDatabase;

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
21 changes: 12 additions & 9 deletions src/CashDispenser.java → src/code/GUI/CashDispenser.java
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
package code.GUI;
// CashDispenser.java
// Represents the cash dispenser of the ATM

import code.Business_logic.Euro;

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
private final static Euro INITIAL_COUNT = new Euro(500,0);
private Euro count; // number of $20 bills remaining

// no-argument CashDispenser constructor initializes count to default
public CashDispenser()
{
count = INITIAL_COUNT; // set count attribute to default
count = new Euro(INITIAL_COUNT.getValoreD()); // set count attribute to default
} // 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
count -= billsRequired; // update the count of bills
Euro billsRequired = new Euro(amount.getValoreD() / 20); // number of $20 bills required
count.sottrai(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
Euro billsRequired = new Euro(amount.getValoreD() / 20); // number of $20 bills required

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

import code.Business_logic.Transaction;
import code.Business_logic.Euro;
import code.Database.BankDatabase;

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 @@ -27,10 +32,10 @@ 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(
Expand Down
1 change: 1 addition & 0 deletions src/DepositSlot.java → src/code/GUI/DepositSlot.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
package code.GUI;
// DepositSlot.java
// Represents the deposit slot of the ATM

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( "$%,.2f", amount.getValoreD());
} // end method displayDollarAmount
} // end class Screen

Expand Down
20 changes: 13 additions & 7 deletions src/Withdrawal.java → src/code/GUI/Withdrawal.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package code.GUI;
// Withdrawal.java
// Represents a withdrawal ATM transaction

import code.Business_logic.Transaction;
import code.Business_logic.Euro;
import code.Database.BankDatabase;

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

// constant corresponding to menu option to cancel
private final static int CANCELED = 6;
private final static int CANCELED = -1;

// Withdrawal constructor
public Withdrawal( int userAccountNumber, Screen atmScreen,
Expand All @@ -27,8 +32,8 @@ 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
int userChoice;
// get references to bank database and screen
BankDatabase bankDatabase = getBankDatabase();
Screen screen = getScreen();
Expand All @@ -37,17 +42,18 @@ public void execute()
do
{
// obtain a chosen withdrawal amount from the user
amount = displayMenuOfAmounts();
userChoice = displayMenuOfAmounts();

// check whether user chose a withdrawal amount or canceled
if ( amount != CANCELED )
if ( userChoice != CANCELED )
{
amount = new Euro(userChoice, 0);
// get available balance of account involved
availableBalance =
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 ) )
Expand Down
3 changes: 3 additions & 0 deletions src/componenti.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Lorenzo, Rossi, S4961068
Mattia, Donzella, S5229269
Maura, Simiras, S5161685
Loading