Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
31 changes: 31 additions & 0 deletions .github/workflows/junit-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: JUnit tests

on:
push:
branches: [ "test" ]
pull_request:
branches: [ "test" ]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: '11'
distribution: 'adopt'

- name: Download JUnit and Hamcrest
run: |
wget https://repo1.maven.org/maven2/junit/junit/4.13.1/junit-4.13.1.jar
wget https://repo1.maven.org/maven2/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar
- name: Compile Java files
run: |
javac -d bin -sourcepath src -cp junit-4.13.1.jar:hamcrest-core-1.3.jar -g src/test/*.java
- name: Run JUnit tests
run: |
java -cp bin:junit-4.13.1.jar:hamcrest-core-1.3.jar org.junit.runner.JUnitCore test.TestSuite
28 changes: 28 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
// Usare IntelliSense per informazioni sui possibili attributi.
// Al passaggio del mouse vengono visualizzate le descrizioni degli attributi esistenti.
// Per altre informazioni, visitare: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "ATMCaseStudy",
"request": "launch",
"mainClass": "code.Business_logic.ATMCaseStudy",
"projectName": "ATM_95d7eefc"
},
{
"type": "java",
"name": "Current File",
"request": "launch",
"mainClass": "${file}"
},
{
"type": "java",
"name": "ATMCaseStudy",
"request": "launch",
"mainClass": "code.ATMCaseStudy",
"projectName": "ATM_3b4aaa4e"
}
]
}
11 changes: 8 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
{
"java.project.sourcePaths": ["src"],
"java.project.outputPath": "bin",
"java.project.referencedLibraries": [
"lib/**/*.jar"
]
"java.project.referencedLibraries": {
"include": [
"lib/**/*.jar"
]
},
"files.exclude": {
"**/.git": false
}
}
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

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

Conflict successfully resolved
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 bin/code/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/**
!.gitignore
3 changes: 3 additions & 0 deletions componenti.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Aya Benkirane 5338412
Nicolò Aicardi 5198997
Andrea Valentino Ricotti 5306194
Binary file added lib/annotations-13.0.jar
Binary file not shown.
Binary file added lib/apiguardian-api-1.1.2.jar
Binary file not shown.
Binary file added lib/core-0.5.1.jar
Binary file not shown.
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.
Binary file added lib/junit-jupiter-api-5.8.2.jar
Binary file not shown.
Binary file added lib/junit-jupiter-engine-5.8.2.jar
Binary file not shown.
Binary file added lib/junit-jupiter-params-5.8.2.jar
Binary file not shown.
Binary file added lib/junit-platform-commons-1.8.2.jar
Binary file not shown.
Binary file added lib/junit-platform-engine-1.8.2.jar
Binary file not shown.
Binary file added lib/junit5-0.5.1.jar
Binary file not shown.
Binary file added lib/opentest4j-1.2.0.jar
Binary file not shown.
8 changes: 8 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,14 @@
package code.Business_logic;
// ATM.java
// Represents an automated teller machine

import code.Database.BankDatabase;
import code.GUI.BalanceInquiry;
import code.GUI.CashDispenser;
import code.GUI.DepositSlot;
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
12 changes: 9 additions & 3 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.DepositSlot;
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 @@ -27,10 +33,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
58 changes: 58 additions & 0 deletions src/code/Business_logic/Euro.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package code.Business_logic;

import java.util.Locale;

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 String.format(Locale.US, "%.2f", (double)valore/100) + " euro";
}

public boolean equals(Object obj){
if (obj == null || getClass() != obj.getClass()) {
return false;
}

return this.valore == ((Euro) obj).valore;
}
}
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
21 changes: 13 additions & 8 deletions src/Withdrawal.java → src/code/Business_logic/Withdrawal.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package code.Business_logic;
// Withdrawal.java
// Represents a withdrawal ATM transaction

import code.Database.BankDatabase;
import code.GUI.CashDispenser;
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 +33,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 @@ -37,17 +43,16 @@ public void execute()
do
{
// obtain a chosen withdrawal amount from the user
amount = displayMenuOfAmounts();
amount = new Euro(displayMenuOfAmounts(), 0);

// 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() );

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
27 changes: 15 additions & 12 deletions src/Account.java → src/code/Database/Account.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
package code.Database;
// Account.java
// Represents a bank account

import code.Business_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 )
double theAvailableBalance, double theTotalBalance )//account constructor still takes double
{
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 +31,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
11 changes: 7 additions & 4 deletions src/BankDatabase.java → src/code/Database/BankDatabase.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package code.Database;
// BankDatabase.java
// Represents the bank account information database

import code.Business_logic.Euro;

public class BankDatabase
{
private Account accounts[]; // array of Accounts
Expand Down Expand Up @@ -42,25 +45,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
Loading