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
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/businesslogic/ATM.class
Binary file not shown.
Binary file added bin/code/businesslogic/ATMCaseStudy.class
Binary file not shown.
Binary file added bin/code/businesslogic/BalanceInquiry.class
Binary file not shown.
Binary file added bin/code/database/Account.class
Binary file not shown.
Binary file added bin/code/database/BankDatabase.class
Binary file not shown.
Binary file added bin/code/database/Euro.class
Binary file not shown.
Binary file added bin/code/database/Transaction.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.
4 changes: 4 additions & 0 deletions componenti.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Di Luca Mattia - 5213177
Mafodda Edoardo - 5302507
Moreno Luca - 5209592
Toscano Mattia - 5288636
11 changes: 11 additions & 0 deletions src/ATM.java → src/code/businesslogic/ATM.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
package code.businesslogic;

import code.database.BankDatabase;
import code.database.Transaction;
import code.gui.CashDispenser;
import code.gui.Deposit;
import code.gui.DepositSlot;
import code.gui.Keypad;
import code.gui.Screen;
import code.gui.Withdrawal;

// ATM.java
// Represents an automated teller machine

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package code.businesslogic;

// ATMCaseStudy.java
// Driver program for the ATM case study

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
package code.businesslogic;

import code.database.BankDatabase;
import code.database.Euro;
import code.database.Transaction;
import code.gui.Screen;

// BalanceInquiry.java
// Represents a balance inquiry ATM transaction

Expand All @@ -18,19 +25,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.displayEuroAmount( availableBalance );
screen.displayMessage( "\n - Total balance: " );
screen.displayDollarAmount( totalBalance );
screen.displayEuroAmount( totalBalance );
screen.displayMessageLine( "" );
} // end method execute
} // end class BalanceInquiry
Expand Down
22 changes: 12 additions & 10 deletions src/Account.java → src/code/database/Account.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package code.database;

// 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 +30,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
13 changes: 7 additions & 6 deletions src/BankDatabase.java → src/code/database/BankDatabase.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
package code.database;
// BankDatabase.java
// Represents the bank account information database

Expand All @@ -9,8 +10,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 +43,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
52 changes: 52 additions & 0 deletions src/code/database/Euro.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package code.database;

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 int getEuro() {
return (int)(this.valore / 100);
}

public String stampa(){
return (double)valore/100 +" euro";
}
}
4 changes: 4 additions & 0 deletions src/Transaction.java → src/code/database/Transaction.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
package code.database;

import code.gui.Screen;

// Transaction.java
// Abstract superclass Transaction represents an ATM transaction

Expand Down
14 changes: 9 additions & 5 deletions src/CashDispenser.java → src/code/gui/CashDispenser.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package code.gui;

import code.database.Euro;

// CashDispenser.java
// Represents the cash dispenser of the ATM

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 int count; // number of 20 bills remaining

// no-argument CashDispenser constructor initializes count to default
public CashDispenser()
Expand All @@ -14,16 +18,16 @@ 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 = amount.getEuro() / 20; // 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 = amount.getEuro() / 20; // number of 20 bills required

if ( count >= billsRequired )
return true; // enough bills available
Expand Down
18 changes: 12 additions & 6 deletions src/Deposit.java → src/code/gui/Deposit.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package code.gui;

import code.database.BankDatabase;
import code.database.Euro;
import code.database.Transaction;

// 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
Expand All @@ -30,12 +36,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.equals(new Euro(0)) )
{
// request deposit envelope containing specified amount
screen.displayMessage(
"\nPlease insert a deposit envelope containing " );
screen.displayDollarAmount( amount );
screen.displayEuroAmount(amount);
screen.displayMessageLine( "." );

// receive deposit envelope
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);
else
{
return ( double ) input / 100; // return dollar amount
return ( Euro ) new Euro(input / 100); // return euro amount
} // end else
} // end method promptForDepositAmount
} // end class Deposit
Expand Down
2 changes: 2 additions & 0 deletions src/DepositSlot.java → src/code/gui/DepositSlot.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package code.gui;

// DepositSlot.java
// Represents the deposit slot of the ATM

Expand Down
2 changes: 2 additions & 0 deletions src/Keypad.java → src/code/gui/Keypad.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down
12 changes: 8 additions & 4 deletions src/Screen.java → src/code/gui/Screen.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
package code.gui;

import code.database.Euro;

// Screen.java
// Represents the screen of the ATM

Expand All @@ -15,11 +19,11 @@ public void displayMessageLine( String message )
System.out.println( message );
} // end method displayMessageLine

// display a dollar amount
public void displayDollarAmount( double amount )
// display euro amount
public void displayEuroAmount( Euro amount )
{
System.out.printf( "$%,.2f", amount );
} // end method displayDollarAmount
System.out.printf( amount.stampa() );
} // end method displayEuroAmount
} // end class Screen


Expand Down
Loading