Skip to content
Open

Lab3 #14

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
2cd5b08
Added new packages code and test
SimoneTomasella2002 Nov 21, 2023
82bbb2f
Added .gitignore
SimoneTomasella2002 Nov 21, 2023
eb1ecb9
added package code
ThomasGhione Nov 21, 2023
f8d8504
Merge branch 'feature' of https://github.com/ThomasGhione/ATM into fe…
SimoneTomasella2002 Nov 21, 2023
09f4bd1
Merge .class
SimoneTomasella2002 Nov 21, 2023
8aacc7e
added class Euro
ThomasGhione Nov 21, 2023
a9ca2f4
Added new packages and updated files location
SimoneTomasella2002 Nov 21, 2023
833627a
fixed some errors
ThomasGhione Nov 21, 2023
05f1a92
from double to euro
ThomasGhione Nov 21, 2023
d4c5419
Fixed a bug in Screen.java
SimoneTomasella2002 Nov 21, 2023
1a841bd
test push
ThomasGhione Nov 21, 2023
abcf6c0
finished converting from double to euro
ThomasGhione Nov 21, 2023
b3ad865
Changed Keypad.java file location and optimized some ops
SimoneTomasella2002 Nov 22, 2023
db9b650
Added Tests for Euro Class
SimoneTomasella2002 Nov 22, 2023
f275ef9
Updated file locations
SimoneTomasella2002 Nov 22, 2023
a27d67b
added testATM placeholders
ThomasGhione Nov 24, 2023
3a39abd
Finished test on TestAccount and TestBankDatabase
SimoneTomasella2002 Nov 26, 2023
cac1cbd
added last test cases
ThomasGhione Nov 27, 2023
cd0ecc8
Co-authored-by: SimoneTomasella <Simo64Terminator@users.noreply.githu…
ThomasGhione Nov 27, 2023
4282279
added componenti.txt
ThomasGhione Nov 28, 2023
15e96e9
Fixed Merge Conflict in local repo
ThomasGhione Nov 28, 2023
992a8fd
Added File componenti.txt
ThomasGhione Nov 28, 2023
ce94a92
Merge branch 'main' of https://github.com/ThomasGhione/ATM
ThomasGhione Nov 28, 2023
21d459f
Committed .class files
ThomasGhione Nov 28, 2023
bba2b2b
Merge branch 'main' into hotfix
ThomasGhione Nov 28, 2023
294034a
trying to force a merge conflict in ATMCaseStudy
ThomasGhione Nov 28, 2023
6871e1b
Updated componenti.txt
SimoneTomasella2002 Nov 28, 2023
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
24 changes: 24 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
replay_pid*
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.
4 changes: 4 additions & 0 deletions componenti.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Thomas Ghione 5254284
Simone Tomasella 5311626

Abbiamo avuto un merge conflict da feature a main, ma non siamo sicuri sia evidente nel DAG, se vuole possiamo mostrarglielo direttamente a lezione se lo ritiene necessario
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
package code.Business_Logic;

import code.GUI.ATM;
// ATMCaseStudy.java
// Driver program for the ATM case study

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
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
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: 11 additions & 10 deletions src/Account.java → src/code/Database/Account.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
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 +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
15 changes: 8 additions & 7 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,12 +10,12 @@ 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
private Account getAccount( int accountNumber )
public Account getAccount( int accountNumber )
{
// loop through accounts searching for matching account number
for ( Account currentAccount : accounts )
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
48 changes: 48 additions & 0 deletions src/code/Database/Euro.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
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 String stampa(){
return (double)valore/100 +" euro";
}
}
6 changes: 6 additions & 0 deletions src/ATM.java → src/code/GUI/ATM.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package code.GUI;
// ATM.java
// Represents an automated teller machine

import code.Business_Logic.CashDispenser;
import code.Business_Logic.DepositSlot;
import code.Business_Logic.Transaction;
import code.Database.BankDatabase;

public class ATM
{
private boolean userAuthenticated; // whether user is authenticated
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.Database.BankDatabase;
import code.Database.Euro;

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
16 changes: 11 additions & 5 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;
// Deposit.java
// Represents a deposit ATM transaction

import code.Business_Logic.DepositSlot;
import code.Business_Logic.Transaction;
import code.Database.BankDatabase;
import code.Database.Euro;

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.getValore() != 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);
else
{
return ( double ) input / 100; // return dollar amount
return new Euro(input / 100); // return dollar amount
} // end else
} // end method promptForDepositAmount
} // end class Deposit
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.Database.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
12 changes: 9 additions & 3 deletions src/Withdrawal.java → src/code/GUI/Withdrawal.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package code.GUI;
// Withdrawal.java
// Represents a withdrawal ATM transaction

import code.Business_Logic.CashDispenser;
import code.Business_Logic.Transaction;
import code.Database.BankDatabase;
import code.Database.Euro;

public class Withdrawal extends Transaction
{
private int amount; // amount to withdraw
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 @@ -47,13 +53,13 @@ public void execute()
bankDatabase.getAvailableBalance( getAccountNumber() );

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

cashDispenser.dispenseCash( amount ); // dispense cash
cashDispensed = true; // cash was dispensed
Expand Down
Loading