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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.class
*.jar
*.json
24 changes: 21 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
{
"java.project.sourcePaths": ["src"],
"java.project.outputPath": "bin",
"java.project.referencedLibraries": [
"lib/**/*.jar"
]
"java.project.referencedLibraries": {
"include": [
"lib/**/*.jar",
"test-lib/junit-4.13.2.jar",
"test-lib/hamcrest-core-1.3.jar",
"test-lib/mockito-core-4.8.1.jar",
"test-lib/byte-buddy-1.12.16.jar",
"test-lib/byte-buddy-agent-1.12.16.jar",
"test-lib/generics-resolver-3.0.3.jar",
"test-lib/mockito-scala_2.13-1.17.30.jar",
"test-lib/mockito-scala-scalatest_2.13-1.17.30.jar",
"test-lib/objenesis-3.2.jar",
"test-lib/scalactic_2.13-3.2.17.jar",
"test-lib/scala-library-2.13.8.jar",
"test-lib/scala-parallel-collections_2.13-1.0.4.jar",
"test-lib/scala-reflect-2.13.8.jar"
],
"exclude": [
"lib/junit-4.13.2.jar"
]
}
}
Binary file modified bin/Account.class
Binary file not shown.
Binary file added bin/TestEuro.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 @@
Matteo Zanardi, S5002780
Lazzaro Simone S5208579
26 changes: 13 additions & 13 deletions src/Account.java → src/code/Businness_logic/Account.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
// Account.java
// Represents a bank account
package code.Businness_logic;
//import code.Businness_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 )
{
accountNumber = theAccountNumber;
pin = thePIN;
availableBalance = theAvailableBalance;
totalBalance = theTotalBalance;
availableBalance = new Euro(theAvailableBalance);
totalBalance = new Euro(theTotalBalance);
} // end Account constructor

// determines whether a user-specified PIN matches PIN in Account
Expand All @@ -28,28 +28,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,3 +1,4 @@
package code.Businness_logic;
// CashDispenser.java
// Represents the cash dispenser of the ATM

Expand All @@ -14,16 +15,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 = ((int)(amount.getValore()/100)) / 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 = ((int)(amount.getValore()/100)) / 20; // number of $20 bills required

if ( count >= billsRequired )
return true; // enough bills available
Expand Down
16 changes: 11 additions & 5 deletions src/Deposit.java → src/code/Businness_logic/Deposit.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package code.Businness_logic;
// import code.Businness_logic.Euro;
// 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.ugualeA((new Euro(-0, 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(0, input); // 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.Businness_logic;
// DepositSlot.java
// Represents the deposit slot of the ATM

Expand Down
48 changes: 48 additions & 0 deletions src/code/Businness_logic/Euro.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package code.Businness_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.Businness_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
21 changes: 13 additions & 8 deletions src/Withdrawal.java → src/code/Businness_logic/Withdrawal.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package code.Businness_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 +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 @@ -40,14 +45,14 @@ public void execute()
amount = displayMenuOfAmounts();

// check whether user chose a withdrawal amount or canceled
if ( amount != CANCELED )
if ( amount.getValore() != CANCELED )
{
// 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.getValore() <= availableBalance.getValore() )
{
// check whether the cash dispenser has enough money
if ( cashDispenser.isSufficientCashAvailable( amount ) )
Expand Down Expand Up @@ -85,14 +90,14 @@ 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
double userChoice = 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 };
double amounts[] = { 0.0, 20.0, 40.0, 60.0, 100.0, 200.0 };

// loop while no valid choice has been made
while ( userChoice == 0 )
Expand Down Expand Up @@ -128,7 +133,7 @@ private int displayMenuOfAmounts()
} // end switch
} // end while

return userChoice; // return withdrawal amount or CANCELED
return new Euro(userChoice); // return withdrawal amount or CANCELED
} // end method displayMenuOfAmounts
} // end class Withdrawal

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,5 +1,6 @@
// BankDatabase.java
// Represents the bank account information database
package code.Database;
import code.Businness_logic.Account;
import code.Businness_logic.Euro;

public class BankDatabase
{
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
8 changes: 8 additions & 0 deletions src/ATM.java → src/code/GUI/ATM.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
package code.GUI;
// ATM.java
// Represents an automated teller machine

import code.Businness_logic.CashDispenser;
import code.Businness_logic.Deposit;
import code.Businness_logic.DepositSlot;
import code.Businness_logic.Transaction;
import code.Businness_logic.Withdrawal;
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
10 changes: 6 additions & 4 deletions src/BalanceInquiry.java → src/code/GUI/BalanceInquiry.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// BalanceInquiry.java
// Represents a balance inquiry ATM transaction
package code.GUI;
import code.Businness_logic.Euro;
import code.Businness_logic.Transaction;
import code.Database.BankDatabase;

public class BalanceInquiry extends Transaction
{
Expand All @@ -18,11 +20,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
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
Loading