Skip to content

Commit

Permalink
Merge pull request #200 from yyangdaa/week-12
Browse files Browse the repository at this point in the history
Yangda - Bug Fixing & PPP
  • Loading branch information
yyangdaa authored Apr 9, 2024
2 parents 4e2746e + 8458c37 commit 21231cb
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 18 deletions.
1 change: 1 addition & 0 deletions data/DefaultCurrency.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Default Currency: SGD
6 changes: 0 additions & 6 deletions docs/team/johndoe.md

This file was deleted.

30 changes: 30 additions & 0 deletions docs/team/yyangdaa.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Zhang Yangda - Project Portfolio Page

## Overview
BudgetBuddy is a finance-tracking application designed for users seeking a centralized platform to manage and
monitor their finances. Tailored for individuals who value efficiency, BudgetBuddy simplifies the process of
tracking and calculating expenses. Its user-friendly interface caters to fast typists, making financial management
both quick and intuitive.
### Summary of Contributions
Given below are my contributions to the project

#### New Feature : Add Expense and Add Savings

1. What it does : Allows user to add expense and savings to the app for users to monitor their spending habits
and savings growth over time.
2. Justification : Users can save their spendings and savings.

#### New Feature : Add SplitExpense, List SplitExpense, and Settle SplitExpense
1. What is does : Allows users to add expenses that are meant to be split amoung friends. Allows users to check the
added list of expenses that are to be among the friends. The users can also settle the expense once others have paid.
2. Justification : This enhancement simplifies the task of tracking shared expenses, making it easier for users to
manage shared activities without the hassle of manual calculations.

#### Code Contributed
[RepoSenseLink](https://nus-cs2113-ay2324s2.github.io/tp-dashboard/?search=yyangdaa&breakdown=true&sort=groupTitle
%20dsc&sortWithin=title&since=2024-02-23&timeframe=commit&mergegroup=&groupSelect=groupByRepos&checkedFileTypes=
docs~functional-code~test-code~other)

#### Enhancements to existing features:
1. Wrote JUnit tests for the ExpenseList, SavingsList, SplitExpenseList and Parser.

34 changes: 34 additions & 0 deletions src/main/java/seedu/budgetbuddy/Storage.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package seedu.budgetbuddy;

import seedu.budgetbuddy.commons.Saving;
import seedu.budgetbuddy.commons.SplitExpense;
import seedu.budgetbuddy.commons.ExpenseList;
import seedu.budgetbuddy.commons.Expense;
import seedu.budgetbuddy.commons.RecurringExpensesList;
Expand Down Expand Up @@ -70,6 +71,7 @@ public void resetRecurringExpensesListFile() throws IOException {
file.createNewFile();
FileWriter writer = new FileWriter(filePath, false);
writer.write("");
writer.close();
}

public void parseRecurringExpensesFile(ArrayList<ExpenseList> recurringExpenses, String line)
Expand Down Expand Up @@ -233,6 +235,38 @@ public void saveCurrency() throws IOException {
}
}


public List<SplitExpense> loadSplitExpenses() throws FileNotFoundException {
File file = new File(filePath);
List<SplitExpense> splitExpenses = new ArrayList<>();
Scanner scanner = new Scanner(file);
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
String[] parts = line.split("\\|");
// Assuming the order is Date|Amount|Number of People|Description
String amount = parts[1].trim();
String numberOfPeople = parts[2].trim();
String description = parts[3].trim();
SplitExpense splitExpense = new SplitExpense(amount, numberOfPeople, description);
splitExpenses.add(splitExpense);
}
scanner.close();
return splitExpenses;
}

public void saveSplitExpenses(List<SplitExpense> splitExpenses) throws IOException {

ensureDirectoryExists();

FileWriter writer = new FileWriter(filePath, false);
for (SplitExpense splitExpense : splitExpenses) {
writer.write(String.format("%s | %s | %s\n",
splitExpense.getAmount(), splitExpense.getNumberOfPeople(), splitExpense.getDescription()));
}
writer.close();
}


/**
* Loads currency data from the specified file path and sets the default currency accordingly.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public String getDescription() {
public void execute() {
try {
splitexpenses.addSplitExpense(this.amount, this.numberOfPeople, this.description);
System.out.println("SplitExpense Added :" + "$" + amount + " spent by " +
System.out.println("SplitExpense Added: " + "$" + amount + " spent by " +
numberOfPeople + " persons. Description: " + description);
} catch (BudgetBuddyException e) {
System.out.println("An error occurred while adding expense.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public Command handleSettleExpenseCommand(String input, SplitExpenseList splitex
try {
int index = Integer.parseInt(parts[1]) - 1;
// Check if the index is within the bounds of the expense list.
if (index < 0 || index >= splitexpenses.size()) {
if (index < 0 || index >= splitexpenses.getSize()) {
System.out.println("Error: Index is out of bounds.");
return null;
}
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/seedu/budgetbuddy/commons/CurrencyConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,38 @@ public void convertSavingCurrency(Currency newCurrency, SavingList savings) {
}
}

public void convertSplitExpenseCurrency(Currency newCurrency, SplitExpenseList splitExpenses) {
if (splitExpenses == null) {
throw new IllegalArgumentException("SplitExpenseList cannot be null");
}

if (DefaultCurrency.getDefaultCurrency() == newCurrency) {
System.out.println("Same currency for Split Expenses. No Conversion needed");
return;
}

for (SplitExpense splitExpense : splitExpenses.getSplitExpenses()) {
if (splitExpense == null) {
LOGGER.warning("Skipping null split expense");
System.out.println("Skipping null split expense");
continue;
}

try {
double convertedAmount = convertAmount(splitExpense.getAmount(), splitExpense.getCurrency(),
newCurrency);
splitExpense.setAmount(convertedAmount);
splitExpense.setCurrency(newCurrency);
} catch (IllegalArgumentException e) {
// Handle any IllegalArgumentException thrown during conversion
LOGGER.severe("Error converting amount for split expense: " + e.getMessage());
System.out.println("Error converting amount for split expense: " + e.getMessage());
}
}

System.out.println("Default currency for Split Expenses changed to " + newCurrency);
}

public void convertRecurringExpensesCurrency(Currency newCurrency, RecurringExpensesList recurringExpensesList) {
if (recurringExpensesList == null) {
throw new IllegalArgumentException("SavingList cannot be null");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,4 @@ public ExpenseList getExpenseListAtListNumber(int listNumber) {
int listNumberAsArrayPosition = listNumber - 1;
return recurringExpenses.get(listNumberAsArrayPosition);
}



}
10 changes: 4 additions & 6 deletions src/main/java/seedu/budgetbuddy/commons/SplitExpense.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package seedu.budgetbuddy.commons;

public class SplitExpense {
public class SplitExpense extends Transaction{
private final String amount;
private final String description;
private final String numberOfPeople;

public SplitExpense(String amount, String numberOfPeople, String description) {
super("Split Expense", Double.parseDouble(amount));
this.amount = amount;
this.numberOfPeople = numberOfPeople;
this.description = description;
Expand All @@ -14,11 +15,7 @@ public SplitExpense(String amount, String numberOfPeople, String description) {
public String getNumberOfPeople() {
return numberOfPeople;
}

public String getAmount() {
return amount;
}


public String getDescription() {
return description;
}
Expand All @@ -38,4 +35,5 @@ public String toString() {
return "Number of People: " + numberOfPeople + " Amount: " + amount + " Description: " +
description + " Amount per person: " + calculateAmountPerPerson();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.logging.Logger;

public class SplitExpenseList {

private static final Logger LOGGER = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);
protected ArrayList <SplitExpense> splitexpenses;
public SplitExpenseList(ArrayList<SplitExpense> splitexpenses){
Expand All @@ -19,14 +20,19 @@ public SplitExpenseList() {
this.splitexpenses = new ArrayList<>();
}

public int size() {
public int getSize() {
return splitexpenses.size();
}

public List<SplitExpense> getSplitExpenses() {
return splitexpenses;
}

public SplitExpense getSplitExpenseListAtListNumber(int listNumber) {
int listNumberAsArrayPosition = listNumber - 1;
return splitexpenses.get(listNumberAsArrayPosition);
}

public void listSplitExpenses() {
LOGGER.info("Listing splitexpenses...");

Expand Down

0 comments on commit 21231cb

Please sign in to comment.