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 #24 from yyangdaa/yangda
add addexpense & addsaving - yangda
- Loading branch information
Showing
16 changed files
with
283 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package seedu.budgetbuddy; | ||
|
||
public class BudgetBuddy { | ||
|
||
private static final Ui ui = new Ui(); | ||
private static final Parser parser = new Parser(); | ||
|
||
public static void main(String[] args) { | ||
ui.greet(); | ||
String input; | ||
while (true) { | ||
input = ui.readCommand(); | ||
if (input.equals("bye")) { | ||
break; | ||
} | ||
parser.parseInput(input); | ||
ui.showAdd(input); | ||
} | ||
ui.showGoodBye(); | ||
ui.closeScanner(); | ||
} | ||
} |
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,15 @@ | ||
package seedu.budgetbuddy; | ||
|
||
public class Expense extends Transaction{ | ||
protected String description; | ||
|
||
public Expense(String category, int amount, String description) { | ||
super(category, amount); | ||
this.description = description; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Category: " + category + " Amount: " + amount + " Description: " + description; | ||
} | ||
} |
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,29 @@ | ||
package seedu.budgetbuddy; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
|
||
public class ExpenseList { | ||
protected ArrayList <Expense> expenses; | ||
protected ArrayList<String> categories; | ||
|
||
public ExpenseList() { | ||
this.expenses = new ArrayList<>(); | ||
this.categories = new ArrayList<>(Arrays.asList("Housing", | ||
"Groceries", "Utility", "Transport", "Entertainment", "Others")); | ||
} | ||
|
||
public void addExpense(Expense expense) { | ||
expenses.add(expense); | ||
} | ||
|
||
public void addExpense(String category, String amount, String description) { | ||
int amountInt = Integer.parseInt(amount); | ||
Expense expense = new Expense(category, amountInt, description); | ||
expenses.add(expense); | ||
|
||
if (!categories.contains(category)) { | ||
categories.add(category); | ||
} | ||
} | ||
} |
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,50 @@ | ||
package seedu.budgetbuddy; | ||
|
||
public class Parser { | ||
|
||
public void parseInput(String input) { | ||
if (input.startsWith("add expense")) { | ||
String[] parts = input.split(" ", 2); | ||
parseExpense(parts[1]); | ||
} else if (input.startsWith("add saving")) { | ||
String[] parts = input.split(" ", 2); | ||
parseSaving(parts[1]); | ||
} else { | ||
System.out.println("Invalid input"); | ||
} | ||
} | ||
|
||
private void parseExpense(String details) { | ||
try { | ||
String category = extractDetail(details, "/c"); | ||
String amount = extractDetail(details, "/a"); | ||
String description = extractDetail(details, "/d"); | ||
TaskManager.addExpense(category, amount, description); | ||
} catch (Exception e) { | ||
System.out.println("Error parsing expense. Ensure the format is correct."); | ||
} | ||
} | ||
|
||
private void parseSaving(String details) { | ||
try { | ||
String category = extractDetail(details, "/c"); | ||
String amount = extractDetail(details, "/a"); | ||
TaskManager.addSaving(category, amount); | ||
} catch (Exception e) { | ||
System.out.println("Error parsing saving. Ensure the format is correct."); | ||
} | ||
} | ||
|
||
private String extractDetail(String details, String prefix) { | ||
int startIndex = details.indexOf(prefix) + prefix.length(); | ||
int endIndex = details.length(); | ||
|
||
String[] nextPrefixes = { "/c", "/a", "/d" }; | ||
for (String nextPrefix : nextPrefixes) { | ||
if (details.indexOf(nextPrefix, startIndex) != -1 && details.indexOf(nextPrefix, startIndex) < endIndex) { | ||
endIndex = details.indexOf(nextPrefix, startIndex); | ||
} | ||
} | ||
return details.substring(startIndex, endIndex).trim(); | ||
} | ||
} |
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,14 @@ | ||
package seedu.budgetbuddy; | ||
|
||
public class Saving extends Transaction{ | ||
|
||
public Saving(String category, int amount) { | ||
super(category, amount); | ||
} | ||
|
||
|
||
@Override | ||
public String toString() { | ||
return "Category: " + category + " Amount: " + amount; | ||
} | ||
} |
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,25 @@ | ||
package seedu.budgetbuddy; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
|
||
public class SavingList { | ||
protected ArrayList <Saving> savings; | ||
protected ArrayList<String> categories; | ||
|
||
public SavingList() { | ||
this.savings = new ArrayList<>(); | ||
this.categories = new ArrayList<>(Arrays.asList("Salary", | ||
"Investments", "Gifts", "Others")); | ||
} | ||
|
||
public void addSaving(String category, String amount) { | ||
int amountInt = Integer.parseInt(amount); | ||
Saving saving = new Saving(category, amountInt); | ||
savings.add(saving); | ||
|
||
if (!categories.contains(category)) { | ||
categories.add(category); | ||
} | ||
} | ||
} |
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,15 @@ | ||
package seedu.budgetbuddy; | ||
|
||
public class TaskManager { | ||
private static ExpenseList expenses = new ExpenseList(); | ||
private static SavingList savings = new SavingList(); | ||
|
||
public static void addExpense(String category, String amount, String description) { | ||
expenses.addExpense(category, amount, description); | ||
} | ||
|
||
public static void addSaving(String category, String amount) { | ||
savings.addSaving(category, amount); | ||
} | ||
} | ||
|
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,20 @@ | ||
package seedu.budgetbuddy; | ||
|
||
public abstract class Transaction { | ||
String category; | ||
int amount; | ||
String description; | ||
|
||
public Transaction(String category, int amount) { | ||
this.category = category; | ||
this.amount = amount; | ||
} | ||
|
||
public String getCategory() { | ||
return category; | ||
} | ||
|
||
public double getAmount() { | ||
return amount; | ||
} | ||
} |
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,63 @@ | ||
package seedu.budgetbuddy; | ||
|
||
import java.util.Scanner; | ||
|
||
public class Ui { | ||
private Scanner scanner; | ||
|
||
public Ui() { | ||
this.scanner = new Scanner(System.in); | ||
} | ||
|
||
public String readCommand() { | ||
return scanner.nextLine().trim(); | ||
} | ||
|
||
public void closeScanner() { | ||
scanner.close(); | ||
} | ||
|
||
public void greet() { | ||
String Logo = | ||
" ____ ____ \n" + | ||
" | __ )| __ ) \n" + | ||
" | _ \\| _ \\ \n" + | ||
" | |_) | |_) |\n" + | ||
" |____/|____/ \n"; | ||
System.out.println("Welcome to BudgetBuddy!\n" + Logo); | ||
System.out.println("What can I do for you?"); | ||
showLine(); | ||
} | ||
|
||
public void showLine() { | ||
System.out.println("____________________________________________________________"); | ||
} | ||
|
||
public void showError(String message){ | ||
System.out.println("an error occurred: " + message); | ||
} | ||
|
||
public void showGoodBye(){ | ||
System.out.println("Bye. Hope to see you again soon!"); | ||
} | ||
|
||
public void showList(String list) { | ||
showLine(); | ||
System.out.println(list); | ||
showLine(); | ||
} | ||
|
||
public void showAdd(String addedItem) { | ||
showLine(); | ||
System.out.println("Got it. I've added this transaction:"); | ||
System.out.println(addedItem); | ||
showLine(); | ||
} | ||
|
||
public void showDelete(String deletedItem) { | ||
showLine(); | ||
System.out.println("Noted. I've removed this transaction:"); | ||
System.out.println(deletedItem); | ||
showLine(); | ||
} | ||
} |
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,5 @@ | ||
package seedu.budgetbuddy.data; | ||
|
||
public class Storage { | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/seedu/budgetBuddy/exception/budgetBuddyException.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,7 @@ | ||
package seedu.budgetbuddy.exception; | ||
|
||
public class budgetBuddyException extends Exception{ | ||
public budgetBuddyException(String message) { | ||
super(message); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
9 changes: 7 additions & 2 deletions
9
src/test/java/seedu/duke/DukeTest.java → ...va/seedu/budgetBuddy/budgetBuddyTest.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 |
---|---|---|
@@ -1,12 +1,17 @@ | ||
package seedu.duke; | ||
package seedu.budgetBuddy; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
class DukeTest { | ||
class budgetBuddyTest { | ||
@Test | ||
public void sampleTest() { | ||
assertTrue(true); | ||
} | ||
|
||
@Test | ||
public void sampleFailingTest() { | ||
assertTrue(true); | ||
} | ||
} |
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,9 +1,10 @@ | ||
Hello from | ||
____ _ | ||
| _ \ _ _| | _____ | ||
| | | | | | | |/ / _ \ | ||
| |_| | |_| | < __/ | ||
|____/ \__,_|_|\_\___| | ||
Welcome to BudgetBuddy! | ||
____ ____ | ||
| __ )| __ ) | ||
| _ \| _ \ | ||
| |_) | |_) | | ||
|____/|____/ | ||
|
||
What is your name? | ||
Hello James Gosling | ||
What can I do for you? | ||
____________________________________________________________ | ||
Bye. Hope to see you again soon! |
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 @@ | ||
James Gosling | ||
bye |