From 4e6e1b720510d2a63b2f8bd272ec9f9cf20a5e5b Mon Sep 17 00:00:00 2001 From: Roberto Casadei Date: Fri, 26 Feb 2021 16:15:07 +0100 Subject: [PATCH] Newlines --- .gitattributes | 1 + .../src/lab01/example/Main.java | 50 ++++---- .../lab01/example/model/AccountHolder.java | 102 ++++++++--------- .../src/lab01/example/model/BankAccount.java | 74 ++++++------ .../example/model/SimpleBankAccount.java | 96 ++++++++-------- .../test/SimpleBankAccountTest.java | 106 ++++++++--------- pps-lab01-tdd/src/lab01/tdd/CircularList.java | 108 +++++++++--------- .../src/lab01/tdd/SelectStrategy.java | 28 ++--- pps-lab01-tdd/test/CircularListTest.java | 25 ++-- 9 files changed, 300 insertions(+), 290 deletions(-) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..176a458 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto diff --git a/pps-lab01-intellij-basic-example/src/lab01/example/Main.java b/pps-lab01-intellij-basic-example/src/lab01/example/Main.java index fb2a148..526332e 100644 --- a/pps-lab01-intellij-basic-example/src/lab01/example/Main.java +++ b/pps-lab01-intellij-basic-example/src/lab01/example/Main.java @@ -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()); + } +} diff --git a/pps-lab01-intellij-basic-example/src/lab01/example/model/AccountHolder.java b/pps-lab01-intellij-basic-example/src/lab01/example/model/AccountHolder.java index 241e804..9030fe4 100644 --- a/pps-lab01-intellij-basic-example/src/lab01/example/model/AccountHolder.java +++ b/pps-lab01-intellij-basic-example/src/lab01/example/model/AccountHolder.java @@ -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); + } +} diff --git a/pps-lab01-intellij-basic-example/src/lab01/example/model/BankAccount.java b/pps-lab01-intellij-basic-example/src/lab01/example/model/BankAccount.java index 2bd51bf..12a5778 100644 --- a/pps-lab01-intellij-basic-example/src/lab01/example/model/BankAccount.java +++ b/pps-lab01-intellij-basic-example/src/lab01/example/model/BankAccount.java @@ -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); +} diff --git a/pps-lab01-intellij-basic-example/src/lab01/example/model/SimpleBankAccount.java b/pps-lab01-intellij-basic-example/src/lab01/example/model/SimpleBankAccount.java index 76bea24..cc5d63b 100644 --- a/pps-lab01-intellij-basic-example/src/lab01/example/model/SimpleBankAccount.java +++ b/pps-lab01-intellij-basic-example/src/lab01/example/model/SimpleBankAccount.java @@ -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; + } +} diff --git a/pps-lab01-intellij-basic-example/test/SimpleBankAccountTest.java b/pps-lab01-intellij-basic-example/test/SimpleBankAccountTest.java index b85abf0..ba4ebe2 100644 --- a/pps-lab01-intellij-basic-example/test/SimpleBankAccountTest.java +++ b/pps-lab01-intellij-basic-example/test/SimpleBankAccountTest.java @@ -1,53 +1,53 @@ -import lab01.example.model.AccountHolder; -import lab01.example.model.BankAccount; -import lab01.example.model.SimpleBankAccount; - -import org.junit.jupiter.api.*; -import static org.junit.jupiter.api.Assertions.*; - -/** - * The test suite for testing the SimpleBankAccount implementation - */ -class SimpleBankAccountTest { - - private AccountHolder accountHolder; - private BankAccount bankAccount; - - @BeforeEach - void beforeEach(){ - accountHolder = new AccountHolder("Mario", "Rossi", 1); - bankAccount = new SimpleBankAccount(accountHolder, 0); - } - - @Test - void testInitialBalance() { - assertEquals(0, bankAccount.getBalance()); - } - - @Test - void testDeposit() { - bankAccount.deposit(accountHolder.getId(), 100); - assertEquals(100, bankAccount.getBalance()); - } - - @Test - void testWrongDeposit() { - bankAccount.deposit(accountHolder.getId(), 100); - bankAccount.deposit(2, 50); - assertEquals(100, bankAccount.getBalance()); - } - - @Test - void testWithdraw() { - bankAccount.deposit(accountHolder.getId(), 100); - bankAccount.withdraw(accountHolder.getId(), 70); - assertEquals(30, bankAccount.getBalance()); - } - - @Test - void testWrongWithdraw() { - bankAccount.deposit(accountHolder.getId(), 100); - bankAccount.withdraw(2, 70); - assertEquals(100, bankAccount.getBalance()); - } -} +import lab01.example.model.AccountHolder; +import lab01.example.model.BankAccount; +import lab01.example.model.SimpleBankAccount; + +import org.junit.jupiter.api.*; +import static org.junit.jupiter.api.Assertions.*; + +/** + * The test suite for testing the SimpleBankAccount implementation + */ +class SimpleBankAccountTest { + + private AccountHolder accountHolder; + private BankAccount bankAccount; + + @BeforeEach + void beforeEach(){ + accountHolder = new AccountHolder("Mario", "Rossi", 1); + bankAccount = new SimpleBankAccount(accountHolder, 0); + } + + @Test + void testInitialBalance() { + assertEquals(0, bankAccount.getBalance()); + } + + @Test + void testDeposit() { + bankAccount.deposit(accountHolder.getId(), 100); + assertEquals(100, bankAccount.getBalance()); + } + + @Test + void testWrongDeposit() { + bankAccount.deposit(accountHolder.getId(), 100); + bankAccount.deposit(2, 50); + assertEquals(100, bankAccount.getBalance()); + } + + @Test + void testWithdraw() { + bankAccount.deposit(accountHolder.getId(), 100); + bankAccount.withdraw(accountHolder.getId(), 70); + assertEquals(30, bankAccount.getBalance()); + } + + @Test + void testWrongWithdraw() { + bankAccount.deposit(accountHolder.getId(), 100); + bankAccount.withdraw(2, 70); + assertEquals(100, bankAccount.getBalance()); + } +} diff --git a/pps-lab01-tdd/src/lab01/tdd/CircularList.java b/pps-lab01-tdd/src/lab01/tdd/CircularList.java index 63fa6c0..9c831c0 100644 --- a/pps-lab01-tdd/src/lab01/tdd/CircularList.java +++ b/pps-lab01-tdd/src/lab01/tdd/CircularList.java @@ -1,54 +1,54 @@ -package lab01.tdd; - -import java.util.Optional; - -/** - * Represents a circular list of integers, where the following element of the last one into the list - * is the first element of the list itself. - */ -public interface CircularList { - - /** - * Adds an element into the first available place - * @param element the element to be added to the list - */ - void add(final int element); - - /** - * Provides the current size of the list - * @return the size of the list - */ - int size(); - - /** - * Check if the list is empty - * @return true if the list is empty, false otherwise - */ - boolean isEmpty(); - - /** - * Provides the next element of the list. Example: having a list like {1,2,3} the first call of next() returns 1, - * the second call returns 2, then 3 is returned at the third call. Finally the fourth one return 1 again, - * because the circular mechanism. - * @return the next element into the list - */ - Optional next(); - - /** - * Provides the previous element of the list. Its behaviour is dual of the next() method. - * @return the previous element into the list - */ - Optional previous(); - - /** - * Reset the current element to the first one of the list. The first one is the first added to the list. - */ - void reset(); - - /** - * Provides the next element of the list according to the injected strategy. - * @param strategy the strategy to be used (e.g., the next even element, the next odd element, etc.) - * @return the next element of the list according to the strategy. - */ - Optional next(final SelectStrategy strategy); -} +package lab01.tdd; + +import java.util.Optional; + +/** + * Represents a circular list of integers, where the following element of the last one into the list + * is the first element of the list itself. + */ +public interface CircularList { + + /** + * Adds an element into the first available place + * @param element the element to be added to the list + */ + void add(final int element); + + /** + * Provides the current size of the list + * @return the size of the list + */ + int size(); + + /** + * Check if the list is empty + * @return true if the list is empty, false otherwise + */ + boolean isEmpty(); + + /** + * Provides the next element of the list. Example: having a list like {1,2,3} the first call of next() returns 1, + * the second call returns 2, then 3 is returned at the third call. Finally the fourth one return 1 again, + * because the circular mechanism. + * @return the next element into the list + */ + Optional next(); + + /** + * Provides the previous element of the list. Its behaviour is dual of the next() method. + * @return the previous element into the list + */ + Optional previous(); + + /** + * Reset the current element to the first one of the list. The first one is the first added to the list. + */ + void reset(); + + /** + * Provides the next element of the list according to the injected strategy. + * @param strategy the strategy to be used (e.g., the next even element, the next odd element, etc.) + * @return the next element of the list according to the strategy. + */ + Optional next(final SelectStrategy strategy); +} diff --git a/pps-lab01-tdd/src/lab01/tdd/SelectStrategy.java b/pps-lab01-tdd/src/lab01/tdd/SelectStrategy.java index a5061ab..02d82f3 100644 --- a/pps-lab01-tdd/src/lab01/tdd/SelectStrategy.java +++ b/pps-lab01-tdd/src/lab01/tdd/SelectStrategy.java @@ -1,14 +1,14 @@ -package lab01.tdd; - -/** - * Represent a select Strategy to be applied to determine which is the next element to chose in a CircularList - */ -public interface SelectStrategy { - - /** - * Determines if the element satisfies the strategy - * @param element the element to be checked - * @return true if the element satisfies the strategy, false otherwise - */ - boolean apply(final int element); -} +package lab01.tdd; + +/** + * Represent a select Strategy to be applied to determine which is the next element to chose in a CircularList + */ +public interface SelectStrategy { + + /** + * Determines if the element satisfies the strategy + * @param element the element to be checked + * @return true if the element satisfies the strategy, false otherwise + */ + boolean apply(final int element); +} diff --git a/pps-lab01-tdd/test/CircularListTest.java b/pps-lab01-tdd/test/CircularListTest.java index 5c7a972..2fcd77b 100644 --- a/pps-lab01-tdd/test/CircularListTest.java +++ b/pps-lab01-tdd/test/CircularListTest.java @@ -1,8 +1,17 @@ -/** - * The test suite for testing the CircularList implementation - */ -public class CircularListTest { - - //TODO: test implementation - -} +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; + +/** + * The test suite for testing the CircularList implementation + */ +public class CircularListTest { + + //TODO: test implementation + + @Disabled + @Test public void testTodo(){ + Assertions.fail(); + } + +}