Skip to content

Commit

Permalink
Newlines
Browse files Browse the repository at this point in the history
  • Loading branch information
metaphori committed Feb 26, 2021
1 parent 1459544 commit 4e6e1b7
Show file tree
Hide file tree
Showing 9 changed files with 300 additions and 290 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto
50 changes: 25 additions & 25 deletions pps-lab01-intellij-basic-example/src/lab01/example/Main.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
package lab01.example;

import lab01.example.model.AccountHolder;
import lab01.example.model.BankAccount;
import lab01.example.model.SimpleBankAccount;

public class Main {

public static void main(String[] args) {
final AccountHolder accountHolder = new AccountHolder("Mario", "Rossi", 1);
final BankAccount bankAccount = new SimpleBankAccount(accountHolder, 0);

bankAccount.deposit(accountHolder.getId(), 100);

System.out.println("Current balance is " + bankAccount.getBalance());

bankAccount.withdraw(accountHolder.getId(), 30);

System.out.println("Current balance is " + bankAccount.getBalance());

bankAccount.withdraw(accountHolder.getId(), 80);

System.out.println("Current balance is " + bankAccount.getBalance());
}
}
package lab01.example;

import lab01.example.model.AccountHolder;
import lab01.example.model.BankAccount;
import lab01.example.model.SimpleBankAccount;

public class Main {

public static void main(String[] args) {
final AccountHolder accountHolder = new AccountHolder("Mario", "Rossi", 1);
final BankAccount bankAccount = new SimpleBankAccount(accountHolder, 0);

bankAccount.deposit(accountHolder.getId(), 100);

System.out.println("Current balance is " + bankAccount.getBalance());

bankAccount.withdraw(accountHolder.getId(), 30);

System.out.println("Current balance is " + bankAccount.getBalance());

bankAccount.withdraw(accountHolder.getId(), 80);

System.out.println("Current balance is " + bankAccount.getBalance());
}
}
Original file line number Diff line number Diff line change
@@ -1,51 +1,51 @@
package lab01.example.model;

/**
* This class represents the account holder concept.
* That is: a person that can subscribe a bank account.
*
* Each account holder has a name, a surname and an ID (unique in the bank system)
*/
public class AccountHolder {
private final int id;
private final String name;
private final String surname;

public AccountHolder(final String name, final String surname, final int id) {
this.name = name;
this.surname = surname;
this.id = id;
}

/**
* Retrieve the name of the the person registered as possible account holder
* @return the name of the holder
*/
public String getName() {
return this.name;
}

/**
* Retrieve the surname of the person registered as possible account holder
* @return the surname of the holder
*/
public String getSurname() {
return this.surname;
}

/**
* Retrieve the ID of the person registered as possible account holder
* @return the id of the holder
*/
public int getId() {
return this.id;
}

/**
* Provides a string representation
* @return the string representation for an AccountHolder instance
*/
public String toString() {
return String.format("[ID = %d] %s %s", this.id, this.name, this.surname);
}
}
package lab01.example.model;

/**
* This class represents the account holder concept.
* That is: a person that can subscribe a bank account.
*
* Each account holder has a name, a surname and an ID (unique in the bank system)
*/
public class AccountHolder {
private final int id;
private final String name;
private final String surname;

public AccountHolder(final String name, final String surname, final int id) {
this.name = name;
this.surname = surname;
this.id = id;
}

/**
* Retrieve the name of the the person registered as possible account holder
* @return the name of the holder
*/
public String getName() {
return this.name;
}

/**
* Retrieve the surname of the person registered as possible account holder
* @return the surname of the holder
*/
public String getSurname() {
return this.surname;
}

/**
* Retrieve the ID of the person registered as possible account holder
* @return the id of the holder
*/
public int getId() {
return this.id;
}

/**
* Provides a string representation
* @return the string representation for an AccountHolder instance
*/
public String toString() {
return String.format("[ID = %d] %s %s", this.id, this.name, this.surname);
}
}
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
package lab01.example.model;

/**
* This interface defines the concept of a very basic bank account.
*/
public interface BankAccount {

/**
* Allows to know who is the holder of this bank account
* @return the AccountHolder instance related to this bank account.
*/
AccountHolder getHolder();

/**
* Returns the current balance of the bank account
* @return the current balance
*/
double getBalance();

/**
* Allows the deposit of an amount on the account, if the given usrID corresponds to the register holder ID
* of the bank account. This ID acts like an "identification token" .
*
* @param usrID the id of the user that wants do the deposit
* @param amount the amount of the deposit
*/
void deposit(int usrID, double amount);

/**
* Allows the withdraw of an amount from the account, if the given usrID corresponds to the register holder ID
* of the bank account. This ID acts like an "identification token" .
*
* @param usrID the id of the user that wants do the withdraw
* @param amount the amount of the withdraw
*/
void withdraw(int usrID, double amount);
}
package lab01.example.model;

/**
* This interface defines the concept of a very basic bank account.
*/
public interface BankAccount {

/**
* Allows to know who is the holder of this bank account
* @return the AccountHolder instance related to this bank account.
*/
AccountHolder getHolder();

/**
* Returns the current balance of the bank account
* @return the current balance
*/
double getBalance();

/**
* Allows the deposit of an amount on the account, if the given usrID corresponds to the register holder ID
* of the bank account. This ID acts like an "identification token" .
*
* @param usrID the id of the user that wants do the deposit
* @param amount the amount of the deposit
*/
void deposit(int usrID, double amount);

/**
* Allows the withdraw of an amount from the account, if the given usrID corresponds to the register holder ID
* of the bank account. This ID acts like an "identification token" .
*
* @param usrID the id of the user that wants do the withdraw
* @param amount the amount of the withdraw
*/
void withdraw(int usrID, double amount);
}
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
package lab01.example.model;

/**
* This class represent a particular instance of a BankAccount.
* In particular, a Simple Bank Account allows always the deposit
* while the withdraw is allowed only if the balance greater or equal the withdrawal amount
*/
public class SimpleBankAccount implements BankAccount {

private double balance;
private final AccountHolder holder;

public SimpleBankAccount(final AccountHolder holder, final double balance) {
this.holder = holder;
this.balance = balance;
}
@Override
public AccountHolder getHolder(){
return this.holder;
}

@Override
public double getBalance() {
return this.balance;
}

@Override
public void deposit(final int usrID, final double amount) {
if (checkUser(usrID)) {
this.balance += amount;
}
}

@Override
public void withdraw(final int usrID, final double amount) {
if (checkUser(usrID) && isWithdrawAllowed(amount)) {
this.balance -= amount;
}
}

private boolean isWithdrawAllowed(final double amount){
return this.balance >= amount;
}

private boolean checkUser(final int id) {
return this.holder.getId() == id;
}
}
package lab01.example.model;

/**
* This class represent a particular instance of a BankAccount.
* In particular, a Simple Bank Account allows always the deposit
* while the withdraw is allowed only if the balance greater or equal the withdrawal amount
*/
public class SimpleBankAccount implements BankAccount {

private double balance;
private final AccountHolder holder;

public SimpleBankAccount(final AccountHolder holder, final double balance) {
this.holder = holder;
this.balance = balance;
}
@Override
public AccountHolder getHolder(){
return this.holder;
}

@Override
public double getBalance() {
return this.balance;
}

@Override
public void deposit(final int usrID, final double amount) {
if (checkUser(usrID)) {
this.balance += amount;
}
}

@Override
public void withdraw(final int usrID, final double amount) {
if (checkUser(usrID) && isWithdrawAllowed(amount)) {
this.balance -= amount;
}
}

private boolean isWithdrawAllowed(final double amount){
return this.balance >= amount;
}

private boolean checkUser(final int id) {
return this.holder.getId() == id;
}
}
Loading

0 comments on commit 4e6e1b7

Please sign in to comment.