Skip to content

Commit

Permalink
#1305: Amended to Java indentation v2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
hheanly123 committed Oct 15, 2023
1 parent 017f3ec commit da32e25
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 130 deletions.
74 changes: 37 additions & 37 deletions money/src/main/java/com/iluwatar/Account.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ public class Account {
/**
* The primary currency for the account.
*/
private final Currency primaryCurrency;
private final Currency primaryCurrency;

/**
* The secondary currency for the account.
*/
private final Currency secondaryCurrency;
private final Currency secondaryCurrency;

/**
* The balance in the primary currency.
*/
private Money primaryBalance;
private Money primaryBalance;

/**
* The balance in the secondary currency.
Expand All @@ -60,11 +60,11 @@ public class 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;
this.primaryBalance = new Money(0, primaryCurrency);
this.secondaryBalance = new Money(0, secondaryCurrency);
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 @@ -74,13 +74,13 @@ public Account(final Currency pCurr, final Currency sCurr) {
* @throws IllegalArgumentException if the deposited money has an invalid
* currency.
*/
public void deposit(final Money money) {
validateCurrency(money);
if (money.getCurrency().equals(primaryCurrency)) {
primaryBalance = primaryBalance.add(money);
} else {
secondaryBalance = secondaryBalance.add(money);
}
public void deposit(final Money money) {
validateCurrency(money);
if (money.getCurrency().equals(primaryCurrency)) {
primaryBalance = primaryBalance.add(money);
} else {
secondaryBalance = secondaryBalance.add(money);
}
}

/**
Expand All @@ -90,21 +90,21 @@ public void deposit(final Money money) {
* @throws IllegalArgumentException if the withdrawn money has an invalid
* 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 "
+ "primary currency");
}
primaryBalance = primaryBalance.subtract(money);
} else {
if (secondaryBalance.getAmount() < money.getAmount()) {
throw new IllegalArgumentException("Insufficient balance in "
+ "secondary currency");
}
secondaryBalance = secondaryBalance.subtract(money);
public void withdraw(final Money money) {
validateCurrency(money);
if (money.getCurrency().equals(primaryCurrency)) {
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 "
+ "secondary currency");
}
secondaryBalance = secondaryBalance.subtract(money);
}
}

/**
Expand All @@ -115,20 +115,20 @@ public void withdraw(final Money money) {
* @throws IllegalArgumentException if the currency is invalid for this
* account.
*/
private void validateCurrency(final Money money) {
if (!money.getCurrency().equals(primaryCurrency)
&& !money.getCurrency().equals(secondaryCurrency)) {
throw new IllegalArgumentException("Invalid currency for this "
+ "account");
}
private void validateCurrency(final Money money) {
if (!money.getCurrency().equals(primaryCurrency)
&& !money.getCurrency().equals(secondaryCurrency)) {
throw new IllegalArgumentException("Invalid currency for this "
+ "account");
}
}

/**
* Gets the primary currency balance of the account.
*
* @return The primary currency balance.
*/
public Money getPrimaryBalance() {
public Money getPrimaryBalance() {
return primaryBalance;
}

Expand All @@ -137,7 +137,7 @@ public Money getPrimaryBalance() {
*
* @return The secondary currency balance.
*/
public Money getSecondaryBalance() {
public Money getSecondaryBalance() {
return secondaryBalance;
}
}
82 changes: 41 additions & 41 deletions money/src/main/java/com/iluwatar/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* displays the account balances.
*/
public final class App {
private App() {
private App() {
// Private constructor to hide the default public constructor
}

Expand All @@ -16,47 +16,47 @@ private App() {
*
* @param args Command-line arguments.
*/
public static void main(final String[] args) {
final Currency usd = Currency.usd();
final Currency eur = Currency.eur();

final Money money1 = new Money(10_000, usd);
final Money money2 = new Money(5_000, eur);
final int amount1 = 70;
final int amount2 = 30;

final Account account = new Account(usd, eur);

account.deposit(money1);
account.deposit(money2);

System.out.println("Primary Balance: "
+ account.getPrimaryBalance().getAmount()
+ " "
+ account.getPrimaryBalance().getCurrency().
getStringRepresentation());
System.out.println("Secondary Balance: "
+ account.getSecondaryBalance().getAmount()
public static void main(final String[] args) {
final Currency usd = Currency.usd();
final Currency eur = Currency.eur();

final Money money1 = new Money(10_000, usd);
final Money money2 = new Money(5_000, eur);
final int amount1 = 70;
final int amount2 = 30;

final Account account = new Account(usd, eur);

account.deposit(money1);
account.deposit(money2);

System.out.println("Primary Balance: "
+ account.getPrimaryBalance().getAmount()
+ " "
+ account.getPrimaryBalance().getCurrency().
getStringRepresentation());
System.out.println("Secondary Balance: "
+ account.getSecondaryBalance().getAmount()
+ " "
+ account.getSecondaryBalance().getCurrency().
getStringRepresentation());

final Money allocationMoney = new Money(6_000, usd);

final Account[] accounts = new Account[2];
accounts[0] = account;
accounts[1] = new Account(usd, eur);

allocationMoney.allocate(accounts, amount1, amount2);

System.out.println("Allocated Balances:");
for (int i = 0; i < accounts.length; i++) {
System.out.println("Account "
+ (i + 1)
+ ": " + accounts[i].getPrimaryBalance().getAmount()
+ " "
+ account.getSecondaryBalance().getCurrency().
+ accounts[i].getPrimaryBalance().getCurrency().
getStringRepresentation());

final Money allocationMoney = new Money(6_000, usd);

final Account[] accounts = new Account[2];
accounts[0] = account;
accounts[1] = new Account(usd, eur);

allocationMoney.allocate(accounts, amount1, amount2);

System.out.println("Allocated Balances:");
for (int i = 0; i < accounts.length; i++) {
System.out.println("Account "
+ (i + 1)
+ ": " + accounts[i].getPrimaryBalance().getAmount()
+ " "
+ accounts[i].getPrimaryBalance().getCurrency().
getStringRepresentation());
}
}
}
}
28 changes: 14 additions & 14 deletions money/src/main/java/com/iluwatar/Currency.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,22 @@ public class Currency {
/**
* The default cent factor for the currency.
*/
private static final int DEFAULT_VALUE = 100;
private static final int DEFAULT_VALUE = 100;

/**
* The factor used to convert currency amounts between whole numbers and
* cents. This is typically set to 100 for most currencies, where 1 unit is
* equivalent to 100 cents. Adjust this factor if the currency operates in
* a different denomination.
*/
private int centFactor;
private int centFactor;

/**
* A human-readable string representation of the money amount and currency.
* This string is used to display the money value to users or for debugging
* purposes.
*/
private String stringRepresentation;
private String stringRepresentation;

/**
* Constructs a Currency with the specified cent factor and string
Expand All @@ -62,44 +62,44 @@ public class 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;
}

/**
* Gets the cent factor for the currency.
*
* @return The cent factor of the currency.
*/
public int getCentFactor() {
return centFactor;
public int getCentFactor() {
return centFactor;
}

/**
* Gets the string representation of the currency.
*
* @return The string representation of the currency.
*/
public String getStringRepresentation() {
return stringRepresentation;
public String getStringRepresentation() {
return stringRepresentation;
}

/**
* Creates a new Currency instance representing the US Dollar (USD).
*
* @return A Currency instance for USD.
*/
public static Currency usd() {
return new Currency(DEFAULT_VALUE, "USD");
public static Currency usd() {
return new Currency(DEFAULT_VALUE, "USD");
}

/**
* Creates a new Currency instance representing the Euro (EUR).
*
* @return A Currency instance for EUR.
*/
public static Currency eur() {
return new Currency(DEFAULT_VALUE, "EUR");
public static Currency eur() {
return new Currency(DEFAULT_VALUE, "EUR");
}
}
Loading

0 comments on commit da32e25

Please sign in to comment.