forked from nus-cs2113-AY2324S2/tp
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into junRong-DG-Introduction
# Conflicts: # docs/DeveloperGuide.md
- Loading branch information
Showing
46 changed files
with
1,983 additions
and
103 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
@startuml | ||
actor User | ||
participant "BudgetBuddy" as BB | ||
participant "Parser" as P | ||
participant "EditExpenseCommand" as EEC | ||
participant "ExpenseList" as EL | ||
participant "Expense" as E | ||
|
||
User -> BB: inputCommand("edit expense c/Category i/Index a/Amount d/Description") | ||
activate BB | ||
BB -> P: parseCommand(input) | ||
activate P | ||
P -> EEC: new EditExpenseCommand(expenses, category, index, amount, description) | ||
activate EEC | ||
P --> BB: command | ||
deactivate P | ||
BB -> EEC: execute() | ||
activate EEC | ||
EEC -> EL: editExpense(category, index, amount, description) | ||
activate EL | ||
EL -> E: getExpense(index) | ||
activate E | ||
E -> E: setCategory(category) | ||
E -> E: setAmount(amount) | ||
E -> E: setDescription(description) | ||
E --> EL: expenseUpdated | ||
deactivate E | ||
EL --> EEC: editConfirmed | ||
deactivate EL | ||
EEC --> BB: commandExecuted | ||
deactivate EEC | ||
BB --> User: "Expense edited successfully." | ||
deactivate BB | ||
@enduml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package seedu.budgetbuddy; | ||
|
||
public class Budget { | ||
private String category; | ||
private double budget; | ||
|
||
public Budget(String category, double budget){ | ||
this.category = category; | ||
this.budget = budget; | ||
} | ||
|
||
public String getCategory(){ | ||
return category; | ||
} | ||
|
||
public double getBudget() { | ||
return budget; | ||
} | ||
|
||
public void setBudget(double budget){ | ||
this.budget = budget; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package seedu.budgetbuddy; | ||
|
||
public enum CommandPrefix { | ||
FIND(new String[]{"d/", "morethan/", "lessthan/"}), | ||
REC(new String[]{"to/", "c/", "a/", "d/"}), | ||
ADD(new String[]{"c/", "a/", "d/"}); | ||
|
||
private final String[] nextPrefixes; | ||
|
||
CommandPrefix(String[] nextPrefixes) { | ||
this.nextPrefixes = nextPrefixes; | ||
} | ||
|
||
public String[] getNextPrefixes() { | ||
return nextPrefixes; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
package seedu.budgetbuddy; | ||
|
||
import java.util.Currency; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.logging.Logger; | ||
|
||
public class CurrencyConverter { | ||
|
||
private static final Logger LOGGER = Logger.getLogger(CurrencyConverter.class.getName()); | ||
private Map<Currency, Double> exchangeRates; | ||
public CurrencyConverter() { | ||
this.exchangeRates = new HashMap<>(); | ||
// Initialize exchange rates with default values | ||
exchangeRates.put(Currency.getInstance("SGD"), 1.0); | ||
exchangeRates.put(Currency.getInstance("USD"), 0.75); | ||
exchangeRates.put(Currency.getInstance("EUR"), 0.68); | ||
exchangeRates.put(Currency.getInstance("JPY"), 112.25); | ||
exchangeRates.put(Currency.getInstance("KRW"), 996.85); | ||
exchangeRates.put(Currency.getInstance("MYR"), 3.51); | ||
exchangeRates.put(Currency.getInstance("CNY"), 5.36); | ||
exchangeRates.put(Currency.getInstance("HKD"), 5.80); | ||
} | ||
|
||
public double convertAmount(double amount, Currency fromCurrency, Currency toCurrency) { | ||
// Check if exchange rates for both currencies are available | ||
if (!exchangeRates.containsKey(fromCurrency) || !exchangeRates.containsKey(toCurrency)) { | ||
LOGGER.warning("Exchange rates not available for one or more currencies"); | ||
throw new IllegalArgumentException("Exchange rates not available for one or more currencies"); | ||
} | ||
assert exchangeRates.containsKey(fromCurrency) : "Exchange rates not available for fromCurrency: " | ||
+ fromCurrency; | ||
assert exchangeRates.containsKey(toCurrency) : "Exchange rates not available for toCurrency: " + toCurrency; | ||
|
||
|
||
double fromRate = exchangeRates.get(fromCurrency); | ||
double toRate = exchangeRates.get(toCurrency); | ||
|
||
if (fromRate <= 0 || toRate <= 0) { | ||
LOGGER.warning("Exchange rates must be positive numbers"); | ||
throw new IllegalArgumentException("Exchange rates must be positive numbers"); | ||
} | ||
// Check if exchange rates are positive numbers | ||
assert fromRate > 0 : "Exchange rate for fromCurrency must be a positive number: " + fromRate; | ||
assert toRate > 0 : "Exchange rate for toCurrency must be a positive number: " + toRate; | ||
|
||
LOGGER.info("Converting " + amount + " " + fromCurrency + " to " + toCurrency); | ||
|
||
if (!fromCurrency.equals(toCurrency)) { | ||
// Convert to SGD first | ||
double amountInSGD = amount / fromRate; | ||
// Then convert from SGD to the target currency | ||
double convertedAmount = amountInSGD * toRate; | ||
LOGGER.info("Conversion successful. Result: " + convertedAmount + " " + toCurrency); | ||
return convertedAmount; | ||
} else { | ||
// If the currencies are the same, no conversion needed | ||
LOGGER.info("Same currency. No conversion needed."); | ||
return amount; | ||
} | ||
} | ||
|
||
// Convert currencies in Expense List | ||
public void convertCurrency(Currency newCurrency, ExpenseList expenses) { | ||
// Check if the ExpenseList is not null | ||
if (expenses == null) { | ||
throw new IllegalArgumentException("ExpenseList cannot be null"); | ||
} | ||
assert expenses != null : "ExpenseList cannot be null"; | ||
|
||
for (Expense expense : expenses.getExpenses()) { | ||
// Skip if the current expense is null | ||
if (expense == null) { | ||
LOGGER.warning("Skipping null expense"); | ||
System.out.println("Skipping null expense"); | ||
continue; | ||
} | ||
|
||
try { | ||
double convertedAmount = convertAmount(expense.getAmount(), expense.getCurrency(), newCurrency); | ||
expense.setAmount(convertedAmount); | ||
expense.setCurrency(newCurrency); | ||
} catch (IllegalArgumentException e) { | ||
// Handle any IllegalArgumentException thrown during conversion | ||
LOGGER.severe("Error converting amount for expense: " + e.getMessage()); | ||
System.out.println("Error converting amount for expense: " + e.getMessage()); | ||
} | ||
} | ||
} | ||
|
||
// Convert currencies in Saving List | ||
public void convertCurrency(Currency newCurrency, SavingList savings) { | ||
// Check if the SavingList is not null | ||
if (savings == null) { | ||
throw new IllegalArgumentException("SavingList cannot be null"); | ||
} | ||
assert savings != null : "SavingList cannot be null"; | ||
|
||
for (Saving saving : savings.getSavings()) { | ||
// Skip if the current saving is null | ||
if (saving == null) { | ||
LOGGER.warning("Skipping null saving"); | ||
System.out.println("Skipping null saving"); | ||
continue; | ||
} | ||
|
||
try { | ||
double convertedAmount = convertAmount(saving.getAmount(), saving.getCurrency(), newCurrency); | ||
saving.setAmount(convertedAmount); | ||
saving.setCurrency(newCurrency); | ||
} catch (IllegalArgumentException e) { | ||
// Handle any IllegalArgumentException thrown during conversion | ||
LOGGER.severe("Error converting amount for saving: " + e.getMessage()); | ||
System.out.println("Error converting amount for saving: " + e.getMessage()); | ||
} | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.