Skip to content

Commit

Permalink
iluwatar#1305: Amended to Java indentation v4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
hheanly123 committed Oct 15, 2023
1 parent faaa2c1 commit 66a2f61
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 41 deletions.
46 changes: 23 additions & 23 deletions money/src/main/java/com/iluwatar/Account.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
}

Expand All @@ -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);
Expand All @@ -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");
}
}
Expand All @@ -129,15 +129,15 @@ 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.
*
* @return The secondary currency balance.
*/
public Money getSecondaryBalance() {
return secondaryBalance;
}
return secondaryBalance;
}
}
10 changes: 5 additions & 5 deletions money/src/main/java/com/iluwatar/Currency.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
26 changes: 13 additions & 13 deletions money/src/main/java/com/iluwatar/Money.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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;
}
}

Expand All @@ -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");
}
}
Expand Down

0 comments on commit 66a2f61

Please sign in to comment.