diff --git a/money/src/main/java/com/iluwatar/Account.java b/money/src/main/java/com/iluwatar/Account.java index d2dfdd1c6323..2e4ebf3e58eb 100644 --- a/money/src/main/java/com/iluwatar/Account.java +++ b/money/src/main/java/com/iluwatar/Account.java @@ -48,21 +48,21 @@ public class Account { */ private Money primaryBalance; - /** - * The balance in the secondary currency. - */ - private Money secondaryBalance; + /** + * The balance in the secondary currency. + */ + private Money secondaryBalance; /** * Constructs an Account with the specified primary and secondary * currencies. * - * @param pCurr The primary currency for the account. - * @param sCurr The secondary currency for the account. + * @param pcurr The primary currency for the account. + * @param scurr The secondary currency for the account. */ - public Account(final Currency pCurr, final Currency sCurr) { - this.primaryCurrency = pCurr; - this.secondaryCurrency = sCurr; + public Account(final Currency pcurr, final Currency scurr) { + this.primaryCurrency = pcurr; + this.secondaryCurrency = scurr; this.primaryBalance = new Money(0, primaryCurrency); this.secondaryBalance = new Money(0, secondaryCurrency); } @@ -72,14 +72,14 @@ public Account(final Currency pCurr, final Currency sCurr) { * * @param money The Money object to deposit into the account. * @throws IllegalArgumentException if the deposited money has an invalid - * currency. + * currency. */ public void deposit(final Money money) { validateCurrency(money); if (money.getCurrency().equals(primaryCurrency)) { - primaryBalance = primaryBalance.add(money); + primaryBalance = primaryBalance.add(money); } else { - secondaryBalance = secondaryBalance.add(money); + secondaryBalance = secondaryBalance.add(money); } } @@ -88,19 +88,19 @@ public void deposit(final Money money) { * * @param money The Money object to withdraw from the account. * @throws IllegalArgumentException if the withdrawn money has an invalid - * currency or if there is insufficient balance. + * currency or if there is insufficient balance. */ public void withdraw(final Money money) { validateCurrency(money); if (money.getCurrency().equals(primaryCurrency)) { - if (primaryBalance.getAmount() < money.getAmount()) { - throw new IllegalArgumentException("Insufficient balance in " + if (primaryBalance.getAmount() < money.getAmount()) { + throw new IllegalArgumentException("Insufficient balance in " + "primary currency"); - } + } primaryBalance = primaryBalance.subtract(money); } else { if (secondaryBalance.getAmount() < money.getAmount()) { - throw new IllegalArgumentException("Insufficient balance in " + throw new IllegalArgumentException("Insufficient balance in " + "secondary currency"); } secondaryBalance = secondaryBalance.subtract(money); @@ -113,12 +113,12 @@ public void withdraw(final Money money) { * * @param money The Money object to validate. * @throws IllegalArgumentException if the currency is invalid for this - * account. + * account. */ private void validateCurrency(final Money money) { if (!money.getCurrency().equals(primaryCurrency) && !money.getCurrency().equals(secondaryCurrency)) { - throw new IllegalArgumentException("Invalid currency for this " + throw new IllegalArgumentException("Invalid currency for this " + "account"); } } @@ -129,8 +129,8 @@ private void validateCurrency(final Money money) { * @return The primary currency balance. */ public Money getPrimaryBalance() { - return primaryBalance; - } + return primaryBalance; + } /** * Gets the secondary currency balance of the account. @@ -138,6 +138,6 @@ public Money getPrimaryBalance() { * @return The secondary currency balance. */ public Money getSecondaryBalance() { - return secondaryBalance; - } + return secondaryBalance; + } } diff --git a/money/src/main/java/com/iluwatar/Currency.java b/money/src/main/java/com/iluwatar/Currency.java index b7a183f18b29..3440313c7511 100644 --- a/money/src/main/java/com/iluwatar/Currency.java +++ b/money/src/main/java/com/iluwatar/Currency.java @@ -58,12 +58,12 @@ public class Currency { * Constructs a Currency with the specified cent factor and string * representation. * - * @param cF The cent factor for the currency. - * @param sR The string representation of the currency. + * @param cf The cent factor for the currency. + * @param sr The string representation of the currency. */ - public Currency(final int cF, final String sR) { - this.centFactor = cF; - this.stringRepresentation = sR; + public Currency(final int cf, final String sr) { + this.centFactor = cf; + this.stringRepresentation = sr; } /** diff --git a/money/src/main/java/com/iluwatar/Money.java b/money/src/main/java/com/iluwatar/Money.java index 0e664f6abe03..17bc3ef6d19e 100644 --- a/money/src/main/java/com/iluwatar/Money.java +++ b/money/src/main/java/com/iluwatar/Money.java @@ -83,7 +83,7 @@ public Currency getCurrency() { * @param other The Money object to add. * @return A new Money object representing the result of the addition. * @throws IllegalArgumentException if the currencies of the two Money - * objects are not the same. + * objects are not the same. */ public Money add(final Money other) { validateSameCurrency(other); @@ -96,13 +96,13 @@ public Money add(final Money other) { * @param other The Money object to subtract. * @return A new Money object representing the result of the subtraction. * @throws IllegalArgumentException if the currencies of the two Money - * objects are not the same, - * or if the subtraction would result in a negative amount. + * objects are not the same, or if the subtraction would result in a + * negative amount. */ public Money subtract(final Money other) { validateSameCurrency(other); if (this.amount < other.amount) { - throw new IllegalArgumentException("Subtracted money is more than " + throw new IllegalArgumentException("Subtracted money is more than " + "what we have"); } return new Money(this.amount - other.amount, this.currency); @@ -126,18 +126,18 @@ public Money multiplyBy(final double multiplier) { * @param accounts An array of Account objects to allocate the money to. * @param percentages The percentages to allocate to each account. * @throws IllegalArgumentException if the sum of percentages is not 100% - * or if the currencies of Money and accounts are not the same. + * or if the currencies of Money and accounts are not the same. */ public void allocate(final Account[] accounts, final int... percentages) { long remainingAmount = this.amount; for (int i = 0; i < accounts.length; i++) { - long allocation = (long) (this.amount * percentages[i] + long allocation = (long) (this.amount * percentages[i] / DEFAULT_AMOUNT); - if (i == accounts.length - 1) { - allocation = remainingAmount; - } - accounts[i].deposit(new Money(allocation, this.currency)); - remainingAmount -= allocation; + if (i == accounts.length - 1) { + allocation = remainingAmount; + } + accounts[i].deposit(new Money(allocation, this.currency)); + remainingAmount -= allocation; } } @@ -147,11 +147,11 @@ public void allocate(final Account[] accounts, final int... percentages) { * * @param other The Money object to validate. * @throws IllegalArgumentException if the currencies of the two Money - * objects are not the same. + * objects are not the same. */ private void validateSameCurrency(final Money other) { if (!this.currency.equals(other.currency)) { - throw new IllegalArgumentException("Money objects must have the " + throw new IllegalArgumentException("Money objects must have the " + "same currency"); } }