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 pull request #9 from sweijie24/branch-Listing
Create lists for expenses and savings
- Loading branch information
Showing
12 changed files
with
255 additions
and
8 deletions.
There are no files selected for viewing
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
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
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
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
21 changes: 21 additions & 0 deletions
21
src/main/java/seedu/budgetbuddy/command/ListExpenseCommand.java
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,21 @@ | ||
package seedu.budgetbuddy.command; | ||
|
||
import seedu.budgetbuddy.ExpenseList; | ||
|
||
public class ListExpenseCommand extends Command { | ||
private ExpenseList expenses; | ||
private String filterCategory; | ||
public ListExpenseCommand(ExpenseList expenses) { | ||
this.expenses = expenses; | ||
} | ||
|
||
public ListExpenseCommand(ExpenseList expenses, String filterCategory) { | ||
this.expenses = expenses; | ||
this.filterCategory = filterCategory; | ||
} | ||
|
||
@Override | ||
public void execute() { | ||
expenses.listExpenses(filterCategory); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/seedu/budgetbuddy/command/ListSavingsCommand.java
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,27 @@ | ||
package seedu.budgetbuddy.command; | ||
|
||
import seedu.budgetbuddy.ExpenseList; | ||
import seedu.budgetbuddy.SavingList; | ||
|
||
public class ListSavingsCommand extends Command { | ||
private SavingList savings; | ||
private ExpenseList expenses; | ||
private String filterCategory; | ||
|
||
public ListSavingsCommand(SavingList savings, ExpenseList expenses) { | ||
this.savings = savings; | ||
this.expenses = expenses; | ||
} | ||
|
||
public ListSavingsCommand(SavingList savings, ExpenseList expenses, String filterCategory) { | ||
this.savings = savings; | ||
this.expenses = expenses; | ||
this.filterCategory = filterCategory; | ||
} | ||
|
||
@Override | ||
public void execute() { | ||
savings.listSavings(this.filterCategory, this.expenses); | ||
} | ||
} | ||
|
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,31 @@ | ||
package seedu.budgetbuddy; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
public class ExpenseListTest { | ||
|
||
@Test | ||
public void calculateTotalExpenses_addingIntegers_success() { | ||
ExpenseList expenseList = new ExpenseList(); | ||
expenseList.addExpense("Transport", "50", "Bus Fare"); | ||
expenseList.addExpense("Food", "30", "Lunch"); | ||
|
||
assertEquals(80, expenseList.calculateTotalExpenses()); | ||
} | ||
|
||
@Test | ||
public void calculateTotalExpenses_addingNegativeIntegers_exceptionThrown() { | ||
ExpenseList expenseList = new ExpenseList(); | ||
expenseList.addExpense("Transport", "-50", "Bus Fare"); | ||
expenseList.addExpense("Food", "-30", "Lunch"); | ||
|
||
try { | ||
assertEquals(0, expenseList.calculateTotalExpenses()); | ||
fail(); | ||
} catch (Exception e) { | ||
assertEquals("java.lang.Exception: Expenses should not be negative", e.getMessage()); | ||
} | ||
} | ||
} |
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,31 @@ | ||
package seedu.budgetbuddy; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
public class SavingListTest { | ||
|
||
@Test | ||
public void calculateRemainingSavings_sufficientFunds_success() { | ||
SavingList savingList = new SavingList(); | ||
double initialAmount = 1000; | ||
double totalExpenses = 200; | ||
double expectedRemaining = 800; | ||
|
||
double actualRemaining = savingList.calculateRemainingSavings(initialAmount, totalExpenses); | ||
|
||
assertEquals(expectedRemaining, actualRemaining); | ||
} | ||
|
||
@Test | ||
public void testCalculateRemainingSavings_insufficientFunds_exceptionThrown() { | ||
SavingList savingList = new SavingList(); | ||
double initialAmount = 100; | ||
double totalExpenses = 200; | ||
|
||
assertThrows(RuntimeException.class, () -> { | ||
savingList.calculateRemainingSavings(initialAmount, totalExpenses); | ||
}); | ||
} | ||
} |
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 |
---|---|---|
@@ -1 +1 @@ | ||
bye | ||
bye |