Skip to content

Commit

Permalink
Merge branch 'master' into junRong-DG-Introduction
Browse files Browse the repository at this point in the history
# Conflicts:
#	docs/DeveloperGuide.md
  • Loading branch information
itsmejr257 committed Mar 27, 2024
2 parents 0949fe5 + 63728c7 commit dd3f2f4
Show file tree
Hide file tree
Showing 46 changed files with 1,983 additions and 103 deletions.
299 changes: 284 additions & 15 deletions docs/DeveloperGuide.md

Large diffs are not rendered by default.

29 changes: 28 additions & 1 deletion docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ to deal with finances on a singular platform with ease as long as you can type f
7. List Savings
8. List Expense
9. Find Expense
10. Change Currency

### Display Commands : `menu`
Displays the corresponding features of BudgetBuddy
Expand Down Expand Up @@ -66,6 +67,16 @@ Format: `add savings c/CATEGORY a/AMOUNT`
* The `AMOUNT` must be a positive integer.
* The `DESCRIPTION` can be any string.

### Add Split Expenses
Add expenses that are meant for splitting among friends or colleague

Format: `split expenses a/AMOUNT n/NUMBER_OF_PEOPLE d/DESCRIPTION`

* Increments split expenses
* The `AMOUNT` must be a positive number
* The `NUMER_OF_PEOPLE` must be a positive integer.
* The `DESCRIPTION` can be any string

Example of usage:

`add savings c/Salary a/10000`
Expand Down Expand Up @@ -187,12 +198,28 @@ Examples of usage :
`find expenses d/coffee` : Finds all expenses with the word "coffee" in the description
`find expenses d/coffee morethan/200` : Finds all expenses with the word "coffee" and amount higher than $200

### Changing Currencies : `change currency [CURRENCY_CODE]`

Converts current currency to targeted currency

Format : `change currency [CURRENCY_CODE]`

* Default currency is 'SGD'.
* `CURRENCY_CODE` consists of the following currencies: 'SGD', 'USD', 'EUR', 'MYR', 'JPY', 'KRW', 'CNY', 'HKD'
* `CURRENCY_CODE` cannot be null.
* Conversion of Currency is interchangeable (e.g. SGD -> USD -> JPY)

Examples of usage:

`change currency USD` : Converts current currency into USD

## Command Summary
* Add Savings: `add savings c/CATEGORY a/AMOUNT`
* Add Expense: `add expense c/CATEGORY a/AMOUNT d/DESCRIPTION`
* Edit Expenses `edit expense c/CATEGORY i/INDEX a/AMOUNT d/DESCRIPTION`
* Edit Savings `edit savings c/CATEGORY i/INDEX a/AMOUNT`
* List Expenses: `list expenses CATEGORY`
* List Savings: `list savings CATEGORY`
* Find Expenses `find expenses [d/DESCRIPTION] [morethan/MINAMOUNT] [lessthan/MAXAMOUNT] `
* Find Expenses `find expenses [d/DESCRIPTION] [morethan/MINAMOUNT] [lessthan/MAXAMOUNT]`
* Change Currency `change currency [CURRENCY_CODE]`

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/diagrams/ExpenseList_SequenceDiagram.png
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.
Binary file added docs/diagrams/SavingList_SequenceDiagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/diagrams/SequenceDiagram_FindExpenses.jpg
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.
Binary file added docs/diagrams/sequenceDiagram_MenuFeature.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/team/EditExpenseSequence.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions docs/team/EditExpenseSequence.puml
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
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.3-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/seedu/budgetbuddy/Budget.java
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;
}
}
33 changes: 31 additions & 2 deletions src/main/java/seedu/budgetbuddy/BudgetBuddy.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,63 @@

import seedu.budgetbuddy.command.Command;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Scanner;

public class BudgetBuddy {
private Ui ui;
private Parser parser;
private ExpenseList expenses;
private SavingList savings;
private SplitExpenseList splitexpenses;
private RecurringExpensesList expensesList;

private Storage expensesStorage;
private Storage savingsStorage;


public BudgetBuddy() {
ui = new Ui();
parser = new Parser();
expenses = new ExpenseList();
savings = new SavingList();
expensesList = new RecurringExpensesList();
splitexpenses = new SplitExpenseList();
expensesStorage = new Storage("src/main/java/seedu/budgetbuddy/data/ExpenseFile.txt");
savingsStorage = new Storage("src/main/java/seedu/budgetbuddy/data/SavingsFile.txt");

}

public void handleCommands(String input) {
Command command = parser.parseCommand(expenses, savings, input);
Command command = parser.parseCommand(expenses, savings, splitexpenses, expensesList, input);


if (command != null) {
command.execute();
} else {
System.out.println("Invalid command");
System.out.println("(Invalid command)");
}

try {
expensesStorage.saveExpenses(expenses.getExpenses());
savingsStorage.saveSavings(savings.getSavings());
} catch (IOException e) {
System.out.println("Error saving expenses to file.");
}

}

public void run() {
Scanner scanner = new Scanner(System.in);

try {
this.expenses.getExpenses().addAll(expensesStorage.loadExpenses());
this.savings.getSavings().addAll(savingsStorage.loadSavings());
} catch (FileNotFoundException e) {
System.out.println("No existing expense file found. Starting fresh.");
}

ui.showWelcome();

boolean isExit = false;
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/seedu/budgetbuddy/CommandPrefix.java
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;
}

}
119 changes: 119 additions & 0 deletions src/main/java/seedu/budgetbuddy/CurrencyConverter.java
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());
}
}
}

}
Loading

0 comments on commit dd3f2f4

Please sign in to comment.