From 050c2c297c33d362a3c9e66fe2748a501b3921c6 Mon Sep 17 00:00:00 2001
From: Dylan Siew <88567790+dylansiew@users.noreply.github.com>
Date: Tue, 5 Mar 2024 21:55:51 +0800
Subject: [PATCH 001/208] Update README.md
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index f82e2494b7..53fcf874a7 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-# Duke project template
+# Finance Calculator
This is a project template for a greenfield Java project. It's named after the Java mascot _Duke_. Given below are instructions on how to use it.
From 9a1d4445c0f20ecfd12634823e39927005bc9074 Mon Sep 17 00:00:00 2001
From: Chong Xern <104547209+ChongXern@users.noreply.github.com>
Date: Wed, 6 Mar 2024 19:40:47 +0800
Subject: [PATCH 002/208] Add classes for transaction, inflow and outflow
---
src/main/java/Main.class | Bin 0 -> 413 bytes
src/main/java/Main.java | 5 ++++
.../Inflow$Category.class | Bin 0 -> 1337 bytes
.../java/financialtransactions/Inflow.class | Bin 0 -> 718 bytes
.../java/financialtransactions/Inflow.java | 14 +++++++++++
.../Outflow$Category.class | Bin 0 -> 1345 bytes
.../java/financialtransactions/Outflow.class | Bin 0 -> 723 bytes
.../java/financialtransactions/Outflow.java | 14 +++++++++++
.../financialtransactions/Transaction.class | Bin 0 -> 780 bytes
.../financialtransactions/Transaction.java | 23 ++++++++++++++++++
10 files changed, 56 insertions(+)
create mode 100644 src/main/java/Main.class
create mode 100644 src/main/java/Main.java
create mode 100644 src/main/java/financialtransactions/Inflow$Category.class
create mode 100644 src/main/java/financialtransactions/Inflow.class
create mode 100644 src/main/java/financialtransactions/Inflow.java
create mode 100644 src/main/java/financialtransactions/Outflow$Category.class
create mode 100644 src/main/java/financialtransactions/Outflow.class
create mode 100644 src/main/java/financialtransactions/Outflow.java
create mode 100644 src/main/java/financialtransactions/Transaction.class
create mode 100644 src/main/java/financialtransactions/Transaction.java
diff --git a/src/main/java/Main.class b/src/main/java/Main.class
new file mode 100644
index 0000000000000000000000000000000000000000..18fbafd8af9f9e377492d1144c0b10294c47207c
GIT binary patch
literal 413
zcmZvY%Syvg5QhIr(xyqHt*x!sf-Z#Ag?WIAAcCuUfk-#5lJ-zfIY}fYijSoW1s6Vm
z4<*it3lVx2b2;
`aiWg#95bDP=mBk6c
z^oJ7%4LCMj4^4Rg@bLMe5D8OR$xFR)B_y-pI+tk?7P*L$Q3I=l=ABR~+k49LnR3y_
znvIT!F4hU%B})YRUQ4KyRsCPt>OR(#>3lSt*yt0ii%2qIon2A}S1Va|~HBIzz{j#ZP6FSyH;#br`?-lXN6P
zG#Wnpqm0kJjxd8UTe3bqr_b9xJ^lIX>kj}~Y)bGk%pO{f;nXa{_FThh8a2;qIL%bS
zIkX$^XL5#T)*J4JFc<-eGeJWH=
z2VNDn1TmmuP!PpZR^u5rR7Azp-Tc;`w#liRDuy`~ES0zOyPUbD;x!7$R@s#94=
zRAdAdI{BQ8unbkkpp2-DVa_e7c!XuHhS;ackc=mK)q^HqRt0j61CnB}XgQ|VI^H+k
zvaxRylm5p_i5~T4i0qi&+s46b!!?dg&va?Oux`~I!)v+J+#gR=$S>M=kU6)k5;8f|5XY;tVI;=E=uL=zC?hoKr#~g4p#NI;n%ByHYB|oY?J!cP#gVv
zRca%mSLHT_^y}-%NMo(j?_H
vfRrr2&^aESV&v+C3LS*&sge4D&cW94oH!pg@Iu549gf}uEyj>RE))9=q<|bh
literal 0
HcmV?d00001
diff --git a/src/main/java/financialtransactions/Inflow.class b/src/main/java/financialtransactions/Inflow.class
new file mode 100644
index 0000000000000000000000000000000000000000..ae37fb1168234cc8c74511d2f6cef944687a224f
GIT binary patch
literal 718
zcmaJ<*-8U36g_Ecr=5;k>#kL(3v>bd0aHY&2tr+;;(I#A8W}T?NfkfK2Niq}pZzHD
zMq67%C2(_3a!&4+xA*540J~UqkwDTx%EK7a45bUHxC$f>jpi!mfsv7l>!(A&kZwpN
z%{Ieaxpl>Fcs=B*TW=dJRoCCEoMq|BjE5{-hD^YX=tlaEp)f)|?p%q$_zpaV&EG>F
zsEaVV-DvjpE+#PPAn#!c1%~2(B8FTn%s|OdEw}!of5-4EXAG%kbS@YsTT+Rm-gQUl
zQ{D;bWOlULegRgHKNRLNIzQo>Ukf92%#dx%uHvSrN!I!!_DD+`e^7q3z~A;6+;-H{
zf!LQerQ8=|%T9sNk%-Nquqjgx-hom=H$xuBf?#IQ4wR^q2^v0-1hZ2oJ56XEDO!M2
zt(Bj^?#X4CA#1+~Xq;*CQnvkl!5W?0n{>7I0Ou#)eyH*M9`R?1WdoG@{A{)Mirgc{
ohZ36u= {
+ protected enum Category {
+ INCOME, INVESTMENT, GIFT, LOAN, REFUND, OTHER
+ }
+ public Inflow(String name, double amount) {
+ super(name, amount);
+ }
+ protected void setCategory(Category category) {
+ super.category = category;
+ }
+}
diff --git a/src/main/java/financialtransactions/Outflow$Category.class b/src/main/java/financialtransactions/Outflow$Category.class
new file mode 100644
index 0000000000000000000000000000000000000000..19a926ead116e7101b074eabad92da82c522d7d4
GIT binary patch
literal 1345
zcma)5ZBNrs6n^gB+SMX+2+E6sfVd51BH|01xG}0MnH!;lWbsoOWtNmSb{)oV{v;iV
z5RHb<{wU+QHzmwq%$BTApVRZ4w|nld-`{=$C}Legh+%Huatxr-Rw!U2|*2}dj_q(oQSoqcI8`>7P+)!~7qYTpQPO-AB
z=?v+&{nn>o91{{oRoudDO5U_x$D|~wbmhP}GP1Vew6e9`1GDMp6infcglQEsn5BX*
z95knMNcoQpyJOb&8J1H$>XL1=+qoWt?t7Ng%JpX80Yv;c759*0h~+KE@>dx~dP4=u
za(YKbRH4@AWW;5tG6rQNWejuMqKZdY;^PqYv>E18{SSmvpUWa8caLTl_#IfmcyD0(=R-l5&dH|<~qD?PL0
zgUa`tYBk58=x)brny)NgxEieX0zW#+Q8nBChTHZf6d7*)ccn>Ob{x|ar)g5j^7-{B
zEYi@Y=vqmIQGQ7PLRxr%wC4h8wFS~b3#1hW5@URENf{;o$5^5`%fzM$`A_L$;fIOrNC8{KN_F
zexcXD^Ke}}M5Pka|2aVjD+z_K7`gIt*ASs6kV(XTfHlHhg!M+G3rTN8yEOkstcwA?
zA$5_^8*z`sMOuF^0M#|R5D9}z?np0dj9hf6P$PVvRhoVzXe^HxWD8*xF9jB;IXVX_jG=&1Vd4+;o*+vA
literal 0
HcmV?d00001
diff --git a/src/main/java/financialtransactions/Outflow.class b/src/main/java/financialtransactions/Outflow.class
new file mode 100644
index 0000000000000000000000000000000000000000..48f8949226316427987cd7d2cb5b8059896e6b49
GIT binary patch
literal 723
zcma)4ZA%+L5Pl|!x!iftXzOcLh>FAn%n!IAmPnzHs1Wh{=3L{-xd(e2OMjLhw9pTw
zpZ!tdteiDSEoEVLX7-t9UUnWHfBpjS85;o#D0(P`m_nIQzffA}Sc$|Mp)(O%mFld0
z`f3o$9i^4sCoDF4SK>yr6QM`#fi+5xqQl)Y9~Jl>f)LXP3G08SJRaMNB>hIH#KOu^
zYQ7WZC-{zsS2DJdhZ(}oKPk4mIYGdQYa!+^Pngc6een}ojo$xJM7w8%Qa3%9gxQ|b
z@@RZLl;%_n6ZR}jHk=pe0&0C}FVpiAVZ^nx(qsgGphjBQvEi`(JIN=e+Ia_(Pw7vK
z(SAe-2I<(u@{4jcg*jx;eFgV@Bs1HWu4t|z{HnDy-9%)WWV7-z5!8891>OLl2y$P~
z@&j92DDeTjW~=c7bjvE?BTKg@fX~2y0X*V7V3YmsrQB@Y!F!8$TUD(cGJb(kE(@(icilFLKSPQ1sqc4R@M*Jo&Y?4tvCPx
literal 0
HcmV?d00001
diff --git a/src/main/java/financialtransactions/Outflow.java b/src/main/java/financialtransactions/Outflow.java
new file mode 100644
index 0000000000..b5de105514
--- /dev/null
+++ b/src/main/java/financialtransactions/Outflow.java
@@ -0,0 +1,14 @@
+package financialtransactions;
+import financialtransactions.Transaction;
+
+public class Outflow extends Transaction {
+ protected enum Category {
+ RENT, DEBT, SHOPPING, TREAT, EDUCATION, OTHER
+ }
+ public Outflow(String name, double amount) {
+ super(name, amount);
+ }
+ protected void setCategory(Category category) {
+ this.category = category;
+ }
+}
diff --git a/src/main/java/financialtransactions/Transaction.class b/src/main/java/financialtransactions/Transaction.class
new file mode 100644
index 0000000000000000000000000000000000000000..11c75863295d9950a79e07eef9abdff3695e0ced
GIT binary patch
literal 780
zcmZWnO;6iE6r6RO7$+tPX@GvwHifoMDv<*>KuCzFCqxgixNnSWElSps<5cReYAY2X
zap(`|kE$3umN7(@ci+y=n>YJ*|NX!F3*Z!P9R?~EOb1oe1lrf~yBtoX4u@YS*MXl1
z)Q*)_$%#P4?O)nhgKeSipaDmq_f2W3eI=(!EcIOaiHh`m=she1Of6@DK%zD$BJihn#7Sb966_!ajB?6C^9OcpWYisx}-
z%U!KE>R&SBEV?4Ab*^-9v6xMQ*prhf5i1Omi_B`*?XM=Y2nnaTOZH+U&>(VF7<`;o
zSggAJ%u!=rCU2Jg<=oU>%_TVv++**stU?0yakPm2;EPI+(JnQAKW(|$V?Pbv
zw#kpTmPPD&HgD!@HXCdjF$3Ft3WEQ0jxUHDpu$X`HMoTse7=D-aBr~wn~=auj-71V
z=2(Z#5>1Mlc!k%wzz%0YUUl#X)~_P1mVr%Dckrg58U=Oz=M(A%sc-R)7E@bg)s3gB
b-TW*))5Lr1QgeB>Jti-s5BNwC1E1~zou8Cz
literal 0
HcmV?d00001
diff --git a/src/main/java/financialtransactions/Transaction.java b/src/main/java/financialtransactions/Transaction.java
new file mode 100644
index 0000000000..4d6d187968
--- /dev/null
+++ b/src/main/java/financialtransactions/Transaction.java
@@ -0,0 +1,23 @@
+package financialtransactions;
+
+public abstract class Transaction {
+ protected String name;
+ protected double amount;
+ protected String date;
+ protected T category;
+
+ public Transaction(String name, double amount) {
+ this.name = name;
+ this.amount = amount;
+ }
+ protected String getName() {
+ return name;
+ }
+ protected double getAmount() {
+ return amount;
+ }
+ protected T getCategory() {
+ return category;
+ }
+ protected abstract void setCategory(T category);
+}
\ No newline at end of file
From 02a372503eb9e002065a186f1216808238e4f4b3 Mon Sep 17 00:00:00 2001
From: dylansiew <88567790+dylansiew@users.noreply.github.com>
Date: Fri, 8 Mar 2024 13:50:13 +0800
Subject: [PATCH 003/208] feature: outflow/inflow managers
---
src/main/java/Main.java | 43 +++++++++-
.../java/financialtransactions/Inflow.java | 9 +-
.../java/financialtransactions/Outflow.java | 11 +--
.../financialtransactions/Transaction.java | 27 +++++-
.../TransactionList.java | 45 ++++++++++
src/main/java/seedu/duke/Duke.java | 21 -----
src/main/java/template/BaseDate.java | 82 +++++++++++++++++++
src/main/java/user/Authentication.java | 27 ++++++
src/main/java/user/BaseUser.java | 20 +++++
9 files changed, 250 insertions(+), 35 deletions(-)
create mode 100644 src/main/java/financialtransactions/TransactionList.java
delete mode 100644 src/main/java/seedu/duke/Duke.java
create mode 100644 src/main/java/template/BaseDate.java
create mode 100644 src/main/java/user/Authentication.java
create mode 100644 src/main/java/user/BaseUser.java
diff --git a/src/main/java/Main.java b/src/main/java/Main.java
index 868f45cfbf..878b0a56c4 100644
--- a/src/main/java/Main.java
+++ b/src/main/java/Main.java
@@ -1,5 +1,46 @@
+import java.util.Scanner;
+
+import financialtransactions.*;
+import user.Authentication;
+import user.BaseUser;
+
public class Main {
public static void main(String[] args) {
- System.out.println("hello wordl");
+ BaseUser user = new BaseUser("Bob");
+ Scanner sc = new Scanner(System.in);
+ System.out.println("Enter password: ");
+ String password = sc.nextLine();
+ Authentication auth = user.getAuthentication();
+ if (auth.checkPassword("Bob", password)) {
+ System.out.println("Password is correct");
+ } else {
+ System.out.println("Password is incorrect");
+ }
+
+ TransactionList inflow = new TransactionList<>();
+ TransactionList outflow = new TransactionList<>();
+ Inflow income = new Inflow("Salary payment", 400.00, null);
+ income.setCategory(Inflow.Category.INCOME);
+ inflow.addTransaction(income);
+
+ Inflow investment = new Inflow("Investment", 500.00, null);
+ investment.setCategory(Inflow.Category.INVESTMENT);
+ inflow.addTransaction(investment);
+
+ Inflow loan = new Inflow("Loan payment", 400.00, "23/05/2022 1900");
+ loan.setCategory(Inflow.Category.LOAN);
+ inflow.addTransaction(loan);
+
+ Outflow rent = new Outflow("Rent", 50000, null);
+ rent.setCategory(Outflow.Category.RENT);
+ outflow.addTransaction(rent);
+
+ Outflow shopping = new Outflow("Shopping", 200, "23/05/2022 2000");
+ shopping.setCategory(Outflow.Category.SHOPPING);
+ outflow.addTransaction(shopping);
+
+ System.out.println(inflow.toString());
+ System.out.println(outflow.toString());
+ sc.close();
}
}
diff --git a/src/main/java/financialtransactions/Inflow.java b/src/main/java/financialtransactions/Inflow.java
index 885d09a758..28480e8527 100644
--- a/src/main/java/financialtransactions/Inflow.java
+++ b/src/main/java/financialtransactions/Inflow.java
@@ -1,14 +1,13 @@
package financialtransactions;
-import financialtransactions.Transaction;
public class Inflow extends Transaction {
- protected enum Category {
+ public enum Category {
INCOME, INVESTMENT, GIFT, LOAN, REFUND, OTHER
}
- public Inflow(String name, double amount) {
- super(name, amount);
+ public Inflow(String name, double amount, String date) {
+ super(name, amount, date);
}
- protected void setCategory(Category category) {
+ public void setCategory(Category category) {
super.category = category;
}
}
diff --git a/src/main/java/financialtransactions/Outflow.java b/src/main/java/financialtransactions/Outflow.java
index b5de105514..6c428c5731 100644
--- a/src/main/java/financialtransactions/Outflow.java
+++ b/src/main/java/financialtransactions/Outflow.java
@@ -1,14 +1,15 @@
package financialtransactions;
-import financialtransactions.Transaction;
public class Outflow extends Transaction {
- protected enum Category {
+ public enum Category {
RENT, DEBT, SHOPPING, TREAT, EDUCATION, OTHER
}
- public Outflow(String name, double amount) {
- super(name, amount);
+
+ public Outflow(String name, double amount, String date) {
+ super(name, -1.00 * amount, date);
}
- protected void setCategory(Category category) {
+
+ public void setCategory(Category category) {
this.category = category;
}
}
diff --git a/src/main/java/financialtransactions/Transaction.java b/src/main/java/financialtransactions/Transaction.java
index 4d6d187968..9c7cd34aac 100644
--- a/src/main/java/financialtransactions/Transaction.java
+++ b/src/main/java/financialtransactions/Transaction.java
@@ -1,23 +1,44 @@
package financialtransactions;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+
+import template.BaseDate;
+
public abstract class Transaction {
protected String name;
protected double amount;
- protected String date;
+ protected BaseDate date;
protected T category;
- public Transaction(String name, double amount) {
+ public Transaction(String name, double amount, String date) {
this.name = name;
this.amount = amount;
+ if(date == null){
+ this.date = new BaseDate(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")));
+ }
+ else{
+ this.date = new BaseDate(date);
+ }
}
+
protected String getName() {
return name;
}
- protected double getAmount() {
+
+ public double getAmount() {
return amount;
}
+
protected T getCategory() {
return category;
}
+
protected abstract void setCategory(T category);
+
+ @Override
+ public String toString() {
+ String baseString = String.format("Name: %s, Amount: %.2f, Date: %s", name, amount, date.toString());
+ return baseString;
+ }
}
\ No newline at end of file
diff --git a/src/main/java/financialtransactions/TransactionList.java b/src/main/java/financialtransactions/TransactionList.java
new file mode 100644
index 0000000000..9b471f5752
--- /dev/null
+++ b/src/main/java/financialtransactions/TransactionList.java
@@ -0,0 +1,45 @@
+package financialtransactions;
+
+import java.util.ArrayList;
+
+public class TransactionList> {
+ private ArrayList transactionList;
+
+ public TransactionList(){
+ this.transactionList = new ArrayList<>();
+ }
+
+ public Boolean addTransaction(T newTransaction){
+ if(newTransaction != null){
+ transactionList.add(newTransaction);
+ return true;
+ }
+ return false;
+ }
+
+ public Boolean removeTransacitonIndex(int index){
+ if(index >= transactionList.size() || index < 0){
+ System.out.println("Invalid Index");
+ return false;
+ }
+ transactionList.remove(index);
+ return true;
+ }
+ public double getBalance(){
+ double balance = 0.00;
+ for(Transaction> transaction : transactionList){
+ balance += transaction.getAmount();
+ }
+ return balance;
+ }
+ @Override
+ public String toString(){
+ String baseString = "Transactions: \n";
+ Integer index = 1;
+ for(T transaction : transactionList){
+ baseString += String.format("%d)\t%s\n", index, transaction.toString());
+ index += 1;
+ }
+ return baseString;
+ }
+}
diff --git a/src/main/java/seedu/duke/Duke.java b/src/main/java/seedu/duke/Duke.java
deleted file mode 100644
index 5c74e68d59..0000000000
--- a/src/main/java/seedu/duke/Duke.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package seedu.duke;
-
-import java.util.Scanner;
-
-public class Duke {
- /**
- * Main entry-point for the java.duke.Duke application.
- */
- public static void main(String[] args) {
- String logo = " ____ _ \n"
- + "| _ \\ _ _| | _____ \n"
- + "| | | | | | | |/ / _ \\\n"
- + "| |_| | |_| | < __/\n"
- + "|____/ \\__,_|_|\\_\\___|\n";
- System.out.println("Hello from\n" + logo);
- System.out.println("What is your name?");
-
- Scanner in = new Scanner(System.in);
- System.out.println("Hello " + in.nextLine());
- }
-}
diff --git a/src/main/java/template/BaseDate.java b/src/main/java/template/BaseDate.java
new file mode 100644
index 0000000000..1a3a04a38b
--- /dev/null
+++ b/src/main/java/template/BaseDate.java
@@ -0,0 +1,82 @@
+package template;
+
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.time.format.DateTimeParseException;
+import java.util.List;
+import java.util.ArrayList;
+
+public class BaseDate {
+ private static final List dateFormats = List.of(
+ "yyyy-MM-dd",
+ "dd-MM-yyyy",
+ "dd/MM/yyyy",
+ "yyyy-MM-dd",
+ "yyyy/MM/dd",
+ "dd:MM:yyyy",
+ "ddMMyyyy",
+ "ddMMyy",
+ "MMM dd yyyy");
+
+ private static final List timeFormats = List.of(
+ "HH:mm",
+ "HHmm",
+ "hh:mma");
+
+ private static final ArrayList dateTimeFormats = dateTimeVary();
+ public static DateTimeFormatter formatter = null;
+ LocalDateTime dateTime = null;
+ private final String DEAULT_TIME = " 0000";
+
+ public BaseDate(String args){
+ args = args.strip();
+ if (!args.contains(" ")) {
+ args = args + DEAULT_TIME;
+ }
+ for (String format : dateTimeFormats) {
+ try {
+ formatter = DateTimeFormatter.ofPattern(format);
+ dateTime = LocalDateTime.parse(args, formatter);
+ } catch (DateTimeParseException e) {
+ continue;
+ }
+
+ }
+ if (dateTime == null) {
+ System.out.println(String.format(
+ "Please input date in one of the correct formats: %s\n\n(Optional) Please input time in one of the correct formats: %s\n",
+ dateFormats, timeFormats));
+ }
+ }
+
+ private static ArrayList dateTimeVary() {
+ ArrayList varyList = new ArrayList();
+ for (String dateFormat : dateFormats) {
+ for (String timeFormat : timeFormats) {
+ varyList.add(String.format("%s %s", dateFormat, timeFormat));
+ varyList.add(String.format("%s %s", timeFormat, dateFormat));
+ }
+ }
+ return varyList;
+ }
+
+ @Override
+ public String toString() {
+ formatter = DateTimeFormatter.ofPattern("MMM dd yyyy hh:mma");
+ return String.format("%s", dateTime.format(formatter));
+ }
+
+ public boolean equals(BaseDate otherDate) {
+ if (otherDate != null) {
+ return this.dateTime.toLocalDate().equals(otherDate.dateTime.toLocalDate());
+ }
+ return false;
+ }
+
+ public boolean isBefore(BaseDate otherDate) {
+ if (otherDate != null) {
+ return this.dateTime.isBefore(otherDate.dateTime);
+ }
+ return false;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/user/Authentication.java b/src/main/java/user/Authentication.java
new file mode 100644
index 0000000000..d8ed570b7e
--- /dev/null
+++ b/src/main/java/user/Authentication.java
@@ -0,0 +1,27 @@
+package user;
+
+public class Authentication {
+ private String password;
+ String username;
+
+ public Authentication(String password, String username) {
+ this.password = password;
+ this.username = username;
+ }
+
+ public String getUsername() {
+ return this.username;
+ }
+
+ public Boolean checkPassword(String username, String password) {
+ return this.password.equals(password) && this.username.equals(username);
+ }
+
+ public Boolean changePassword(String username, String oldPassword, String newPassword) {
+ if (!checkPassword(username, oldPassword)) {
+ return false;
+ }
+ this.password = newPassword;
+ return true;
+ }
+}
diff --git a/src/main/java/user/BaseUser.java b/src/main/java/user/BaseUser.java
new file mode 100644
index 0000000000..38c88f3340
--- /dev/null
+++ b/src/main/java/user/BaseUser.java
@@ -0,0 +1,20 @@
+package user;
+
+public class BaseUser {
+ String name;
+ Authentication auth;
+
+ public BaseUser(String name) {
+ this.name = name;
+ String username = name.replace(" ", "_");
+ this.auth = new Authentication("password", username);
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public Authentication getAuthentication(){
+ return this.auth;
+ }
+}
From 28fd31f884e53de26023fc9786720d6c5760285b Mon Sep 17 00:00:00 2001
From: dylansiew <88567790+dylansiew@users.noreply.github.com>
Date: Fri, 8 Mar 2024 14:00:27 +0800
Subject: [PATCH 004/208] abstraction of transactionlist
---
.gitignore | 2 +
src/main/java/Main.class | Bin 413 -> 0 bytes
src/main/java/Main.java | 16 +++----
.../Inflow$Category.class | Bin 1337 -> 0 bytes
.../java/financialtransactions/Inflow.class | Bin 718 -> 0 bytes
.../Outflow$Category.class | Bin 1345 -> 0 bytes
.../java/financialtransactions/Outflow.class | Bin 723 -> 0 bytes
.../financialtransactions/Transaction.class | Bin 780 -> 0 bytes
.../TransactionManager.java | 42 ++++++++++++++++++
9 files changed, 51 insertions(+), 9 deletions(-)
delete mode 100644 src/main/java/Main.class
delete mode 100644 src/main/java/financialtransactions/Inflow$Category.class
delete mode 100644 src/main/java/financialtransactions/Inflow.class
delete mode 100644 src/main/java/financialtransactions/Outflow$Category.class
delete mode 100644 src/main/java/financialtransactions/Outflow.class
delete mode 100644 src/main/java/financialtransactions/Transaction.class
create mode 100644 src/main/java/financialtransactions/TransactionManager.java
diff --git a/.gitignore b/.gitignore
index 2873e189e1..8fb41d88e1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -15,3 +15,5 @@ bin/
/text-ui-test/ACTUAL.TXT
text-ui-test/EXPECTED-UNIX.TXT
+
+/*.class
\ No newline at end of file
diff --git a/src/main/java/Main.class b/src/main/java/Main.class
deleted file mode 100644
index 18fbafd8af9f9e377492d1144c0b10294c47207c..0000000000000000000000000000000000000000
GIT binary patch
literal 0
HcmV?d00001
literal 413
zcmZvY%Syvg5QhIr(xyqHt*x!sf-Z#Ag?WIAAcCuUfk-#5lJ-zfIY}fYijSoW1s6Vm
z4<*it3lVx2b2;`aiWg#95bDP=mBk6c
z^oJ7%4LCMj4^4Rg@bLMe5D8OR$xFR)B_y-pI+tk?7P*L$Q3I=l=ABR~+k49LnR3y_
znvIT!F4hU%B})YRUQ4KyRsCPt>OR(#>3lSt*yt0ii%2qIon inflow = new TransactionList<>();
- TransactionList outflow = new TransactionList<>();
+ TransactionManager manager = new TransactionManager();
Inflow income = new Inflow("Salary payment", 400.00, null);
income.setCategory(Inflow.Category.INCOME);
- inflow.addTransaction(income);
+ manager.addTransaction(income);
Inflow investment = new Inflow("Investment", 500.00, null);
investment.setCategory(Inflow.Category.INVESTMENT);
- inflow.addTransaction(investment);
+ manager.addTransaction(investment);
Inflow loan = new Inflow("Loan payment", 400.00, "23/05/2022 1900");
loan.setCategory(Inflow.Category.LOAN);
- inflow.addTransaction(loan);
+ manager.addTransaction(loan);
Outflow rent = new Outflow("Rent", 50000, null);
rent.setCategory(Outflow.Category.RENT);
- outflow.addTransaction(rent);
+ manager.addTransaction(rent);
Outflow shopping = new Outflow("Shopping", 200, "23/05/2022 2000");
shopping.setCategory(Outflow.Category.SHOPPING);
- outflow.addTransaction(shopping);
+ manager.addTransaction(shopping);
- System.out.println(inflow.toString());
- System.out.println(outflow.toString());
+ System.out.println(manager.toString());
sc.close();
}
}
diff --git a/src/main/java/financialtransactions/Inflow$Category.class b/src/main/java/financialtransactions/Inflow$Category.class
deleted file mode 100644
index 77b76c1672fb9215f387ada9bd1f50d6fc7963dc..0000000000000000000000000000000000000000
GIT binary patch
literal 0
HcmV?d00001
literal 1337
zcma)5ZBNrs7(I7y?Mi_;1O=ubuiH>2A}S1Va|~HBIzz{j#ZP6FSyH;#br`?-lXN6P
zG#Wnpqm0kJjxd8UTe3bqr_b9xJ^lIX>kj}~Y)bGk%pO{f;nXa{_FThh8a2;qIL%bS
zIkX$^XL5#T)*J4JFc<-eGeJWH=
z2VNDn1TmmuP!PpZR^u5rR7Azp-Tc;`w#liRDuy`~ES0zOyPUbD;x!7$R@s#94=
zRAdAdI{BQ8unbkkpp2-DVa_e7c!XuHhS;ackc=mK)q^HqRt0j61CnB}XgQ|VI^H+k
zvaxRylm5p_i5~T4i0qi&+s46b!!?dg&va?Oux`~I!)v+J+#gR=$S>M=kU6)k5;8f|5XY;tVI;=E=uL=zC?hoKr#~g4p#NI;n%ByHYB|oY?J!cP#gVv
zRca%mSLHT_^y}-%NMo(j?_H
vfRrr2&^aESV&v+C3LS*&sge4D&cW94oH!pg@Iu549gf}uEyj>RE))9=q<|bh
diff --git a/src/main/java/financialtransactions/Inflow.class b/src/main/java/financialtransactions/Inflow.class
deleted file mode 100644
index ae37fb1168234cc8c74511d2f6cef944687a224f..0000000000000000000000000000000000000000
GIT binary patch
literal 0
HcmV?d00001
literal 718
zcmaJ<*-8U36g_Ecr=5;k>#kL(3v>bd0aHY&2tr+;;(I#A8W}T?NfkfK2Niq}pZzHD
zMq67%C2(_3a!&4+xA*540J~UqkwDTx%EK7a45bUHxC$f>jpi!mfsv7l>!(A&kZwpN
z%{Ieaxpl>Fcs=B*TW=dJRoCCEoMq|BjE5{-hD^YX=tlaEp)f)|?p%q$_zpaV&EG>F
zsEaVV-DvjpE+#PPAn#!c1%~2(B8FTn%s|OdEw}!of5-4EXAG%kbS@YsTT+Rm-gQUl
zQ{D;bWOlULegRgHKNRLNIzQo>Ukf92%#dx%uHvSrN!I!!_DD+`e^7q3z~A;6+;-H{
zf!LQerQ8=|%T9sNk%-Nquqjgx-hom=H$xuBf?#IQ4wR^q2^v0-1hZ2oJ56XEDO!M2
zt(Bj^?#X4CA#1+~Xq;*CQnvkl!5W?0n{>7I0Ou#)eyH*M9`R?1WdoG@{A{)Mirgc{
ohZ36u=r-Rw!U2|*2}dj_q(oQSoqcI8`>7P+)!~7qYTpQPO-AB
z=?v+&{nn>o91{{oRoudDO5U_x$D|~wbmhP}GP1Vew6e9`1GDMp6infcglQEsn5BX*
z95knMNcoQpyJOb&8J1H$>XL1=+qoWt?t7Ng%JpX80Yv;c759*0h~+KE@>dx~dP4=u
za(YKbRH4@AWW;5tG6rQNWejuMqKZdY;^PqYv>E18{SSmvpUWa8caLTl_#IfmcyD0(=R-l5&dH|<~qD?PL0
zgUa`tYBk58=x)brny)NgxEieX0zW#+Q8nBChTHZf6d7*)ccn>Ob{x|ar)g5j^7-{B
zEYi@Y=vqmIQGQ7PLRxr%wC4h8wFS~b3#1hW5@URENf{;o$5^5`%fzM$`A_L$;fIOrNC8{KN_F
zexcXD^Ke}}M5Pka|2aVjD+z_K7`gIt*ASs6kV(XTfHlHhg!M+G3rTN8yEOkstcwA?
zA$5_^8*z`sMOuF^0M#|R5D9}z?np0dj9hf6P$PVvRhoVzXe^HxWD8*xF9jB;IXVX_jG=&1Vd4+;o*+vA
diff --git a/src/main/java/financialtransactions/Outflow.class b/src/main/java/financialtransactions/Outflow.class
deleted file mode 100644
index 48f8949226316427987cd7d2cb5b8059896e6b49..0000000000000000000000000000000000000000
GIT binary patch
literal 0
HcmV?d00001
literal 723
zcma)4ZA%+L5Pl|!x!iftXzOcLh>FAn%n!IAmPnzHs1Wh{=3L{-xd(e2OMjLhw9pTw
zpZ!tdteiDSEoEVLX7-t9UUnWHfBpjS85;o#D0(P`m_nIQzffA}Sc$|Mp)(O%mFld0
z`f3o$9i^4sCoDF4SK>yr6QM`#fi+5xqQl)Y9~Jl>f)LXP3G08SJRaMNB>hIH#KOu^
zYQ7WZC-{zsS2DJdhZ(}oKPk4mIYGdQYa!+^Pngc6een}ojo$xJM7w8%Qa3%9gxQ|b
z@@RZLl;%_n6ZR}jHk=pe0&0C}FVpiAVZ^nx(qsgGphjBQvEi`(JIN=e+Ia_(Pw7vK
z(SAe-2I<(u@{4jcg*jx;eFgV@Bs1HWu4t|z{HnDy-9%)WWV7-z5!8891>OLl2y$P~
z@&j92DDeTjW~=c7bjvE?BTKg@fX~2y0X*V7V3YmsrQB@Y!F!8$TUD(cGJb(kE(@(icilFLKSPQ1sqc4R@M*Jo&Y?4tvCPx
diff --git a/src/main/java/financialtransactions/Transaction.class b/src/main/java/financialtransactions/Transaction.class
deleted file mode 100644
index 11c75863295d9950a79e07eef9abdff3695e0ced..0000000000000000000000000000000000000000
GIT binary patch
literal 0
HcmV?d00001
literal 780
zcmZWnO;6iE6r6RO7$+tPX@GvwHifoMDv<*>KuCzFCqxgixNnSWElSps<5cReYAY2X
zap(`|kE$3umN7(@ci+y=n>YJ*|NX!F3*Z!P9R?~EOb1oe1lrf~yBtoX4u@YS*MXl1
z)Q*)_$%#P4?O)nhgKeSipaDmq_f2W3eI=(!EcIOaiHh`m=she1Of6@DK%zD$BJihn#7Sb966_!ajB?6C^9OcpWYisx}-
z%U!KE>R&SBEV?4Ab*^-9v6xMQ*prhf5i1Omi_B`*?XM=Y2nnaTOZH+U&>(VF7<`;o
zSggAJ%u!=rCU2Jg<=oU>%_TVv++**stU?0yakPm2;EPI+(JnQAKW(|$V?Pbv
zw#kpTmPPD&HgD!@HXCdjF$3Ft3WEQ0jxUHDpu$X`HMoTse7=D-aBr~wn~=auj-71V
z=2(Z#5>1Mlc!k%wzz%0YUUl#X)~_P1mVr%Dckrg58U=Oz=M(A%sc-R)7E@bg)s3gB
b-TW*))5Lr1QgeB>Jti-s5BNwC1E1~zou8Cz
diff --git a/src/main/java/financialtransactions/TransactionManager.java b/src/main/java/financialtransactions/TransactionManager.java
new file mode 100644
index 0000000000..12d09c4e7d
--- /dev/null
+++ b/src/main/java/financialtransactions/TransactionManager.java
@@ -0,0 +1,42 @@
+package financialtransactions;
+
+public class TransactionManager {
+ private TransactionList inflows;
+ private TransactionList outflows;
+
+ public TransactionManager() {
+ this.inflows = new TransactionList<>();
+ this.outflows = new TransactionList<>();
+ }
+
+ public boolean addTransaction(Transaction> transaction) {
+ if (transaction instanceof Inflow) {
+ Inflow inflow = (Inflow) transaction;
+ return inflows.addTransaction(inflow);
+ } else if (transaction instanceof Outflow) {
+ Outflow outflow = (Outflow) transaction;
+ return outflows.addTransaction(outflow);
+ }
+ System.out.println("Invalid transaction type.");
+ return false;
+ }
+
+ public boolean removeTransaction(int index, boolean isInflow) {
+ if (isInflow) {
+ return inflows.removeTransacitonIndex(index);
+ } else {
+ return outflows.removeTransacitonIndex(index);
+ }
+ }
+
+ public double getTotalBalance() {
+ double inflowBalance = inflows.getBalance();
+ double outflowBalance = outflows.getBalance();
+ return inflowBalance + outflowBalance;
+ }
+
+ @Override
+ public String toString() {
+ return "Inflows:\n" + inflows.toString() + "\nOutflows:\n" + outflows.toString();
+ }
+}
From 67798049e472c229e7eaa6a0e219f391b304e37b Mon Sep 17 00:00:00 2001
From: dylansiew <88567790+dylansiew@users.noreply.github.com>
Date: Fri, 8 Mar 2024 14:52:36 +0800
Subject: [PATCH 005/208] change md
---
docs/AboutUs.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/AboutUs.md b/docs/AboutUs.md
index 0f072953ea..5e37701f3b 100644
--- a/docs/AboutUs.md
+++ b/docs/AboutUs.md
@@ -2,7 +2,7 @@
Display | Name | Github Profile | Portfolio
--------|:----:|:--------------:|:---------:
-![](https://via.placeholder.com/100.png?text=Photo) | John Doe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md)
+![](https://via.placeholder.com/100.png?text=Photo) | Dylan | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md)
![](https://via.placeholder.com/100.png?text=Photo) | Don Joe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md)
![](https://via.placeholder.com/100.png?text=Photo) | Ron John | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md)
![](https://via.placeholder.com/100.png?text=Photo) | John Roe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md)
From cd1ea770b1ad026bb9cbe9133b24b1d63e457163 Mon Sep 17 00:00:00 2001
From: Kishen271828
Date: Wed, 13 Mar 2024 19:10:29 +0800
Subject: [PATCH 006/208] Create Parser Class
---
src/main/java/parser/Parser.java | 43 ++++++++++++++++++++++++++++++++
1 file changed, 43 insertions(+)
create mode 100644 src/main/java/parser/Parser.java
diff --git a/src/main/java/parser/Parser.java b/src/main/java/parser/Parser.java
new file mode 100644
index 0000000000..94a13b5460
--- /dev/null
+++ b/src/main/java/parser/Parser.java
@@ -0,0 +1,43 @@
+package parser;
+
+import financialtransactions.*;
+import java.util.ArrayList;
+
+public class Parser {
+ protected static boolean isContinue = true;
+
+ public static void parseCommand(String command, TransactionManager manager) {
+ String[] commandParts = command.split(" ");
+ String action = commandParts[0];
+
+ switch (action) {
+ case "login":
+ // Implement login functionality
+ break;
+ case "add-source":
+ // Implement add source of income functionality
+ break;
+ case "delete-source":
+ // Implement delete source of income functionality
+ break;
+ case "add-transaction":
+ // Implement add transaction functionality
+ break;
+ case "delete-transaction":
+ // Implement delete transaction functionality
+ break;
+ case "view-history":
+ break;
+ case "export-csv":
+ // Implement export to CSV functionality
+ break;
+ case "help":
+ // Implement help functionality
+ break;
+ default:
+ System.out.println("Invalid command");
+ break;
+ }
+ }
+}
+
From 74abae04614a43bc13f8686087da6c902eba5e50 Mon Sep 17 00:00:00 2001
From: Kishen271828
Date: Wed, 13 Mar 2024 19:58:00 +0800
Subject: [PATCH 007/208] Add view transaction history functionality
---
.../financialtransactions/TransactionList.java | 17 +++++++++++++++++
.../TransactionManager.java | 5 +++++
src/main/java/parser/Parser.java | 2 ++
3 files changed, 24 insertions(+)
diff --git a/src/main/java/financialtransactions/TransactionList.java b/src/main/java/financialtransactions/TransactionList.java
index 9b471f5752..83d4944798 100644
--- a/src/main/java/financialtransactions/TransactionList.java
+++ b/src/main/java/financialtransactions/TransactionList.java
@@ -9,6 +9,10 @@ public TransactionList(){
this.transactionList = new ArrayList<>();
}
+ public ArrayList getTransactionList() {
+ return this.transactionList;
+ }
+
public Boolean addTransaction(T newTransaction){
if(newTransaction != null){
transactionList.add(newTransaction);
@@ -42,4 +46,17 @@ public String toString(){
}
return baseString;
}
+
+ public String lastNTransactions(int n) {
+ String baseString = "Transactions: \n";
+ int listSize = transactionList.size();
+ int index = 1;
+ for (int i = listSize - 1; i >= listSize - n - 1; i--) {
+ T transaction = transactionList.get(i);
+ baseString += String.format("%d)\t%s\n", index, transaction.toString());
+ index++;
+ }
+ return baseString;
+ }
+
}
diff --git a/src/main/java/financialtransactions/TransactionManager.java b/src/main/java/financialtransactions/TransactionManager.java
index 12d09c4e7d..c53a0d880a 100644
--- a/src/main/java/financialtransactions/TransactionManager.java
+++ b/src/main/java/financialtransactions/TransactionManager.java
@@ -1,5 +1,6 @@
package financialtransactions;
+
public class TransactionManager {
private TransactionList inflows;
private TransactionList outflows;
@@ -39,4 +40,8 @@ public double getTotalBalance() {
public String toString() {
return "Inflows:\n" + inflows.toString() + "\nOutflows:\n" + outflows.toString();
}
+
+ public void displayTransactionHistory(int n) {
+ System.out.println("Inflows:\n" + inflows.lastNTransactions(n) + "\nOutflows:\n" + outflows.lastNTransactions(n));
+ }
}
diff --git a/src/main/java/parser/Parser.java b/src/main/java/parser/Parser.java
index 94a13b5460..b15ec958aa 100644
--- a/src/main/java/parser/Parser.java
+++ b/src/main/java/parser/Parser.java
@@ -27,6 +27,8 @@ public static void parseCommand(String command, TransactionManager manager) {
// Implement delete transaction functionality
break;
case "view-history":
+ int numTransactions = Integer.parseInt(command.split(" ")[1].trim());
+ manager.displayTransactionHistory(numTransactions);
break;
case "export-csv":
// Implement export to CSV functionality
From 36fa3fd47322849dd042166312ffb4cc111ea7a0 Mon Sep 17 00:00:00 2001
From: dylansiew <88567790+dylansiew@users.noreply.github.com>
Date: Wed, 13 Mar 2024 22:21:00 +0800
Subject: [PATCH 008/208] bug: fixed all gradle flagged issues
---
src/main/java/Main.java | 4 +++-
.../java/financialtransactions/Transaction.java | 5 ++---
.../financialtransactions/TransactionManager.java | 5 ++++-
src/main/java/parser/Parser.java | 3 +--
src/main/java/template/BaseDate.java | 15 +++++++--------
src/main/java/user/Authentication.java | 2 +-
6 files changed, 18 insertions(+), 16 deletions(-)
diff --git a/src/main/java/Main.java b/src/main/java/Main.java
index d254036e74..0285871101 100644
--- a/src/main/java/Main.java
+++ b/src/main/java/Main.java
@@ -1,6 +1,8 @@
import java.util.Scanner;
-import financialtransactions.*;
+import financialtransactions.Inflow;
+import financialtransactions.Outflow;
+import financialtransactions.TransactionManager;
import user.Authentication;
import user.BaseUser;
diff --git a/src/main/java/financialtransactions/Transaction.java b/src/main/java/financialtransactions/Transaction.java
index 9c7cd34aac..46afb222e2 100644
--- a/src/main/java/financialtransactions/Transaction.java
+++ b/src/main/java/financialtransactions/Transaction.java
@@ -16,8 +16,7 @@ public Transaction(String name, double amount, String date) {
this.amount = amount;
if(date == null){
this.date = new BaseDate(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")));
- }
- else{
+ } else{
this.date = new BaseDate(date);
}
}
@@ -41,4 +40,4 @@ public String toString() {
String baseString = String.format("Name: %s, Amount: %.2f, Date: %s", name, amount, date.toString());
return baseString;
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/financialtransactions/TransactionManager.java b/src/main/java/financialtransactions/TransactionManager.java
index c53a0d880a..6c070c08a3 100644
--- a/src/main/java/financialtransactions/TransactionManager.java
+++ b/src/main/java/financialtransactions/TransactionManager.java
@@ -42,6 +42,9 @@ public String toString() {
}
public void displayTransactionHistory(int n) {
- System.out.println("Inflows:\n" + inflows.lastNTransactions(n) + "\nOutflows:\n" + outflows.lastNTransactions(n));
+ String inflowTransactions = inflows.lastNTransactions(n);
+ String outflowTransactions = outflows.lastNTransactions(n);
+ System.out.println("Inflows:\n" + inflowTransactions + "\nOutflows:\n" + outflowTransactions);
}
+
}
diff --git a/src/main/java/parser/Parser.java b/src/main/java/parser/Parser.java
index b15ec958aa..a2217952c9 100644
--- a/src/main/java/parser/Parser.java
+++ b/src/main/java/parser/Parser.java
@@ -1,7 +1,6 @@
package parser;
-import financialtransactions.*;
-import java.util.ArrayList;
+import financialtransactions.TransactionManager;
public class Parser {
protected static boolean isContinue = true;
diff --git a/src/main/java/template/BaseDate.java b/src/main/java/template/BaseDate.java
index 1a3a04a38b..eeff41335d 100644
--- a/src/main/java/template/BaseDate.java
+++ b/src/main/java/template/BaseDate.java
@@ -7,6 +7,7 @@
import java.util.ArrayList;
public class BaseDate {
+ public static DateTimeFormatter formatter = null;
private static final List dateFormats = List.of(
"yyyy-MM-dd",
"dd-MM-yyyy",
@@ -24,14 +25,14 @@ public class BaseDate {
"hh:mma");
private static final ArrayList dateTimeFormats = dateTimeVary();
- public static DateTimeFormatter formatter = null;
+
LocalDateTime dateTime = null;
- private final String DEAULT_TIME = " 0000";
+ private final String defaultTime = " 0000";
- public BaseDate(String args){
+ public BaseDate(String args) {
args = args.strip();
if (!args.contains(" ")) {
- args = args + DEAULT_TIME;
+ args = args + defaultTime;
}
for (String format : dateTimeFormats) {
try {
@@ -43,9 +44,7 @@ public BaseDate(String args){
}
if (dateTime == null) {
- System.out.println(String.format(
- "Please input date in one of the correct formats: %s\n\n(Optional) Please input time in one of the correct formats: %s\n",
- dateFormats, timeFormats));
+ System.out.println("Incorrect Format");
}
}
@@ -79,4 +78,4 @@ public boolean isBefore(BaseDate otherDate) {
}
return false;
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/user/Authentication.java b/src/main/java/user/Authentication.java
index d8ed570b7e..73aff39e30 100644
--- a/src/main/java/user/Authentication.java
+++ b/src/main/java/user/Authentication.java
@@ -1,8 +1,8 @@
package user;
public class Authentication {
- private String password;
String username;
+ private String password;
public Authentication(String password, String username) {
this.password = password;
From 6cf07fe885fa84ab69c142b9086d99cbb7edb1d2 Mon Sep 17 00:00:00 2001
From: dylansiew <88567790+dylansiew@users.noreply.github.com>
Date: Wed, 13 Mar 2024 23:04:34 +0800
Subject: [PATCH 009/208] fix: gradle io redirection failure
---
build.gradle | 4 +-
compile.sh | 21 +++
file_paths.txt | 147 ++++++++++++++++++
src/main/java/{ => financeproject}/Main.java | 1 +
.../TransactionList.java | 4 +-
src/test/java/seedu/duke/DukeTest.java | 12 --
text-ui-test/EXPECTED.TXT | 20 ++-
text-ui-test/input.txt | 2 +-
8 files changed, 186 insertions(+), 25 deletions(-)
create mode 100755 compile.sh
create mode 100644 file_paths.txt
rename src/main/java/{ => financeproject}/Main.java (98%)
delete mode 100644 src/test/java/seedu/duke/DukeTest.java
diff --git a/build.gradle b/build.gradle
index ea82051fab..833bad8eb2 100644
--- a/build.gradle
+++ b/build.gradle
@@ -29,11 +29,11 @@ test {
}
application {
- mainClass.set("seedu.duke.Duke")
+ mainClass.set("financeproject.Main")
}
shadowJar {
- archiveBaseName.set("duke")
+ archiveBaseName.set("project")
archiveClassifier.set("")
}
diff --git a/compile.sh b/compile.sh
new file mode 100755
index 0000000000..63cebacae2
--- /dev/null
+++ b/compile.sh
@@ -0,0 +1,21 @@
+#!/bin/bash
+
+# Define the base directory variables
+SRC_DIR="src"
+BUILD_DIR="build"
+CLASSES_DIR="$BUILD_DIR/classes"
+LIBS_DIR="$BUILD_DIR/libs"
+JAR_NAME="project.jar"
+
+
+# Compile the Java files
+find "$SRC_DIR" -name "*.java" > sources.txt
+javac -d "$CLASSES_DIR" @sources.txt
+rm sources.txt
+
+# Package the .class files into a .jar file
+cd "$CLASSES_DIR"
+jar cvf "../libs/$JAR_NAME" *
+cd -
+
+echo "Compilation and packaging complete."
diff --git a/file_paths.txt b/file_paths.txt
new file mode 100644
index 0000000000..97c44f9f0e
--- /dev/null
+++ b/file_paths.txt
@@ -0,0 +1,147 @@
+./compile.sh
+./config/checkstyle/suppressions.xml
+./config/checkstyle/checkstyle.xml
+./docs/AboutUs.md
+./docs/UserGuide.md
+./docs/README.md
+./docs/team/johndoe.md
+./docs/DeveloperGuide.md
+./text-ui-test/runtest.bat
+./text-ui-test/EXPECTED-UNIX.TXT
+./text-ui-test/EXPECTED.TXT
+./text-ui-test/input.txt
+./text-ui-test/runtest.sh
+./text-ui-test/ACTUAL.TXT
+./README.md
+./gradle/wrapper/gradle-wrapper.jar
+./gradle/wrapper/gradle-wrapper.properties
+./file_paths.txt
+./gradlew
+./.gitignore
+./CONTRIBUTORS.md
+./.github/workflows/gradle.yml
+./build.gradle
+./.gradle/file-system.probe
+./.gradle/vcs-1/gc.properties
+./.gradle/7.6.2/executionHistory/executionHistory.lock
+./.gradle/7.6.2/executionHistory/executionHistory.bin
+./.gradle/7.6.2/gc.properties
+./.gradle/7.6.2/fileChanges/last-build.bin
+./.gradle/7.6.2/dependencies-accessors/gc.properties
+./.gradle/7.6.2/dependencies-accessors/dependencies-accessors.lock
+./.gradle/7.6.2/checksums/checksums.lock
+./.gradle/7.6.2/fileHashes/fileHashes.lock
+./.gradle/7.6.2/fileHashes/fileHashes.bin
+./.gradle/7.6.2/fileHashes/resourceHashesCache.bin
+./.gradle/buildOutputCleanup/cache.properties
+./.gradle/buildOutputCleanup/outputFiles.bin
+./.gradle/buildOutputCleanup/buildOutputCleanup.lock
+./build/classes/java/main/financialtransactions/Outflow.class
+./build/classes/java/main/financialtransactions/Inflow$Category.class
+./build/classes/java/main/financialtransactions/Outflow$Category.class
+./build/classes/java/main/financialtransactions/Inflow.class
+./build/classes/java/main/financialtransactions/TransactionManager.class
+./build/classes/java/main/financialtransactions/TransactionList.class
+./build/classes/java/main/financialtransactions/Transaction.class
+./build/classes/java/main/template/BaseDate.class
+./build/classes/java/main/user/Authentication.class
+./build/classes/java/main/user/BaseUser.class
+./build/classes/java/main/parser/Parser.class
+./build/classes/java/main/Main.class
+./build/libs/duke.jar
+./build/tmp/compileJava/previous-compilation-data.bin
+./build/tmp/shadowJar/MANIFEST.MF
+./.git/ORIG_HEAD
+./.git/config
+./.git/objects/61/1e6bb7d87d2cccc09b0b50d14139b41a791512
+./.git/objects/3b/0d120ecd000efe10980df7f669aa92a89cb6d1
+./.git/objects/3b/c6ecaf968345b1781f2c0ee5181c6f20753492
+./.git/objects/69/b73269c517a29a32c6bd89d1da23db57359782
+./.git/objects/58/0b21ab7b1b06454bf68220d25b6e827b8e4e50
+./.git/objects/93/21376bc46dd94f61072a09a4e4c15e1b3a3fc2
+./.git/objects/94/e47c854c2956015669f6479048070dfda6ded7
+./.git/objects/9c/653fd68c278c8ed9a2de5d31b5ef7922ce323d
+./.git/objects/02/858711010960685a51c3d502e2f613fe3ddd22
+./.git/objects/b5/7c77e1bcb2c8dd6012df079b36b41c60f475d6
+./.git/objects/bb/03976d24fb3cab970cb7ba69cc1175aefb1909
+./.git/objects/be/5d40a35736ec6f87f508efcda93e984590bc83
+./.git/objects/a2/217952c96c66e8675be0eda9d44776384b7d1d
+./.git/objects/ae/be20a1c00e6c2cb43d9a96f17b0a541e0ee0a3
+./.git/objects/f4/67d6c788a22ec10d6472f2ca0ea82c13f873c0
+./.git/objects/ee/ff41335d883f71be89bfb533287f9e2219254b
+./.git/objects/fc/3473e18dc459060a128c90870b6a50e7a8e288
+./.git/objects/f2/2d6cc02ff313a68c49a2d156c0af55f19f677e
+./.git/objects/f5/b1f11ac417dfb8bc861a5008ca615cf973e240
+./.git/objects/pack/pack-33a51df449e49363184d1bf26911c357f8f98bbb.pack
+./.git/objects/pack/pack-33a51df449e49363184d1bf26911c357f8f98bbb.idx
+./.git/objects/11/ec7ec31876b87bf9a0b385a02ee23c892e9089
+./.git/objects/7c/e087879386ccf1382f3c7f7350f88e1c0b69e2
+./.git/objects/16/0ade0a72af1206ef011178306a828531af1a9e
+./.git/objects/73/aff39e301522547599fc3133100eeb694f2d03
+./.git/objects/73/aac78b03559379c1f7a36f5c85e68a9f04e6bf
+./.git/objects/87/5f7ae5499ac9b3822ab035c12bd7a8f526f981
+./.git/objects/4c/d6663a05b86e59fa6bfe15cc55dbe2dc69c0f3
+./.git/objects/2a/80d4526441670c30fb13bef54d4ed5762adeaf
+./.git/objects/2f/bac1978e0977851e58e5f356e47d125a79f729
+./.git/objects/36/fa3fd47322849dd042166312ffb4cc111ea7a0
+./.git/objects/96/22e98bee857326e6bdd17121dab1232a63d99b
+./.git/objects/37/8b652464cb15c8af588a941e13e61960ea74f2
+./.git/objects/6c/070c08a384202511ca1907324ba05cde598c43
+./.git/objects/ba/2761a656cf9e6e5db75fc553fac528cad7e4a5
+./.git/objects/b9/d0bedbed673bbe42c22885cefe93f500271d35
+./.git/objects/ef/1fe424fa6fdf3d4d1f7b107b6beecf80f243f9
+./.git/objects/ef/66b5b45b63bd32daff9062fa89766374a31af8
+./.git/objects/e9/e0c259e0729b7151dd3e1f55b90e20ffc7ac47
+./.git/objects/e7/daae1ce0b64cb257ac1b2fe618f76a0ddc52a2
+./.git/objects/46/afb222e226e4dc0cdc594a15bd20ecf404f700
+./.git/objects/77/3e23a2ddcff842ce33aa3f6adfce4ec029e361
+./.git/objects/70/5a83bba6036ad80bf35eacf02c723b7a188228
+./.git/objects/70/770adf86b59d5dcdf91d6b822d6528fb310960
+./.git/objects/24/e9d88d5e4356278c4e8b7f86dceef09d840344
+./.git/objects/4f/e34084af9b4c5b1ebb95aa4d132c7d8e6588ec
+./.git/objects/76/73f7ce5bf02cfd7f323fe67dd91eb05c10a1ea
+./.git/objects/13/566b81b018ad684f3a35fee301741b2734c8f4
+./.git/HEAD
+./.git/info/exclude
+./.git/logs/HEAD
+./.git/logs/refs/heads/pr/47
+./.git/logs/refs/heads/master
+./.git/logs/refs/remotes/github-desktop-AY2324S2-CS2113-T15-3/HEAD
+./.git/logs/refs/remotes/github-desktop-AY2324S2-CS2113-T15-3/master
+./.git/logs/refs/remotes/origin/HEAD
+./.git/logs/refs/remotes/origin/master
+./.git/description
+./.git/hooks/commit-msg.sample
+./.git/hooks/pre-rebase.sample
+./.git/hooks/pre-commit.sample
+./.git/hooks/applypatch-msg.sample
+./.git/hooks/fsmonitor-watchman.sample
+./.git/hooks/pre-receive.sample
+./.git/hooks/prepare-commit-msg.sample
+./.git/hooks/post-update.sample
+./.git/hooks/pre-merge-commit.sample
+./.git/hooks/pre-applypatch.sample
+./.git/hooks/pre-push.sample
+./.git/hooks/update.sample
+./.git/hooks/push-to-checkout.sample
+./.git/refs/heads/pr/47
+./.git/refs/heads/master
+./.git/refs/remotes/github-desktop-AY2324S2-CS2113-T15-3/HEAD
+./.git/refs/remotes/github-desktop-AY2324S2-CS2113-T15-3/master
+./.git/refs/remotes/origin/HEAD
+./.git/refs/remotes/origin/master
+./.git/index
+./.git/packed-refs
+./.git/COMMIT_EDITMSG
+./.git/FETCH_HEAD
+./gradlew.bat
+./src/main/java/financialtransactions/TransactionManager.java
+./src/main/java/financialtransactions/Inflow.java
+./src/main/java/financialtransactions/TransactionList.java
+./src/main/java/financialtransactions/Outflow.java
+./src/main/java/financialtransactions/Transaction.java
+./src/main/java/template/BaseDate.java
+./src/main/java/user/Authentication.java
+./src/main/java/user/BaseUser.java
+./src/main/java/parser/Parser.java
+./src/main/java/Main.java
diff --git a/src/main/java/Main.java b/src/main/java/financeproject/Main.java
similarity index 98%
rename from src/main/java/Main.java
rename to src/main/java/financeproject/Main.java
index 0285871101..d8e833bb14 100644
--- a/src/main/java/Main.java
+++ b/src/main/java/financeproject/Main.java
@@ -1,3 +1,4 @@
+package financeproject;
import java.util.Scanner;
import financialtransactions.Inflow;
diff --git a/src/main/java/financialtransactions/TransactionList.java b/src/main/java/financialtransactions/TransactionList.java
index 83d4944798..48864bd5ec 100644
--- a/src/main/java/financialtransactions/TransactionList.java
+++ b/src/main/java/financialtransactions/TransactionList.java
@@ -41,7 +41,7 @@ public String toString(){
String baseString = "Transactions: \n";
Integer index = 1;
for(T transaction : transactionList){
- baseString += String.format("%d)\t%s\n", index, transaction.toString());
+ baseString += String.format("%d) %s\n", index, transaction.toString());
index += 1;
}
return baseString;
@@ -53,7 +53,7 @@ public String lastNTransactions(int n) {
int index = 1;
for (int i = listSize - 1; i >= listSize - n - 1; i--) {
T transaction = transactionList.get(i);
- baseString += String.format("%d)\t%s\n", index, transaction.toString());
+ baseString += String.format("%d) %s\n", index, transaction.toString());
index++;
}
return baseString;
diff --git a/src/test/java/seedu/duke/DukeTest.java b/src/test/java/seedu/duke/DukeTest.java
deleted file mode 100644
index 2dda5fd651..0000000000
--- a/src/test/java/seedu/duke/DukeTest.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package seedu.duke;
-
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-import org.junit.jupiter.api.Test;
-
-class DukeTest {
- @Test
- public void sampleTest() {
- assertTrue(true);
- }
-}
diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT
index 892cb6cae7..aaeea28810 100644
--- a/text-ui-test/EXPECTED.TXT
+++ b/text-ui-test/EXPECTED.TXT
@@ -1,9 +1,13 @@
-Hello from
- ____ _
-| _ \ _ _| | _____
-| | | | | | | |/ / _ \
-| |_| | |_| | < __/
-|____/ \__,_|_|\_\___|
+Enter password:
+Password is correct
+Inflows:
+Transactions:
+1) Name: Salary payment, Amount: 400.00, Date: Mar 13 2024 11:03pm
+2) Name: Investment, Amount: 500.00, Date: Mar 13 2024 11:03pm
+3) Name: Loan payment, Amount: 400.00, Date: May 23 2022 07:00pm
+
+Outflows:
+Transactions:
+1) Name: Rent, Amount: -50000.00, Date: Mar 13 2024 11:03pm
+2) Name: Shopping, Amount: -200.00, Date: May 23 2022 08:00pm
-What is your name?
-Hello James Gosling
diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt
index f6ec2e9f95..7aa311adf9 100644
--- a/text-ui-test/input.txt
+++ b/text-ui-test/input.txt
@@ -1 +1 @@
-James Gosling
\ No newline at end of file
+password
\ No newline at end of file
From f2fc50be45e3c51de571db67220d0b16f691a1cf Mon Sep 17 00:00:00 2001
From: dylansiew <88567790+dylansiew@users.noreply.github.com>
Date: Wed, 13 Mar 2024 23:11:44 +0800
Subject: [PATCH 010/208] fix: set time for all
---
src/main/java/financeproject/Main.java | 6 +++---
text-ui-test/EXPECTED.TXT | 6 +++---
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/main/java/financeproject/Main.java b/src/main/java/financeproject/Main.java
index d8e833bb14..0e87bc029b 100644
--- a/src/main/java/financeproject/Main.java
+++ b/src/main/java/financeproject/Main.java
@@ -21,11 +21,11 @@ public static void main(String[] args) {
}
TransactionManager manager = new TransactionManager();
- Inflow income = new Inflow("Salary payment", 400.00, null);
+ Inflow income = new Inflow("Salary payment", 400.00, "23/05/2022 1900");
income.setCategory(Inflow.Category.INCOME);
manager.addTransaction(income);
- Inflow investment = new Inflow("Investment", 500.00, null);
+ Inflow investment = new Inflow("Investment", 500.00, "23/05/2022 1900");
investment.setCategory(Inflow.Category.INVESTMENT);
manager.addTransaction(investment);
@@ -33,7 +33,7 @@ public static void main(String[] args) {
loan.setCategory(Inflow.Category.LOAN);
manager.addTransaction(loan);
- Outflow rent = new Outflow("Rent", 50000, null);
+ Outflow rent = new Outflow("Rent", 50000, "23/05/2022 1900");
rent.setCategory(Outflow.Category.RENT);
manager.addTransaction(rent);
diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT
index aaeea28810..b16d13e41d 100644
--- a/text-ui-test/EXPECTED.TXT
+++ b/text-ui-test/EXPECTED.TXT
@@ -2,12 +2,12 @@ Enter password:
Password is correct
Inflows:
Transactions:
-1) Name: Salary payment, Amount: 400.00, Date: Mar 13 2024 11:03pm
-2) Name: Investment, Amount: 500.00, Date: Mar 13 2024 11:03pm
+1) Name: Salary payment, Amount: 400.00, Date: May 23 2022 07:00pm
+2) Name: Investment, Amount: 500.00, Date: May 23 2022 07:00pm
3) Name: Loan payment, Amount: 400.00, Date: May 23 2022 07:00pm
Outflows:
Transactions:
-1) Name: Rent, Amount: -50000.00, Date: Mar 13 2024 11:03pm
+1) Name: Rent, Amount: -50000.00, Date: May 23 2022 07:00pm
2) Name: Shopping, Amount: -200.00, Date: May 23 2022 08:00pm
From 16af8d0b9fe7df695b6967719800325460a69cb1 Mon Sep 17 00:00:00 2001
From: dylansiew <88567790+dylansiew@users.noreply.github.com>
Date: Wed, 13 Mar 2024 23:19:24 +0800
Subject: [PATCH 011/208] fix: Am/PM text
---
src/main/java/template/BaseDate.java | 3 ++-
text-ui-test/EXPECTED.TXT | 10 +++++-----
2 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/main/java/template/BaseDate.java b/src/main/java/template/BaseDate.java
index eeff41335d..094f26264c 100644
--- a/src/main/java/template/BaseDate.java
+++ b/src/main/java/template/BaseDate.java
@@ -4,6 +4,7 @@
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.List;
+import java.util.Locale;
import java.util.ArrayList;
public class BaseDate {
@@ -61,7 +62,7 @@ private static ArrayList dateTimeVary() {
@Override
public String toString() {
- formatter = DateTimeFormatter.ofPattern("MMM dd yyyy hh:mma");
+ formatter = DateTimeFormatter.ofPattern("MMM dd yyyy hh:mma", Locale.US);
return String.format("%s", dateTime.format(formatter));
}
diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT
index b16d13e41d..3eaf7fc564 100644
--- a/text-ui-test/EXPECTED.TXT
+++ b/text-ui-test/EXPECTED.TXT
@@ -2,12 +2,12 @@ Enter password:
Password is correct
Inflows:
Transactions:
-1) Name: Salary payment, Amount: 400.00, Date: May 23 2022 07:00pm
-2) Name: Investment, Amount: 500.00, Date: May 23 2022 07:00pm
-3) Name: Loan payment, Amount: 400.00, Date: May 23 2022 07:00pm
+1) Name: Salary payment, Amount: 400.00, Date: May 23 2022 07:00PM
+2) Name: Investment, Amount: 500.00, Date: May 23 2022 07:00PM
+3) Name: Loan payment, Amount: 400.00, Date: May 23 2022 07:00PM
Outflows:
Transactions:
-1) Name: Rent, Amount: -50000.00, Date: May 23 2022 07:00pm
-2) Name: Shopping, Amount: -200.00, Date: May 23 2022 08:00pm
+1) Name: Rent, Amount: -50000.00, Date: May 23 2022 07:00PM
+2) Name: Shopping, Amount: -200.00, Date: May 23 2022 08:00PM
From a4c9471b3db3b5b0d100305cb7843478577d386f Mon Sep 17 00:00:00 2001
From: chowy
Date: Thu, 14 Mar 2024 22:06:49 +0800
Subject: [PATCH 012/208] Added Storage class to load and store data
---
src/main/java/financeproject/Main.java | 12 ++--
.../financialtransactions/Transaction.java | 5 ++
.../TransactionList.java | 10 +++-
.../TransactionManager.java | 5 +-
src/main/java/storage/Storage.java | 59 +++++++++++++++++++
5 files changed, 85 insertions(+), 6 deletions(-)
create mode 100644 src/main/java/storage/Storage.java
diff --git a/src/main/java/financeproject/Main.java b/src/main/java/financeproject/Main.java
index 0e87bc029b..be36c64170 100644
--- a/src/main/java/financeproject/Main.java
+++ b/src/main/java/financeproject/Main.java
@@ -1,14 +1,16 @@
package financeproject;
import java.util.Scanner;
-import financialtransactions.Inflow;
-import financialtransactions.Outflow;
+//import financialtransactions.Inflow;
+//import financialtransactions.Outflow;
import financialtransactions.TransactionManager;
+import storage.Storage;
import user.Authentication;
import user.BaseUser;
public class Main {
public static void main(String[] args) {
+ Storage storage = new Storage("./data");
BaseUser user = new BaseUser("Bob");
Scanner sc = new Scanner(System.in);
System.out.println("Enter password: ");
@@ -20,7 +22,8 @@ public static void main(String[] args) {
System.out.println("Password is incorrect");
}
- TransactionManager manager = new TransactionManager();
+ TransactionManager manager = storage.loadFile();
+ /*
Inflow income = new Inflow("Salary payment", 400.00, "23/05/2022 1900");
income.setCategory(Inflow.Category.INCOME);
manager.addTransaction(income);
@@ -40,8 +43,9 @@ public static void main(String[] args) {
Outflow shopping = new Outflow("Shopping", 200, "23/05/2022 2000");
shopping.setCategory(Outflow.Category.SHOPPING);
manager.addTransaction(shopping);
-
+ */
System.out.println(manager.toString());
+ storage.saveFile(manager);
sc.close();
}
}
diff --git a/src/main/java/financialtransactions/Transaction.java b/src/main/java/financialtransactions/Transaction.java
index 46afb222e2..469d54b1b2 100644
--- a/src/main/java/financialtransactions/Transaction.java
+++ b/src/main/java/financialtransactions/Transaction.java
@@ -40,4 +40,9 @@ public String toString() {
String baseString = String.format("Name: %s, Amount: %.2f, Date: %s", name, amount, date.toString());
return baseString;
}
+
+ public String toSave() {
+ String baseString = String.format("%s|%.2f|%s|%s\n", name, amount, date.toString(), category);
+ return baseString;
+ }
}
diff --git a/src/main/java/financialtransactions/TransactionList.java b/src/main/java/financialtransactions/TransactionList.java
index 48864bd5ec..cce8ff6844 100644
--- a/src/main/java/financialtransactions/TransactionList.java
+++ b/src/main/java/financialtransactions/TransactionList.java
@@ -58,5 +58,13 @@ public String lastNTransactions(int n) {
}
return baseString;
}
-
+
+ public String toSave() {
+ String baseString = "";
+ for (T transaction : transactionList) {
+ baseString += transaction.toSave();
+ }
+ return baseString;
+ }
+
}
diff --git a/src/main/java/financialtransactions/TransactionManager.java b/src/main/java/financialtransactions/TransactionManager.java
index 6c070c08a3..15cacb68c6 100644
--- a/src/main/java/financialtransactions/TransactionManager.java
+++ b/src/main/java/financialtransactions/TransactionManager.java
@@ -46,5 +46,8 @@ public void displayTransactionHistory(int n) {
String outflowTransactions = outflows.lastNTransactions(n);
System.out.println("Inflows:\n" + inflowTransactions + "\nOutflows:\n" + outflowTransactions);
}
-
+
+ public String toSave() {
+ return inflows.toSave() + outflows.toSave();
+ }
}
diff --git a/src/main/java/storage/Storage.java b/src/main/java/storage/Storage.java
new file mode 100644
index 0000000000..78d6e5d30e
--- /dev/null
+++ b/src/main/java/storage/Storage.java
@@ -0,0 +1,59 @@
+package storage;
+
+import financialtransactions.Inflow;
+import financialtransactions.Outflow;
+import financialtransactions.TransactionManager;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.Scanner;
+
+public class Storage {
+ private final String filePath;
+ public Storage(String filePath) {
+ this.filePath = filePath;
+ }
+
+ public TransactionManager loadFile() {
+ File f = new File(filePath + "/data.txt");
+ TransactionManager manager = new TransactionManager();
+ try {
+ Scanner sc = new Scanner(f);
+ while (sc.hasNext()) {
+ String[] transactionInfo = sc.nextLine().split("\\|");
+ double amount = Double.parseDouble(transactionInfo[1]);
+ if (!transactionInfo[1].startsWith("-")) {
+ Inflow inflow = new Inflow(transactionInfo[0], amount, transactionInfo[2]);
+ inflow.setCategory(Inflow.Category.valueOf(transactionInfo[3]));
+ manager.addTransaction(inflow);
+ } else {
+ Outflow outflow = new Outflow(transactionInfo[0], -amount, transactionInfo[2]);
+ outflow.setCategory(Outflow.Category.valueOf(transactionInfo[3]));
+ manager.addTransaction(outflow);
+ }
+ }
+ } catch (FileNotFoundException e) {
+ createFileDir();
+ }
+ return manager;
+ }
+
+ private void createFileDir() {
+ File f = new File(filePath);
+ if (!f.mkdir()) {
+ System.out.println("create file failed");
+ }
+ }
+
+ public void saveFile(TransactionManager tm) {
+ try {
+ FileWriter fw = new FileWriter(filePath + "/data.txt");
+ fw.write(tm.toSave());
+ fw.close();
+ } catch (IOException e) {
+ System.out.println("Unable to save tasks!");
+ }
+ }
+}
From 2433db0189c5dee3918141d002f511a514362ffb Mon Sep 17 00:00:00 2001
From: chowy
Date: Thu, 14 Mar 2024 22:13:04 +0800
Subject: [PATCH 013/208] Added UI class to handle user interactions
---
src/main/java/financeproject/Main.java | 15 +++++++--------
src/main/java/userinteraction/UI.java | 17 +++++++++++++++++
2 files changed, 24 insertions(+), 8 deletions(-)
create mode 100644 src/main/java/userinteraction/UI.java
diff --git a/src/main/java/financeproject/Main.java b/src/main/java/financeproject/Main.java
index be36c64170..bbfb93e21b 100644
--- a/src/main/java/financeproject/Main.java
+++ b/src/main/java/financeproject/Main.java
@@ -1,5 +1,4 @@
package financeproject;
-import java.util.Scanner;
//import financialtransactions.Inflow;
//import financialtransactions.Outflow;
@@ -7,19 +6,20 @@
import storage.Storage;
import user.Authentication;
import user.BaseUser;
+import userinteraction.UI;
public class Main {
public static void main(String[] args) {
Storage storage = new Storage("./data");
BaseUser user = new BaseUser("Bob");
- Scanner sc = new Scanner(System.in);
- System.out.println("Enter password: ");
- String password = sc.nextLine();
+ UI ui = new UI();
+ ui.printMessage("Enter password: ");
+ String password = ui.readInput();
Authentication auth = user.getAuthentication();
if (auth.checkPassword("Bob", password)) {
- System.out.println("Password is correct");
+ ui.printMessage("Password is correct");
} else {
- System.out.println("Password is incorrect");
+ ui.printMessage("Password is incorrect");
}
TransactionManager manager = storage.loadFile();
@@ -44,8 +44,7 @@ public static void main(String[] args) {
shopping.setCategory(Outflow.Category.SHOPPING);
manager.addTransaction(shopping);
*/
- System.out.println(manager.toString());
+ ui.printMessage(manager.toString());
storage.saveFile(manager);
- sc.close();
}
}
diff --git a/src/main/java/userinteraction/UI.java b/src/main/java/userinteraction/UI.java
new file mode 100644
index 0000000000..0119de4db1
--- /dev/null
+++ b/src/main/java/userinteraction/UI.java
@@ -0,0 +1,17 @@
+package userinteraction;
+
+import java.util.Scanner;
+
+public class UI {
+ private final Scanner sc = new Scanner(System.in);
+
+ public UI() {}
+
+ public void printMessage(String message) {
+ System.out.println(message);
+ }
+
+ public String readInput() {
+ return sc.nextLine();
+ }
+}
From 9de0182a3232299c70698641428110d2c0e5b1b8 Mon Sep 17 00:00:00 2001
From: chowy
Date: Thu, 14 Mar 2024 22:20:30 +0800
Subject: [PATCH 014/208] Changed expected output
---
text-ui-test/EXPECTED.TXT | 5 -----
1 file changed, 5 deletions(-)
diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT
index 3eaf7fc564..ac391e0738 100644
--- a/text-ui-test/EXPECTED.TXT
+++ b/text-ui-test/EXPECTED.TXT
@@ -2,12 +2,7 @@ Enter password:
Password is correct
Inflows:
Transactions:
-1) Name: Salary payment, Amount: 400.00, Date: May 23 2022 07:00PM
-2) Name: Investment, Amount: 500.00, Date: May 23 2022 07:00PM
-3) Name: Loan payment, Amount: 400.00, Date: May 23 2022 07:00PM
Outflows:
Transactions:
-1) Name: Rent, Amount: -50000.00, Date: May 23 2022 07:00PM
-2) Name: Shopping, Amount: -200.00, Date: May 23 2022 08:00PM
From 2828d6b39a691f91f743294d6dfb2ad74cdd603b Mon Sep 17 00:00:00 2001
From: Kishen271828
Date: Thu, 14 Mar 2024 23:15:56 +0800
Subject: [PATCH 015/208] Fix errors in view transaction history function
---
src/main/java/financeproject/Main.java | 1 +
.../TransactionList.java | 23 +++++-------
.../TransactionManager.java | 35 +++++++++++++++----
src/main/java/parser/Parser.java | 2 +-
4 files changed, 40 insertions(+), 21 deletions(-)
diff --git a/src/main/java/financeproject/Main.java b/src/main/java/financeproject/Main.java
index 0e87bc029b..2efaafcd3f 100644
--- a/src/main/java/financeproject/Main.java
+++ b/src/main/java/financeproject/Main.java
@@ -42,6 +42,7 @@ public static void main(String[] args) {
manager.addTransaction(shopping);
System.out.println(manager.toString());
+ manager.showLastNTransactions(3);
sc.close();
}
}
diff --git a/src/main/java/financialtransactions/TransactionList.java b/src/main/java/financialtransactions/TransactionList.java
index 48864bd5ec..8d9d2ae0d2 100644
--- a/src/main/java/financialtransactions/TransactionList.java
+++ b/src/main/java/financialtransactions/TransactionList.java
@@ -13,6 +13,14 @@ public ArrayList getTransactionList() {
return this.transactionList;
}
+ public int getTransactionListSize() {
+ return this.transactionList.size();
+ }
+
+ public T getNthTransaction(int n) {
+ return this.transactionList.get(n);
+ }
+
public Boolean addTransaction(T newTransaction){
if(newTransaction != null){
transactionList.add(newTransaction);
@@ -21,7 +29,7 @@ public Boolean addTransaction(T newTransaction){
return false;
}
- public Boolean removeTransacitonIndex(int index){
+ public Boolean removeTransactionIndex (int index){
if(index >= transactionList.size() || index < 0){
System.out.println("Invalid Index");
return false;
@@ -46,17 +54,4 @@ public String toString(){
}
return baseString;
}
-
- public String lastNTransactions(int n) {
- String baseString = "Transactions: \n";
- int listSize = transactionList.size();
- int index = 1;
- for (int i = listSize - 1; i >= listSize - n - 1; i--) {
- T transaction = transactionList.get(i);
- baseString += String.format("%d) %s\n", index, transaction.toString());
- index++;
- }
- return baseString;
- }
-
}
diff --git a/src/main/java/financialtransactions/TransactionManager.java b/src/main/java/financialtransactions/TransactionManager.java
index 6c070c08a3..dc11928f29 100644
--- a/src/main/java/financialtransactions/TransactionManager.java
+++ b/src/main/java/financialtransactions/TransactionManager.java
@@ -2,15 +2,18 @@
public class TransactionManager {
+ private TransactionList> transactionList;
private TransactionList inflows;
private TransactionList outflows;
public TransactionManager() {
+ this.transactionList = new TransactionList<>();
this.inflows = new TransactionList<>();
this.outflows = new TransactionList<>();
}
public boolean addTransaction(Transaction> transaction) {
+ transactionList.addTransaction(transaction);
if (transaction instanceof Inflow) {
Inflow inflow = (Inflow) transaction;
return inflows.addTransaction(inflow);
@@ -23,10 +26,11 @@ public boolean addTransaction(Transaction> transaction) {
}
public boolean removeTransaction(int index, boolean isInflow) {
+ transactionList.removeTransactionIndex(index);
if (isInflow) {
- return inflows.removeTransacitonIndex(index);
+ return inflows.removeTransactionIndex(index);
} else {
- return outflows.removeTransacitonIndex(index);
+ return outflows.removeTransactionIndex(index);
}
}
@@ -41,10 +45,29 @@ public String toString() {
return "Inflows:\n" + inflows.toString() + "\nOutflows:\n" + outflows.toString();
}
- public void displayTransactionHistory(int n) {
- String inflowTransactions = inflows.lastNTransactions(n);
- String outflowTransactions = outflows.lastNTransactions(n);
- System.out.println("Inflows:\n" + inflowTransactions + "\nOutflows:\n" + outflowTransactions);
+ public void showLastNTransactions(int n) {
+ int listSize = transactionList.getTransactionListSize();
+ int index = 1;
+
+ System.out.println("Inflows:\nTransactions:");
+ for (int i = listSize - 1; i > listSize - n - 1; i--) {
+ Transaction> transaction = transactionList.getNthTransaction(i);
+ if (transaction instanceof Inflow) {
+ System.out.println(index + ") " + transactionList.getNthTransaction(i).toString());
+ index++;
+ }
+ }
+
+ index = 1;
+ System.out.println("\nOutflows:\nTransactions:");
+ for (int i = listSize - 1; i > listSize - n - 1; i--) {
+ Transaction> transaction = transactionList.getNthTransaction(i);
+ if (transaction instanceof Outflow) {
+ System.out.println(index + ") " + transactionList.getNthTransaction(i).toString());
+ index++;
+ }
+ }
+
}
}
diff --git a/src/main/java/parser/Parser.java b/src/main/java/parser/Parser.java
index a2217952c9..2b0b165ff0 100644
--- a/src/main/java/parser/Parser.java
+++ b/src/main/java/parser/Parser.java
@@ -27,7 +27,7 @@ public static void parseCommand(String command, TransactionManager manager) {
break;
case "view-history":
int numTransactions = Integer.parseInt(command.split(" ")[1].trim());
- manager.displayTransactionHistory(numTransactions);
+ manager.showLastNTransactions(numTransactions);
break;
case "export-csv":
// Implement export to CSV functionality
From db9d9ba238b4e02c0994e916a179b0dc2a38056c Mon Sep 17 00:00:00 2001
From: Kishen271828
Date: Thu, 14 Mar 2024 23:33:56 +0800
Subject: [PATCH 016/208] Add close scanner method
---
src/main/java/financeproject/Main.java | 2 +-
src/main/java/userinteraction/UI.java | 4 ++++
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/src/main/java/financeproject/Main.java b/src/main/java/financeproject/Main.java
index 09bed7bf77..512cfbb432 100644
--- a/src/main/java/financeproject/Main.java
+++ b/src/main/java/financeproject/Main.java
@@ -47,7 +47,7 @@ public static void main(String[] args) {
ui.printMessage(manager.toString());
manager.showLastNTransactions(3);
- //sc.close();
storage.saveFile(manager);
+ ui.closeScanner();
}
}
diff --git a/src/main/java/userinteraction/UI.java b/src/main/java/userinteraction/UI.java
index 0119de4db1..81dacce5b0 100644
--- a/src/main/java/userinteraction/UI.java
+++ b/src/main/java/userinteraction/UI.java
@@ -14,4 +14,8 @@ public void printMessage(String message) {
public String readInput() {
return sc.nextLine();
}
+
+ public void closeScanner() {
+ sc.close();
+ }
}
From 42bc71ef91745bf078933e0b221c4be26e585c2a Mon Sep 17 00:00:00 2001
From: Kishen271828
Date: Fri, 15 Mar 2024 01:47:38 +0800
Subject: [PATCH 017/208] Implement login(partially), add, view-history, quit
in Parser
---
src/main/java/financeproject/Main.java | 20 +++++--
.../TransactionManager.java | 1 -
src/main/java/parser/Parser.java | 56 +++++++++++++------
3 files changed, 53 insertions(+), 24 deletions(-)
diff --git a/src/main/java/financeproject/Main.java b/src/main/java/financeproject/Main.java
index 512cfbb432..292dce220c 100644
--- a/src/main/java/financeproject/Main.java
+++ b/src/main/java/financeproject/Main.java
@@ -3,6 +3,7 @@
import financialtransactions.Inflow;
import financialtransactions.Outflow;
import financialtransactions.TransactionManager;
+import parser.Parser;
import storage.Storage;
import user.Authentication;
import user.BaseUser;
@@ -11,8 +12,9 @@
public class Main {
public static void main(String[] args) {
Storage storage = new Storage("./data");
- BaseUser user = new BaseUser("Bob");
UI ui = new UI();
+ ui.printMessage("Welcome. Inorder to login, type your command in the format:\nlogin u/USERNAME p/PASSWORD");
+ /*BaseUser user = new BaseUser("Bob");
ui.printMessage("Enter password: ");
String password = ui.readInput();
Authentication auth = user.getAuthentication();
@@ -21,9 +23,18 @@ public static void main(String[] args) {
} else {
ui.printMessage("Password is incorrect");
}
+*/
- TransactionManager manager = storage.loadFile();
+ //TransactionManager manager = storage.loadFile();
+ TransactionManager manager = new TransactionManager();
+ while (Parser.isContinue) {
+ String command = ui.readInput();
+ Parser.parseCommand(command, manager);
+ storage.saveFile(manager);
+ }
+ ui.closeScanner();
+ /*
Inflow income = new Inflow("Salary payment", 400.00, "23/05/2022 1900");
income.setCategory(Inflow.Category.INCOME);
manager.addTransaction(income);
@@ -45,9 +56,6 @@ public static void main(String[] args) {
manager.addTransaction(shopping);
- ui.printMessage(manager.toString());
- manager.showLastNTransactions(3);
- storage.saveFile(manager);
- ui.closeScanner();
+ ui.printMessage(manager.toString()); */
}
}
diff --git a/src/main/java/financialtransactions/TransactionManager.java b/src/main/java/financialtransactions/TransactionManager.java
index a66077aa50..72cdfd6270 100644
--- a/src/main/java/financialtransactions/TransactionManager.java
+++ b/src/main/java/financialtransactions/TransactionManager.java
@@ -67,7 +67,6 @@ public void showLastNTransactions(int n) {
index++;
}
}
-
}
public String toSave() {
diff --git a/src/main/java/parser/Parser.java b/src/main/java/parser/Parser.java
index 2b0b165ff0..0245d2e730 100644
--- a/src/main/java/parser/Parser.java
+++ b/src/main/java/parser/Parser.java
@@ -1,39 +1,61 @@
package parser;
+import financialtransactions.Inflow;
+import financialtransactions.Outflow;
import financialtransactions.TransactionManager;
+import user.Authentication;
+import user.BaseUser;
+import userinteraction.UI;
public class Parser {
- protected static boolean isContinue = true;
+ public static boolean isContinue = true;
+ static UI ui = new UI();
public static void parseCommand(String command, TransactionManager manager) {
String[] commandParts = command.split(" ");
String action = commandParts[0];
switch (action) {
- case "login":
- // Implement login functionality
+ case "login": ;
+ BaseUser user = new BaseUser(commandParts[1]);
+ String password = commandParts[2];
+ Authentication auth = user.getAuthentication();
+ if (auth.checkPassword(user.getName(), password)) {
+ ui.printMessage("Password is correct. You are now logged in");
+ } else {
+ ui.printMessage("Password is incorrect");
+ }
break;
- case "add-source":
- // Implement add source of income functionality
+ case "add-inflow":
+ String inflowName = commandParts[1];
+ double inflowAmount = Double.parseDouble(commandParts[2]);
+ String inflowDate = commandParts[3] + " " + commandParts[4];
+
+ Inflow inflow = new Inflow(inflowName, inflowAmount, inflowDate);
+ manager.addTransaction(inflow);
+ ui.printMessage("Ok. Added inflow");
break;
- case "delete-source":
- // Implement delete source of income functionality
+ case "add-outflow":
+ String outflowName = commandParts[1];
+ double outflowAmount = Double.parseDouble(commandParts[2]);
+ String outflowDate = commandParts[3] + " " + commandParts[4];
+
+ Outflow outflow = new Outflow(outflowName, outflowAmount, outflowDate);
+ manager.addTransaction(outflow);
+ ui.printMessage("Ok. Added outflow");
break;
- case "add-transaction":
- // Implement add transaction functionality
+ case "delete-inflow":
+ //manager.removeTransaction(1, true);
break;
- case "delete-transaction":
- // Implement delete transaction functionality
+ case "delete-outflow":
+ //manager.removeTransaction(1, false);
break;
case "view-history":
- int numTransactions = Integer.parseInt(command.split(" ")[1].trim());
+ int numTransactions = Integer.parseInt(commandParts[1].trim());
manager.showLastNTransactions(numTransactions);
break;
- case "export-csv":
- // Implement export to CSV functionality
- break;
- case "help":
- // Implement help functionality
+ case "quit":
+ isContinue = false;
break;
default:
System.out.println("Invalid command");
From 0e7f2ad28643cdc56079bf125d1d68873bb916b1 Mon Sep 17 00:00:00 2001
From: Kishen271828
Date: Fri, 15 Mar 2024 01:49:22 +0800
Subject: [PATCH 018/208] Delete commented code
---
src/main/java/financeproject/Main.java | 10 ----------
1 file changed, 10 deletions(-)
diff --git a/src/main/java/financeproject/Main.java b/src/main/java/financeproject/Main.java
index 292dce220c..b32bb3ed0a 100644
--- a/src/main/java/financeproject/Main.java
+++ b/src/main/java/financeproject/Main.java
@@ -14,16 +14,6 @@ public static void main(String[] args) {
Storage storage = new Storage("./data");
UI ui = new UI();
ui.printMessage("Welcome. Inorder to login, type your command in the format:\nlogin u/USERNAME p/PASSWORD");
- /*BaseUser user = new BaseUser("Bob");
- ui.printMessage("Enter password: ");
- String password = ui.readInput();
- Authentication auth = user.getAuthentication();
- if (auth.checkPassword("Bob", password)) {
- ui.printMessage("Password is correct");
- } else {
- ui.printMessage("Password is incorrect");
- }
-*/
//TransactionManager manager = storage.loadFile();
TransactionManager manager = new TransactionManager();
From fadc5a4fddebb43e59d4cbd0af51e1354266fe8c Mon Sep 17 00:00:00 2001
From: Kishen271828
Date: Fri, 15 Mar 2024 02:09:19 +0800
Subject: [PATCH 019/208] fix gradle check issue
---
src/main/java/financeproject/Main.java | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/main/java/financeproject/Main.java b/src/main/java/financeproject/Main.java
index b32bb3ed0a..614327b2b7 100644
--- a/src/main/java/financeproject/Main.java
+++ b/src/main/java/financeproject/Main.java
@@ -1,12 +1,12 @@
package financeproject;
-import financialtransactions.Inflow;
-import financialtransactions.Outflow;
+//import financialtransactions.Inflow;
+//import financialtransactions.Outflow;
import financialtransactions.TransactionManager;
import parser.Parser;
import storage.Storage;
-import user.Authentication;
-import user.BaseUser;
+//import user.Authentication;
+//import user.BaseUser;
import userinteraction.UI;
public class Main {
From b4df6c610714ba8bad87e09f9175ff3a44ad6cc5 Mon Sep 17 00:00:00 2001
From: ChongXern
Date: Fri, 15 Mar 2024 13:10:38 +0800
Subject: [PATCH 020/208] Add FinTrackTest file and minor adjustments to other
files
---
src/test/java/seedu/FinTrack/FinTrackTest.java | 2 ++
1 file changed, 2 insertions(+)
create mode 100644 src/test/java/seedu/FinTrack/FinTrackTest.java
diff --git a/src/test/java/seedu/FinTrack/FinTrackTest.java b/src/test/java/seedu/FinTrack/FinTrackTest.java
new file mode 100644
index 0000000000..fbc9a950c3
--- /dev/null
+++ b/src/test/java/seedu/FinTrack/FinTrackTest.java
@@ -0,0 +1,2 @@
+package seedu.FinTrack;public class FinTrackTest {
+}
From 234c7a9373156fc407c9aabbe4ebf94b2f5bc655 Mon Sep 17 00:00:00 2001
From: ChongXern
Date: Fri, 15 Mar 2024 15:00:46 +0800
Subject: [PATCH 021/208] Add FinTrack and modify parser
---
.../financialtransactions/TransactionList.java | 7 ++++---
.../financialtransactions/TransactionManager.java | 4 ++--
src/main/java/parser/Parser.java | 5 +++++
src/test/java/seedu/FinTrack/FinTrackTest.java | 14 ++++++++++++--
4 files changed, 23 insertions(+), 7 deletions(-)
diff --git a/src/main/java/financialtransactions/TransactionList.java b/src/main/java/financialtransactions/TransactionList.java
index cce8ff6844..e12e50e974 100644
--- a/src/main/java/financialtransactions/TransactionList.java
+++ b/src/main/java/financialtransactions/TransactionList.java
@@ -13,15 +13,15 @@ public ArrayList getTransactionList() {
return this.transactionList;
}
- public Boolean addTransaction(T newTransaction){
- if(newTransaction != null){
+ public boolean addTransaction(T newTransaction){
+ if (newTransaction != null){
transactionList.add(newTransaction);
return true;
}
return false;
}
- public Boolean removeTransacitonIndex(int index){
+ public Boolean removeTransactionIndex(int index){
if(index >= transactionList.size() || index < 0){
System.out.println("Invalid Index");
return false;
@@ -29,6 +29,7 @@ public Boolean removeTransacitonIndex(int index){
transactionList.remove(index);
return true;
}
+
public double getBalance(){
double balance = 0.00;
for(Transaction> transaction : transactionList){
diff --git a/src/main/java/financialtransactions/TransactionManager.java b/src/main/java/financialtransactions/TransactionManager.java
index 15cacb68c6..91075f42c8 100644
--- a/src/main/java/financialtransactions/TransactionManager.java
+++ b/src/main/java/financialtransactions/TransactionManager.java
@@ -24,9 +24,9 @@ public boolean addTransaction(Transaction> transaction) {
public boolean removeTransaction(int index, boolean isInflow) {
if (isInflow) {
- return inflows.removeTransacitonIndex(index);
+ return inflows.removeTransactionIndex(index);
} else {
- return outflows.removeTransacitonIndex(index);
+ return outflows.removeTransactionIndex(index);
}
}
diff --git a/src/main/java/parser/Parser.java b/src/main/java/parser/Parser.java
index a2217952c9..4de3c7e849 100644
--- a/src/main/java/parser/Parser.java
+++ b/src/main/java/parser/Parser.java
@@ -1,8 +1,13 @@
package parser;
+import userinteraction.UI;
import financialtransactions.TransactionManager;
public class Parser {
+ UI ui;
+ public Parser(UI ui) {
+ this.ui = ui;
+ }
protected static boolean isContinue = true;
public static void parseCommand(String command, TransactionManager manager) {
diff --git a/src/test/java/seedu/FinTrack/FinTrackTest.java b/src/test/java/seedu/FinTrack/FinTrackTest.java
index fbc9a950c3..f0349ac6d4 100644
--- a/src/test/java/seedu/FinTrack/FinTrackTest.java
+++ b/src/test/java/seedu/FinTrack/FinTrackTest.java
@@ -1,2 +1,12 @@
-package seedu.FinTrack;public class FinTrackTest {
-}
+package seedu.FinTrack;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import org.junit.jupiter.api.Test;
+
+public class FinTrackTest {
+ @Test
+ public void sampleTest() {
+ assertTrue(true);
+ }
+}
\ No newline at end of file
From 9a7f83aade6a8b8ba0cacab12f92c8b84a1871d2 Mon Sep 17 00:00:00 2001
From: ChongXern
Date: Fri, 15 Mar 2024 15:46:51 +0800
Subject: [PATCH 022/208] Add outflow junit test
---
.../java/financialtransactions/OutflowTest.java | 13 +++++++++++++
1 file changed, 13 insertions(+)
create mode 100644 src/main/java/financialtransactions/OutflowTest.java
diff --git a/src/main/java/financialtransactions/OutflowTest.java b/src/main/java/financialtransactions/OutflowTest.java
new file mode 100644
index 0000000000..8816ccc747
--- /dev/null
+++ b/src/main/java/financialtransactions/OutflowTest.java
@@ -0,0 +1,13 @@
+package financialtransactions;
+
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
+public class OutflowTest {
+ @Test
+ public void testSetCategory() {
+ Outflow outflow = new Outflow("2024 Sem 2 School Fees", 999999.99, "2024-02-01");
+ outflow.setCategory(Outflow.Category.EDUCATION);
+ assertEquals(Outflow.Category.EDUCATION, outflow.getCategory());
+ }
+}
From 4e0960feeda68dcfcbf94a495792c5a5bb335c71 Mon Sep 17 00:00:00 2001
From: Chong Xern <104547209+ChongXern@users.noreply.github.com>
Date: Fri, 15 Mar 2024 15:49:12 +0800
Subject: [PATCH 023/208] Create OutflowTest.java
---
.../java/financialtransactions/OutflowTest.java | 13 +++++++++++++
1 file changed, 13 insertions(+)
create mode 100644 src/main/java/financialtransactions/OutflowTest.java
diff --git a/src/main/java/financialtransactions/OutflowTest.java b/src/main/java/financialtransactions/OutflowTest.java
new file mode 100644
index 0000000000..8816ccc747
--- /dev/null
+++ b/src/main/java/financialtransactions/OutflowTest.java
@@ -0,0 +1,13 @@
+package financialtransactions;
+
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
+public class OutflowTest {
+ @Test
+ public void testSetCategory() {
+ Outflow outflow = new Outflow("2024 Sem 2 School Fees", 999999.99, "2024-02-01");
+ outflow.setCategory(Outflow.Category.EDUCATION);
+ assertEquals(Outflow.Category.EDUCATION, outflow.getCategory());
+ }
+}
From f45b6c29ce377aae29740a96b8fcb1711bedfaef Mon Sep 17 00:00:00 2001
From: Kishen271828
Date: Fri, 15 Mar 2024 15:54:43 +0800
Subject: [PATCH 024/208] Add JUnit test for Parser class
---
src/main/java/financeproject/Main.java | 6 +++---
src/main/java/parser/Parser.java | 18 ++++++++++++------
src/main/java/parser/ParserTest.java | 16 ++++++++++++++++
3 files changed, 31 insertions(+), 9 deletions(-)
create mode 100644 src/main/java/parser/ParserTest.java
diff --git a/src/main/java/financeproject/Main.java b/src/main/java/financeproject/Main.java
index 614327b2b7..beff48015c 100644
--- a/src/main/java/financeproject/Main.java
+++ b/src/main/java/financeproject/Main.java
@@ -14,13 +14,13 @@ public static void main(String[] args) {
Storage storage = new Storage("./data");
UI ui = new UI();
ui.printMessage("Welcome. Inorder to login, type your command in the format:\nlogin u/USERNAME p/PASSWORD");
-
//TransactionManager manager = storage.loadFile();
TransactionManager manager = new TransactionManager();
- while (Parser.isContinue) {
+ Parser parser = new Parser();
+ while (parser.isContinue) {
String command = ui.readInput();
- Parser.parseCommand(command, manager);
+ parser.parseCommand(command, manager);
storage.saveFile(manager);
}
ui.closeScanner();
diff --git a/src/main/java/parser/Parser.java b/src/main/java/parser/Parser.java
index 0245d2e730..ffe066c43a 100644
--- a/src/main/java/parser/Parser.java
+++ b/src/main/java/parser/Parser.java
@@ -8,15 +8,20 @@
import userinteraction.UI;
public class Parser {
- public static boolean isContinue = true;
- static UI ui = new UI();
+ public boolean isContinue;
+ UI ui;
- public static void parseCommand(String command, TransactionManager manager) {
+ public Parser() {
+ this.isContinue = true;
+ this.ui = new UI();
+ }
+
+ public String parseCommand(String command, TransactionManager manager) {
String[] commandParts = command.split(" ");
String action = commandParts[0];
switch (action) {
- case "login": ;
+ case "login":
BaseUser user = new BaseUser(commandParts[1]);
String password = commandParts[2];
Authentication auth = user.getAuthentication();
@@ -34,7 +39,7 @@ public static void parseCommand(String command, TransactionManager manager) {
Inflow inflow = new Inflow(inflowName, inflowAmount, inflowDate);
manager.addTransaction(inflow);
ui.printMessage("Ok. Added inflow");
- break;
+ return "Ok. Added inflow";
case "add-outflow":
String outflowName = commandParts[1];
double outflowAmount = Double.parseDouble(commandParts[2]);
@@ -43,7 +48,7 @@ public static void parseCommand(String command, TransactionManager manager) {
Outflow outflow = new Outflow(outflowName, outflowAmount, outflowDate);
manager.addTransaction(outflow);
ui.printMessage("Ok. Added outflow");
- break;
+ return "Ok. Added outflow";
case "delete-inflow":
//manager.removeTransaction(1, true);
break;
@@ -61,6 +66,7 @@ public static void parseCommand(String command, TransactionManager manager) {
System.out.println("Invalid command");
break;
}
+ return null;
}
}
diff --git a/src/main/java/parser/ParserTest.java b/src/main/java/parser/ParserTest.java
new file mode 100644
index 0000000000..6ecdd37cc4
--- /dev/null
+++ b/src/main/java/parser/ParserTest.java
@@ -0,0 +1,16 @@
+package parser;
+
+import financialtransactions.TransactionManager;
+import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+//import static org.junit.jupiter.api.Assertions.fail;
+
+public class ParserTest {
+ TransactionManager manager = new TransactionManager();
+
+ @Test
+ public void addInflow_success() {
+ assertEquals("Ok. Added inflow", new Parser().parseCommand("add-inflow Salary 50000 14/03/2024 1700", manager));
+ }
+
+}
From b7e56164496ad7f6e7fc7d89925012a9b7b2362f Mon Sep 17 00:00:00 2001
From: ChongXern
Date: Fri, 15 Mar 2024 15:59:58 +0800
Subject: [PATCH 025/208] Add inflow adding method
---
src/main/java/financialtransactions/TransactionList.java | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/main/java/financialtransactions/TransactionList.java b/src/main/java/financialtransactions/TransactionList.java
index e12e50e974..936511fcce 100644
--- a/src/main/java/financialtransactions/TransactionList.java
+++ b/src/main/java/financialtransactions/TransactionList.java
@@ -67,5 +67,8 @@ public String toSave() {
}
return baseString;
}
-
+
+ public void addInflow(Inflow inflow) {
+ transactionList.add((T) inflow);
+ }
}
From ed2cb7fd9e19c1eb1d901138c5866e461bb31118 Mon Sep 17 00:00:00 2001
From: Kishen271828
Date: Fri, 15 Mar 2024 21:20:18 +0800
Subject: [PATCH 026/208] Move ParserTest.java to its right place
---
src/main/java/parser/ParserTest.java | 16 ----------------
src/test/java/parser/ParserTest.java | 22 ++++++++++++++++++++++
2 files changed, 22 insertions(+), 16 deletions(-)
delete mode 100644 src/main/java/parser/ParserTest.java
create mode 100644 src/test/java/parser/ParserTest.java
diff --git a/src/main/java/parser/ParserTest.java b/src/main/java/parser/ParserTest.java
deleted file mode 100644
index 6ecdd37cc4..0000000000
--- a/src/main/java/parser/ParserTest.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package parser;
-
-import financialtransactions.TransactionManager;
-import org.junit.jupiter.api.Test;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-//import static org.junit.jupiter.api.Assertions.fail;
-
-public class ParserTest {
- TransactionManager manager = new TransactionManager();
-
- @Test
- public void addInflow_success() {
- assertEquals("Ok. Added inflow", new Parser().parseCommand("add-inflow Salary 50000 14/03/2024 1700", manager));
- }
-
-}
diff --git a/src/test/java/parser/ParserTest.java b/src/test/java/parser/ParserTest.java
new file mode 100644
index 0000000000..94593ae0d2
--- /dev/null
+++ b/src/test/java/parser/ParserTest.java
@@ -0,0 +1,22 @@
+package parser;
+
+import financialtransactions.TransactionManager;
+import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+//import static org.junit.jupiter.api.Assertions.fail;
+
+public class ParserTest {
+ TransactionManager manager = new TransactionManager();
+
+ @Test
+ public void addInflow_success() {
+ assertEquals("Ok. Added inflow", new Parser().parseCommand("add-inflow Salary 5000 14/03/2024 1700", manager));
+ assertEquals("Ok. Added inflow", new Parser().parseCommand("add-inflow Investment 600 03/03/2024 1900", manager));
+ }
+
+ public void addOutflow_success() {
+ assertEquals("Ok. Added outflow", new Parser().parseCommand("add-outflow Rent 1000 18/02/2024 1100", manager));
+ assertEquals("Ok. Added outflow", new Parser().parseCommand("add-outflow Shopping 150 30/01/2024 1430", manager));
+ }
+
+}
From 02124100d00bceffc9aa0993418a94c037c78ed5 Mon Sep 17 00:00:00 2001
From: dylansiew <88567790+dylansiew@users.noreply.github.com>
Date: Fri, 15 Mar 2024 21:47:38 +0800
Subject: [PATCH 027/208] feature: junit test
---
build.gradle | 8 ++++++++
.../java/financialtransactions/OutflowTest.java | 13 -------------
src/test/java/user/BaseUserTest.java | 14 ++++++++++++++
3 files changed, 22 insertions(+), 13 deletions(-)
delete mode 100644 src/main/java/financialtransactions/OutflowTest.java
create mode 100644 src/test/java/user/BaseUserTest.java
diff --git a/build.gradle b/build.gradle
index 833bad8eb2..b699c5a6c7 100644
--- a/build.gradle
+++ b/build.gradle
@@ -44,3 +44,11 @@ checkstyle {
run{
standardInput = System.in
}
+dependencies {
+ testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.10.0'
+ testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.10.0'
+}
+test {
+ useJUnitPlatform()
+}
+
diff --git a/src/main/java/financialtransactions/OutflowTest.java b/src/main/java/financialtransactions/OutflowTest.java
deleted file mode 100644
index 8816ccc747..0000000000
--- a/src/main/java/financialtransactions/OutflowTest.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package financialtransactions;
-
-import org.junit.Test;
-import static org.junit.Assert.assertEquals;
-
-public class OutflowTest {
- @Test
- public void testSetCategory() {
- Outflow outflow = new Outflow("2024 Sem 2 School Fees", 999999.99, "2024-02-01");
- outflow.setCategory(Outflow.Category.EDUCATION);
- assertEquals(Outflow.Category.EDUCATION, outflow.getCategory());
- }
-}
diff --git a/src/test/java/user/BaseUserTest.java b/src/test/java/user/BaseUserTest.java
new file mode 100644
index 0000000000..2eb415e3ae
--- /dev/null
+++ b/src/test/java/user/BaseUserTest.java
@@ -0,0 +1,14 @@
+package user;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class BaseUserTest {
+ @Test
+ public void sampleTest() {
+ BaseUser user = new BaseUser("Bob");
+ Authentication auth = user.getAuthentication();
+ assertTrue(auth.checkPassword("Bob", "password"));
+ }
+}
\ No newline at end of file
From d7184227af0430bfbd4fe09f4b6c9cd0b58eddf7 Mon Sep 17 00:00:00 2001
From: Dylan Siew <88567790+dylansiew@users.noreply.github.com>
Date: Fri, 15 Mar 2024 21:59:10 +0800
Subject: [PATCH 028/208] Update build.gradle
---
build.gradle | 7 -------
1 file changed, 7 deletions(-)
diff --git a/build.gradle b/build.gradle
index b699c5a6c7..935e8e335a 100644
--- a/build.gradle
+++ b/build.gradle
@@ -44,11 +44,4 @@ checkstyle {
run{
standardInput = System.in
}
-dependencies {
- testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.10.0'
- testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.10.0'
-}
-test {
- useJUnitPlatform()
-}
From 853d2889f30f4748f45f4d9ebc3ee571e79e521c Mon Sep 17 00:00:00 2001
From: dylansiew <88567790+dylansiew@users.noreply.github.com>
Date: Fri, 15 Mar 2024 22:09:44 +0800
Subject: [PATCH 029/208] bug: wrong test format
---
build.gradle | 9 ++-------
src/main/java/parser/Parser.java | 2 +-
src/test/java/seedu/FinTrack/FinTrackTest.java | 12 ------------
src/test/java/user/BaseUserTest.java | 2 +-
4 files changed, 4 insertions(+), 21 deletions(-)
delete mode 100644 src/test/java/seedu/FinTrack/FinTrackTest.java
diff --git a/build.gradle b/build.gradle
index b699c5a6c7..c9098d4f82 100644
--- a/build.gradle
+++ b/build.gradle
@@ -14,6 +14,7 @@ dependencies {
testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.10.0'
}
+
test {
useJUnitPlatform()
@@ -44,11 +45,5 @@ checkstyle {
run{
standardInput = System.in
}
-dependencies {
- testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.10.0'
- testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.10.0'
-}
-test {
- useJUnitPlatform()
-}
+
diff --git a/src/main/java/parser/Parser.java b/src/main/java/parser/Parser.java
index 4de3c7e849..d2b808c607 100644
--- a/src/main/java/parser/Parser.java
+++ b/src/main/java/parser/Parser.java
@@ -4,11 +4,11 @@
import financialtransactions.TransactionManager;
public class Parser {
+ protected static boolean isContinue = true;
UI ui;
public Parser(UI ui) {
this.ui = ui;
}
- protected static boolean isContinue = true;
public static void parseCommand(String command, TransactionManager manager) {
String[] commandParts = command.split(" ");
diff --git a/src/test/java/seedu/FinTrack/FinTrackTest.java b/src/test/java/seedu/FinTrack/FinTrackTest.java
deleted file mode 100644
index f0349ac6d4..0000000000
--- a/src/test/java/seedu/FinTrack/FinTrackTest.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package seedu.FinTrack;
-
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-import org.junit.jupiter.api.Test;
-
-public class FinTrackTest {
- @Test
- public void sampleTest() {
- assertTrue(true);
- }
-}
\ No newline at end of file
diff --git a/src/test/java/user/BaseUserTest.java b/src/test/java/user/BaseUserTest.java
index 2eb415e3ae..5f20888351 100644
--- a/src/test/java/user/BaseUserTest.java
+++ b/src/test/java/user/BaseUserTest.java
@@ -11,4 +11,4 @@ public void sampleTest() {
Authentication auth = user.getAuthentication();
assertTrue(auth.checkPassword("Bob", "password"));
}
-}
\ No newline at end of file
+}
From ea453d2152f0c36a5a7e18d8f0ab4c41409ea80b Mon Sep 17 00:00:00 2001
From: Dylan Siew <88567790+dylansiew@users.noreply.github.com>
Date: Fri, 15 Mar 2024 22:18:16 +0800
Subject: [PATCH 030/208] removal of buggy code
---
src/main/java/parser/Parser.java | 1 -
1 file changed, 1 deletion(-)
diff --git a/src/main/java/parser/Parser.java b/src/main/java/parser/Parser.java
index f603c54ef9..4aa5cf17bb 100644
--- a/src/main/java/parser/Parser.java
+++ b/src/main/java/parser/Parser.java
@@ -8,7 +8,6 @@
import user.BaseUser;
public class Parser {
- protected static boolean isContinue = true;
public boolean isContinue;
UI ui;
From 7ca326ce312486e05d22b64217f99c23bb90fa3c Mon Sep 17 00:00:00 2001
From: Dylan Siew <88567790+dylansiew@users.noreply.github.com>
Date: Fri, 15 Mar 2024 22:22:27 +0800
Subject: [PATCH 031/208] fixing of buggy code
---
src/main/java/financeproject/Main.java | 2 +-
src/main/java/parser/Parser.java | 4 ++++
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/src/main/java/financeproject/Main.java b/src/main/java/financeproject/Main.java
index beff48015c..4398c3eb30 100644
--- a/src/main/java/financeproject/Main.java
+++ b/src/main/java/financeproject/Main.java
@@ -18,7 +18,7 @@ public static void main(String[] args) {
TransactionManager manager = new TransactionManager();
Parser parser = new Parser();
- while (parser.isContinue) {
+ while (parser.getIsContinue()) {
String command = ui.readInput();
parser.parseCommand(command, manager);
storage.saveFile(manager);
diff --git a/src/main/java/parser/Parser.java b/src/main/java/parser/Parser.java
index 4aa5cf17bb..7bb861c4b6 100644
--- a/src/main/java/parser/Parser.java
+++ b/src/main/java/parser/Parser.java
@@ -68,5 +68,9 @@ public String parseCommand(String command, TransactionManager manager) {
}
return null;
}
+
+ public boolean getIsContinue(){
+ return this.isContinue;
+ }
}
From 231194d9c5cf177876f5d1fd76aca51cf2e9fb3b Mon Sep 17 00:00:00 2001
From: dylansiew <88567790+dylansiew@users.noreply.github.com>
Date: Fri, 15 Mar 2024 22:27:06 +0800
Subject: [PATCH 032/208] fixing buggy merges
---
src/test/java/financialtransactions/OutflowTest.java | 4 ++--
src/test/java/parser/ParserTest.java | 10 ++++++----
2 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/src/test/java/financialtransactions/OutflowTest.java b/src/test/java/financialtransactions/OutflowTest.java
index 777723b089..f100a80573 100644
--- a/src/test/java/financialtransactions/OutflowTest.java
+++ b/src/test/java/financialtransactions/OutflowTest.java
@@ -1,8 +1,8 @@
package financialtransactions;
-import org.testng.annotations.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
public class OutflowTest {
@Test
diff --git a/src/test/java/parser/ParserTest.java b/src/test/java/parser/ParserTest.java
index 94593ae0d2..cca60856c9 100644
--- a/src/test/java/parser/ParserTest.java
+++ b/src/test/java/parser/ParserTest.java
@@ -10,13 +10,15 @@ public class ParserTest {
@Test
public void addInflow_success() {
- assertEquals("Ok. Added inflow", new Parser().parseCommand("add-inflow Salary 5000 14/03/2024 1700", manager));
- assertEquals("Ok. Added inflow", new Parser().parseCommand("add-inflow Investment 600 03/03/2024 1900", manager));
+ Parser test1 = new Parser();
+ assertEquals("Ok. Added inflow", test1.parseCommand("add-inflow Salary 5000 14/03/2024 1700", manager));
+ assertEquals("Ok. Added inflow", test1.parseCommand("add-inflow Investment 600 03/03/2024 1900", manager));
}
public void addOutflow_success() {
- assertEquals("Ok. Added outflow", new Parser().parseCommand("add-outflow Rent 1000 18/02/2024 1100", manager));
- assertEquals("Ok. Added outflow", new Parser().parseCommand("add-outflow Shopping 150 30/01/2024 1430", manager));
+ Parser test1 = new Parser();
+ assertEquals("Ok. Added outflow", test1.parseCommand("add-outflow Rent 1000 18/02/2024 1100", manager));
+ assertEquals("Ok. Added outflow", test1.parseCommand("add-outflow Shopping 150 30/01/2024 1430", manager));
}
}
From df554723449248fb2396d98f53ef49df15a323eb Mon Sep 17 00:00:00 2001
From: Dylan Siew <88567790+dylansiew@users.noreply.github.com>
Date: Fri, 15 Mar 2024 22:37:23 +0800
Subject: [PATCH 033/208] fixing errors in merges
---
text-ui-test/EXPECTED.TXT | 11 +++--------
text-ui-test/input.txt | 3 ++-
2 files changed, 5 insertions(+), 9 deletions(-)
diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT
index ac391e0738..da2eb940bb 100644
--- a/text-ui-test/EXPECTED.TXT
+++ b/text-ui-test/EXPECTED.TXT
@@ -1,8 +1,3 @@
-Enter password:
-Password is correct
-Inflows:
-Transactions:
-
-Outflows:
-Transactions:
-
+Welcome. Inorder to login, type your command in the format:
+login u/USERNAME p/PASSWORD
+Password is correct. You are now logged in
diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt
index 7aa311adf9..d2c95985b2 100644
--- a/text-ui-test/input.txt
+++ b/text-ui-test/input.txt
@@ -1 +1,2 @@
-password
\ No newline at end of file
+login Bob password
+quit
\ No newline at end of file
From 4682a0833dac096a75a78c9d52c3a33dd3f1ca40 Mon Sep 17 00:00:00 2001
From: dylansiew <88567790+dylansiew@users.noreply.github.com>
Date: Fri, 15 Mar 2024 22:48:30 +0800
Subject: [PATCH 034/208] fixing buggy merges
---
compile.sh | 4 ++--
data/data.txt | 7 ++-----
text-ui-test/EXPECTED.TXT | 14 ++++++--------
text-ui-test/input.txt | 3 ++-
4 files changed, 12 insertions(+), 16 deletions(-)
diff --git a/compile.sh b/compile.sh
index 63cebacae2..9cbc1bc6b4 100755
--- a/compile.sh
+++ b/compile.sh
@@ -5,11 +5,11 @@ SRC_DIR="src"
BUILD_DIR="build"
CLASSES_DIR="$BUILD_DIR/classes"
LIBS_DIR="$BUILD_DIR/libs"
-JAR_NAME="project.jar"
+JAR_NAME="Financer.jar"
# Compile the Java files
-find "$SRC_DIR" -name "*.java" > sources.txt
+find "$SRC_DIR" -name "*.java" ! -path "*/test/*" > sources.txt
javac -d "$CLASSES_DIR" @sources.txt
rm sources.txt
diff --git a/data/data.txt b/data/data.txt
index ff82bdbf2d..9d8e78d1b2 100644
--- a/data/data.txt
+++ b/data/data.txt
@@ -1,5 +1,2 @@
-Salary payment|400.00|May 23 2022 07:00PM|INCOME
-Investment|500.00|May 23 2022 07:00PM|INVESTMENT
-Loan payment|400.00|May 23 2022 07:00PM|LOAN
-Rent|-50000.00|May 23 2022 07:00PM|RENT
-Shopping|-200.00|May 23 2022 08:00PM|SHOPPING
+Salary|400.00|May 23 2022 07:00PM|null
+Bills|-300.00|May 23 2022 07:05PM|null
diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT
index ac391e0738..7f603812e3 100644
--- a/text-ui-test/EXPECTED.TXT
+++ b/text-ui-test/EXPECTED.TXT
@@ -1,8 +1,6 @@
-Enter password:
-Password is correct
-Inflows:
-Transactions:
-
-Outflows:
-Transactions:
-
+Welcome. Inorder to login, type your command in the format:
+login u/USERNAME p/PASSWORD
+Password is correct. You are now logged in
+Unable to save tasks!
+Ok. Added inflow
+Unable to save tasks!
diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt
index 7aa311adf9..c1391d5ba1 100644
--- a/text-ui-test/input.txt
+++ b/text-ui-test/input.txt
@@ -1 +1,2 @@
-password
\ No newline at end of file
+login Bob password
+add-inflow Salary 400.00 23/05/2022 1900
\ No newline at end of file
From 28deaaacd5e94aacc7ecffbcc18a0e69da0dde78 Mon Sep 17 00:00:00 2001
From: ChongXern
Date: Fri, 15 Mar 2024 23:25:43 +0800
Subject: [PATCH 035/208] Move outflow junit test to test directory package
---
.../java/financialtransactions/Transaction.java | 2 +-
.../financialtransactions/TransactionList.java | 14 +++++++-------
src/test/java/seedu/OutflowTest.java | 14 ++++++++++++++
3 files changed, 22 insertions(+), 8 deletions(-)
create mode 100644 src/test/java/seedu/OutflowTest.java
diff --git a/src/main/java/financialtransactions/Transaction.java b/src/main/java/financialtransactions/Transaction.java
index 469d54b1b2..43c2f48a16 100644
--- a/src/main/java/financialtransactions/Transaction.java
+++ b/src/main/java/financialtransactions/Transaction.java
@@ -29,7 +29,7 @@ public double getAmount() {
return amount;
}
- protected T getCategory() {
+ public T getCategory() {
return category;
}
diff --git a/src/main/java/financialtransactions/TransactionList.java b/src/main/java/financialtransactions/TransactionList.java
index 936511fcce..305ed66409 100644
--- a/src/main/java/financialtransactions/TransactionList.java
+++ b/src/main/java/financialtransactions/TransactionList.java
@@ -39,13 +39,13 @@ public double getBalance(){
}
@Override
public String toString(){
- String baseString = "Transactions: \n";
- Integer index = 1;
+ StringBuilder baseString = new StringBuilder("Transactions: \n");
+ int index = 1;
for(T transaction : transactionList){
- baseString += String.format("%d) %s\n", index, transaction.toString());
+ baseString.append(String.format("%d) %s\n", index, transaction.toString()));
index += 1;
}
- return baseString;
+ return baseString.toString();
}
public String lastNTransactions(int n) {
@@ -61,11 +61,11 @@ public String lastNTransactions(int n) {
}
public String toSave() {
- String baseString = "";
+ StringBuilder baseString = new StringBuilder();
for (T transaction : transactionList) {
- baseString += transaction.toSave();
+ baseString.append(transaction.toSave());
}
- return baseString;
+ return baseString.toString();
}
public void addInflow(Inflow inflow) {
diff --git a/src/test/java/seedu/OutflowTest.java b/src/test/java/seedu/OutflowTest.java
new file mode 100644
index 0000000000..641cd78d5c
--- /dev/null
+++ b/src/test/java/seedu/OutflowTest.java
@@ -0,0 +1,14 @@
+package seedu;
+
+import financialtransactions.Outflow;
+import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class OutflowTest {
+ @Test
+ public void testSetCategory() {
+ Outflow outflow = new Outflow("2024 Sem 2 School Fees", 999999.99, "2024-02-01");
+ outflow.setCategory(Outflow.Category.EDUCATION);
+ assertEquals(Outflow.Category.EDUCATION, outflow.getCategory());
+ }
+}
From 3fd72b01849d4c78e11459abf6918ad7ba095541 Mon Sep 17 00:00:00 2001
From: ChongXern
Date: Fri, 15 Mar 2024 23:36:49 +0800
Subject: [PATCH 036/208] Add inflow junit test
---
.../java/financialtransactions/InflowTest.java | 14 ++++++++++++++
1 file changed, 14 insertions(+)
create mode 100644 src/test/java/financialtransactions/InflowTest.java
diff --git a/src/test/java/financialtransactions/InflowTest.java b/src/test/java/financialtransactions/InflowTest.java
new file mode 100644
index 0000000000..6e49730a09
--- /dev/null
+++ b/src/test/java/financialtransactions/InflowTest.java
@@ -0,0 +1,14 @@
+package financialtransactions;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class InflowTest {
+ @Test
+ public void testSetCategory() {
+ Inflow inflow = new Inflow("February salary", 20.00, "2024-03-02");
+ inflow.setCategory(Inflow.Category.INCOME);
+ assertEquals(Inflow.Category.INCOME, inflow.getCategory());
+ }
+}
From 55c6e21ce6c4660f1dd034bb692a00daa65d48d7 Mon Sep 17 00:00:00 2001
From: ChongXern
Date: Fri, 15 Mar 2024 23:48:28 +0800
Subject: [PATCH 037/208] Add protected print method to show user which index
to select when deleting transaction
---
.../java/financialtransactions/TransactionList.java | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/src/main/java/financialtransactions/TransactionList.java b/src/main/java/financialtransactions/TransactionList.java
index 46777a9f49..6f0ac21519 100644
--- a/src/main/java/financialtransactions/TransactionList.java
+++ b/src/main/java/financialtransactions/TransactionList.java
@@ -26,7 +26,8 @@ public boolean addTransaction(T newTransaction){
}
- public Boolean removeTransactionIndex (int index){
+ public boolean removeTransactionIndex (int index){
+ printTransactionsSafeInfo();
if (index >= transactionList.size() || index < 0){
System.out.println("Invalid Index");
return false;
@@ -62,8 +63,11 @@ public String toSave() {
return baseString.toString();
}
- public void addInflow(Inflow inflow) {
- transactionList.add((T) inflow);
+ protected void printTransactionsSafeInfo() {
+ int index = 1;
+ for (T transaction : transactionList) {
+ System.out.print(index++);
+ System.out.println(" " + transaction.getName() + " " + transaction.getCategory());
+ }
}
-
}
From 257d3893de78548acc3adfc23142869b386b23a8 Mon Sep 17 00:00:00 2001
From: chowy
Date: Fri, 15 Mar 2024 23:59:19 +0800
Subject: [PATCH 038/208] Added junit test for toSave
---
.../TransactionManagerTest.java | 23 +++++++++++++++++++
1 file changed, 23 insertions(+)
create mode 100644 src/test/java/financialtransactions/TransactionManagerTest.java
diff --git a/src/test/java/financialtransactions/TransactionManagerTest.java b/src/test/java/financialtransactions/TransactionManagerTest.java
new file mode 100644
index 0000000000..e82b58baef
--- /dev/null
+++ b/src/test/java/financialtransactions/TransactionManagerTest.java
@@ -0,0 +1,23 @@
+package financialtransactions;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class TransactionManagerTest {
+ @Test
+ public void toSaveTest() {
+ TransactionManager managerTest = new TransactionManager();
+
+ Inflow income = new Inflow("Salary payment", 400.00, "23/05/2022 1900");
+ income.setCategory(Inflow.Category.INCOME);
+ managerTest.addTransaction(income);
+
+ Outflow shopping = new Outflow("Shopping", 200, "23/05/2022 2000");
+ shopping.setCategory(Outflow.Category.SHOPPING);
+ managerTest.addTransaction(shopping);
+
+ assertEquals("Salary payment|400.00|May 23 2022 07:00PM|INCOME\n" +
+ "Shopping|-200.00|May 23 2022 08:00PM|SHOPPING\n", managerTest.toSave());
+ }
+}
From 163a5f9c521b7773a89ac1b0e0e0262a398824e5 Mon Sep 17 00:00:00 2001
From: ChongXern
Date: Sun, 17 Mar 2024 13:12:52 +0800
Subject: [PATCH 039/208] Add transaction type attribute and methods
---
data/data.txt | 2 --
src/main/java/financeproject/Main.java | 2 +-
.../java/financialtransactions/Inflow.java | 1 +
.../java/financialtransactions/Outflow.java | 1 +
.../financialtransactions/Transaction.java | 18 +++++++++++-------
.../financialtransactions/TransactionList.java | 1 -
.../TransactionManager.java | 9 ++++++---
src/main/java/parser/Parser.java | 1 +
8 files changed, 21 insertions(+), 14 deletions(-)
diff --git a/data/data.txt b/data/data.txt
index 9d8e78d1b2..e69de29bb2 100644
--- a/data/data.txt
+++ b/data/data.txt
@@ -1,2 +0,0 @@
-Salary|400.00|May 23 2022 07:00PM|null
-Bills|-300.00|May 23 2022 07:05PM|null
diff --git a/src/main/java/financeproject/Main.java b/src/main/java/financeproject/Main.java
index 4398c3eb30..50c641ac3f 100644
--- a/src/main/java/financeproject/Main.java
+++ b/src/main/java/financeproject/Main.java
@@ -13,7 +13,7 @@ public class Main {
public static void main(String[] args) {
Storage storage = new Storage("./data");
UI ui = new UI();
- ui.printMessage("Welcome. Inorder to login, type your command in the format:\nlogin u/USERNAME p/PASSWORD");
+ ui.printMessage("Welcome. In order to login, type your command in the format:\nlogin u/USERNAME p/PASSWORD");
//TransactionManager manager = storage.loadFile();
TransactionManager manager = new TransactionManager();
diff --git a/src/main/java/financialtransactions/Inflow.java b/src/main/java/financialtransactions/Inflow.java
index 28480e8527..d7d361a9eb 100644
--- a/src/main/java/financialtransactions/Inflow.java
+++ b/src/main/java/financialtransactions/Inflow.java
@@ -6,6 +6,7 @@ public enum Category {
}
public Inflow(String name, double amount, String date) {
super(name, amount, date);
+ super.transactionType = "I";
}
public void setCategory(Category category) {
super.category = category;
diff --git a/src/main/java/financialtransactions/Outflow.java b/src/main/java/financialtransactions/Outflow.java
index 6c428c5731..22fa2b6b53 100644
--- a/src/main/java/financialtransactions/Outflow.java
+++ b/src/main/java/financialtransactions/Outflow.java
@@ -7,6 +7,7 @@ public enum Category {
public Outflow(String name, double amount, String date) {
super(name, -1.00 * amount, date);
+ super.transactionType = "O";
}
public void setCategory(Category category) {
diff --git a/src/main/java/financialtransactions/Transaction.java b/src/main/java/financialtransactions/Transaction.java
index 43c2f48a16..284a5d0e17 100644
--- a/src/main/java/financialtransactions/Transaction.java
+++ b/src/main/java/financialtransactions/Transaction.java
@@ -1,20 +1,22 @@
package financialtransactions;
+import template.BaseDate;
+
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
-import template.BaseDate;
public abstract class Transaction {
protected String name;
protected double amount;
protected BaseDate date;
protected T category;
+ protected String transactionType; // Indicates type of task, either "O" for outflow or "I" for inflow
public Transaction(String name, double amount, String date) {
this.name = name;
this.amount = amount;
- if(date == null){
+ if (date == null){
this.date = new BaseDate(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")));
} else{
this.date = new BaseDate(date);
@@ -29,6 +31,10 @@ public double getAmount() {
return amount;
}
+ public String getTransactionType() {
+ return this.transactionType;
+ }
+
public T getCategory() {
return category;
}
@@ -37,12 +43,10 @@ public T getCategory() {
@Override
public String toString() {
- String baseString = String.format("Name: %s, Amount: %.2f, Date: %s", name, amount, date.toString());
- return baseString;
+ return String.format("Name: %s, Amount: %.2f, Date: %s", name, amount, date.toString());
}
-
+
public String toSave() {
- String baseString = String.format("%s|%.2f|%s|%s\n", name, amount, date.toString(), category);
- return baseString;
+ return String.format("%s|%.2f|%s|%s\n", name, amount, date.toString(), category);
}
}
diff --git a/src/main/java/financialtransactions/TransactionList.java b/src/main/java/financialtransactions/TransactionList.java
index 6f0ac21519..e7b6b8750b 100644
--- a/src/main/java/financialtransactions/TransactionList.java
+++ b/src/main/java/financialtransactions/TransactionList.java
@@ -25,7 +25,6 @@ public boolean addTransaction(T newTransaction){
return false;
}
-
public boolean removeTransactionIndex (int index){
printTransactionsSafeInfo();
if (index >= transactionList.size() || index < 0){
diff --git a/src/main/java/financialtransactions/TransactionManager.java b/src/main/java/financialtransactions/TransactionManager.java
index 72cdfd6270..5167c54d0d 100644
--- a/src/main/java/financialtransactions/TransactionManager.java
+++ b/src/main/java/financialtransactions/TransactionManager.java
@@ -22,16 +22,19 @@ public boolean addTransaction(Transaction> transaction) {
return outflows.addTransaction(outflow);
}
System.out.println("Invalid transaction type.");
- return false;
}
public boolean removeTransaction(int index, boolean isInflow) {
transactionList.removeTransactionIndex(index);
- if (isInflow) {
+ Transaction> transactionRemoved = transactionList.getNthTransaction(index);
+ String transactionType = transactionRemoved.getTransactionType();
+ if (transactionType.equals("I")) {
return inflows.removeTransactionIndex(index);
- } else {
+ }
+ if (transactionType.equals("O")){
return outflows.removeTransactionIndex(index);
}
+ return false;
}
public double getTotalBalance() {
diff --git a/src/main/java/parser/Parser.java b/src/main/java/parser/Parser.java
index 7bb861c4b6..b309f1ac5f 100644
--- a/src/main/java/parser/Parser.java
+++ b/src/main/java/parser/Parser.java
@@ -50,6 +50,7 @@ public String parseCommand(String command, TransactionManager manager) {
ui.printMessage("Ok. Added outflow");
return "Ok. Added outflow";
case "delete-inflow":
+ String index = commandParts[1];
//manager.removeTransaction(1, true);
break;
case "delete-outflow":
From b3b7a131d8a092b79d420ae3cf7dc4e1d1bff8a9 Mon Sep 17 00:00:00 2001
From: ChongXern
Date: Sun, 17 Mar 2024 13:31:37 +0800
Subject: [PATCH 040/208] Add exceptions classes
---
.../InactivityTimeoutException.java | 4 ++++
.../IncompletePromptException.java | 4 ++++
.../java/customexceptions/SecurityException.java | 4 ++++
src/main/java/customexceptions/TypoException.java | 4 ++++
src/main/java/financeproject/Main.java | 3 ++-
.../financialtransactions/TransactionManager.java | 3 +++
src/main/java/parser/Parser.java | 15 ++++++++++++++-
src/test/java/parser/ParserTest.java | 5 +++--
8 files changed, 38 insertions(+), 4 deletions(-)
create mode 100644 src/main/java/customexceptions/InactivityTimeoutException.java
create mode 100644 src/main/java/customexceptions/IncompletePromptException.java
create mode 100644 src/main/java/customexceptions/SecurityException.java
create mode 100644 src/main/java/customexceptions/TypoException.java
diff --git a/src/main/java/customexceptions/InactivityTimeoutException.java b/src/main/java/customexceptions/InactivityTimeoutException.java
new file mode 100644
index 0000000000..a4b4c89c2d
--- /dev/null
+++ b/src/main/java/customexceptions/InactivityTimeoutException.java
@@ -0,0 +1,4 @@
+package customexceptions;
+
+public class InactivityTimeoutException extends Exception {
+}
diff --git a/src/main/java/customexceptions/IncompletePromptException.java b/src/main/java/customexceptions/IncompletePromptException.java
new file mode 100644
index 0000000000..129f528bd0
--- /dev/null
+++ b/src/main/java/customexceptions/IncompletePromptException.java
@@ -0,0 +1,4 @@
+package customexceptions;
+
+public class IncompletePromptException extends Exception {
+}
diff --git a/src/main/java/customexceptions/SecurityException.java b/src/main/java/customexceptions/SecurityException.java
new file mode 100644
index 0000000000..17be091a0d
--- /dev/null
+++ b/src/main/java/customexceptions/SecurityException.java
@@ -0,0 +1,4 @@
+package customexceptions;
+
+public class SecurityException extends Exception {
+}
diff --git a/src/main/java/customexceptions/TypoException.java b/src/main/java/customexceptions/TypoException.java
new file mode 100644
index 0000000000..758629aa4c
--- /dev/null
+++ b/src/main/java/customexceptions/TypoException.java
@@ -0,0 +1,4 @@
+package customexceptions;
+
+public class TypoException extends Exception {
+}
diff --git a/src/main/java/financeproject/Main.java b/src/main/java/financeproject/Main.java
index 4398c3eb30..d09e6a2d42 100644
--- a/src/main/java/financeproject/Main.java
+++ b/src/main/java/financeproject/Main.java
@@ -2,6 +2,7 @@
//import financialtransactions.Inflow;
//import financialtransactions.Outflow;
+import customexceptions.IncompletePromptException;
import financialtransactions.TransactionManager;
import parser.Parser;
import storage.Storage;
@@ -10,7 +11,7 @@
import userinteraction.UI;
public class Main {
- public static void main(String[] args) {
+ public static void main(String[] args) throws IncompletePromptException {
Storage storage = new Storage("./data");
UI ui = new UI();
ui.printMessage("Welcome. Inorder to login, type your command in the format:\nlogin u/USERNAME p/PASSWORD");
diff --git a/src/main/java/financialtransactions/TransactionManager.java b/src/main/java/financialtransactions/TransactionManager.java
index 72cdfd6270..47710da58d 100644
--- a/src/main/java/financialtransactions/TransactionManager.java
+++ b/src/main/java/financialtransactions/TransactionManager.java
@@ -1,7 +1,10 @@
package financialtransactions;
+import java.util.ArrayList;
public class TransactionManager {
+ private static final String[] INSTRUCTIONS = {"add-inflow", "add-outflow", "delete-inflow",
+ "delete-outflow", "export-csv", "login", "quit", "view-history"};
private TransactionList> transactionList;
private TransactionList inflows;
private TransactionList outflows;
diff --git a/src/main/java/parser/Parser.java b/src/main/java/parser/Parser.java
index 7bb861c4b6..8a64f8ec04 100644
--- a/src/main/java/parser/Parser.java
+++ b/src/main/java/parser/Parser.java
@@ -1,5 +1,6 @@
package parser;
+import customexceptions.IncompletePromptException;
import financialtransactions.Inflow;
import financialtransactions.Outflow;
import userinteraction.UI;
@@ -16,7 +17,7 @@ public Parser() {
this.ui = new UI();
}
- public String parseCommand(String command, TransactionManager manager) {
+ public String parseCommand(String command, TransactionManager manager) throws IncompletePromptException {
String[] commandParts = command.split(" ");
String action = commandParts[0];
@@ -32,6 +33,9 @@ public String parseCommand(String command, TransactionManager manager) {
}
break;
case "add-inflow":
+ if (commandParts.length != 5) {
+ throw new IncompletePromptException();
+ }
String inflowName = commandParts[1];
double inflowAmount = Double.parseDouble(commandParts[2]);
String inflowDate = commandParts[3] + " " + commandParts[4];
@@ -41,6 +45,9 @@ public String parseCommand(String command, TransactionManager manager) {
ui.printMessage("Ok. Added inflow");
return "Ok. Added inflow";
case "add-outflow":
+ if (commandParts.length != 5) {
+ throw new IncompletePromptException();
+ }
String outflowName = commandParts[1];
double outflowAmount = Double.parseDouble(commandParts[2]);
String outflowDate = commandParts[3] + " " + commandParts[4];
@@ -50,9 +57,15 @@ public String parseCommand(String command, TransactionManager manager) {
ui.printMessage("Ok. Added outflow");
return "Ok. Added outflow";
case "delete-inflow":
+ if (commandParts.length != 2) {
+ throw new IncompletePromptException();
+ }
//manager.removeTransaction(1, true);
break;
case "delete-outflow":
+ if (commandParts.length != 2) {
+ throw new IncompletePromptException();
+ }
//manager.removeTransaction(1, false);
break;
case "view-history":
diff --git a/src/test/java/parser/ParserTest.java b/src/test/java/parser/ParserTest.java
index cca60856c9..0150b15731 100644
--- a/src/test/java/parser/ParserTest.java
+++ b/src/test/java/parser/ParserTest.java
@@ -1,5 +1,6 @@
package parser;
+import customexceptions.IncompletePromptException;
import financialtransactions.TransactionManager;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -9,13 +10,13 @@ public class ParserTest {
TransactionManager manager = new TransactionManager();
@Test
- public void addInflow_success() {
+ public void addInflow_success() throws IncompletePromptException {
Parser test1 = new Parser();
assertEquals("Ok. Added inflow", test1.parseCommand("add-inflow Salary 5000 14/03/2024 1700", manager));
assertEquals("Ok. Added inflow", test1.parseCommand("add-inflow Investment 600 03/03/2024 1900", manager));
}
- public void addOutflow_success() {
+ public void addOutflow_success() throws IncompletePromptException {
Parser test1 = new Parser();
assertEquals("Ok. Added outflow", test1.parseCommand("add-outflow Rent 1000 18/02/2024 1100", manager));
assertEquals("Ok. Added outflow", test1.parseCommand("add-outflow Shopping 150 30/01/2024 1430", manager));
From 36467d1b75c7feec49d991e728c21c2e718ef263 Mon Sep 17 00:00:00 2001
From: Chong Xern <104547209+ChongXern@users.noreply.github.com>
Date: Mon, 18 Mar 2024 13:59:05 +0800
Subject: [PATCH 041/208] Change params in remove transaction method
---
.../java/financialtransactions/TransactionManager.java | 3 ++-
src/main/java/parser/Parser.java | 7 ++++---
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/src/main/java/financialtransactions/TransactionManager.java b/src/main/java/financialtransactions/TransactionManager.java
index 5167c54d0d..4c7f7587bb 100644
--- a/src/main/java/financialtransactions/TransactionManager.java
+++ b/src/main/java/financialtransactions/TransactionManager.java
@@ -22,9 +22,10 @@ public boolean addTransaction(Transaction> transaction) {
return outflows.addTransaction(outflow);
}
System.out.println("Invalid transaction type.");
+ return false;
}
- public boolean removeTransaction(int index, boolean isInflow) {
+ public boolean removeTransaction(int index) {
transactionList.removeTransactionIndex(index);
Transaction> transactionRemoved = transactionList.getNthTransaction(index);
String transactionType = transactionRemoved.getTransactionType();
diff --git a/src/main/java/parser/Parser.java b/src/main/java/parser/Parser.java
index b309f1ac5f..122a5fa40e 100644
--- a/src/main/java/parser/Parser.java
+++ b/src/main/java/parser/Parser.java
@@ -19,7 +19,7 @@ public Parser() {
public String parseCommand(String command, TransactionManager manager) {
String[] commandParts = command.split(" ");
String action = commandParts[0];
-
+
switch (action) {
case "login":
BaseUser user = new BaseUser(commandParts[1]);
@@ -50,10 +50,11 @@ public String parseCommand(String command, TransactionManager manager) {
ui.printMessage("Ok. Added outflow");
return "Ok. Added outflow";
case "delete-inflow":
+ case "delete-outflow":
String index = commandParts[1];
+ manager.removeTransaction(Integer.parseInt(index));
//manager.removeTransaction(1, true);
- break;
- case "delete-outflow":
+ //break;
//manager.removeTransaction(1, false);
break;
case "view-history":
From 6b60cde0ea0868194b12ff95b54808091eae8d30 Mon Sep 17 00:00:00 2001
From: Kishen271828
Date: Mon, 18 Mar 2024 21:22:06 +0800
Subject: [PATCH 042/208] Modify parser to comply with input format in UG
---
src/main/java/parser/Parser.java | 61 ++++++++++++++++++++++------
src/test/java/parser/ParserTest.java | 8 ++--
2 files changed, 53 insertions(+), 16 deletions(-)
diff --git a/src/main/java/parser/Parser.java b/src/main/java/parser/Parser.java
index 7bb861c4b6..2fef3207d5 100644
--- a/src/main/java/parser/Parser.java
+++ b/src/main/java/parser/Parser.java
@@ -17,13 +17,22 @@ public Parser() {
}
public String parseCommand(String command, TransactionManager manager) {
- String[] commandParts = command.split(" ");
+ String[] commandParts = command.split("\\s+");
String action = commandParts[0];
switch (action) {
case "login":
- BaseUser user = new BaseUser(commandParts[1]);
- String password = commandParts[2];
+ String username = "";
+ String password = null;
+ for (String part : commandParts) {
+ if (part.startsWith("u/")) {
+ username = part.substring(2);
+ } else if (part.startsWith("p/")) {
+ password = part.substring(2);
+ }
+ }
+
+ BaseUser user = new BaseUser(username);
Authentication auth = user.getAuthentication();
if (auth.checkPassword(user.getName(), password)) {
ui.printMessage("Password is correct. You are now logged in");
@@ -32,20 +41,48 @@ public String parseCommand(String command, TransactionManager manager) {
}
break;
case "add-inflow":
- String inflowName = commandParts[1];
- double inflowAmount = Double.parseDouble(commandParts[2]);
- String inflowDate = commandParts[3] + " " + commandParts[4];
+ String inflowName = null;
+ double inflowAmount = 0;
+ String inflowDate = null;
+ String inflowTime = null;
+
+ for (String part : commandParts) {
+ if (part.startsWith("n/")) {
+ inflowName = part.substring(2);
+ } else if (part.startsWith("a/")) {
+ inflowAmount = Double.parseDouble(part.substring(2));
+ } else if (part.startsWith("d/")) {
+ inflowDate = part.substring(2);
+ } else if (part.startsWith("t/")) {
+ inflowTime = part.substring(2);
+ }
+ }
+ String inflowDateTime = inflowDate + " " + inflowTime;
- Inflow inflow = new Inflow(inflowName, inflowAmount, inflowDate);
+ Inflow inflow = new Inflow(inflowName, inflowAmount, inflowDateTime);
manager.addTransaction(inflow);
ui.printMessage("Ok. Added inflow");
return "Ok. Added inflow";
case "add-outflow":
- String outflowName = commandParts[1];
- double outflowAmount = Double.parseDouble(commandParts[2]);
- String outflowDate = commandParts[3] + " " + commandParts[4];
+ String outflowName = null;
+ double outflowAmount = 0;
+ String outflowDate = null;
+ String outflowTime = null;
+
+ for (String part : commandParts) {
+ if (part.startsWith("n/")) {
+ outflowName = part.substring(2);
+ } else if (part.startsWith("a/")) {
+ outflowAmount = Double.parseDouble(part.substring(2));
+ } else if (part.startsWith("d/")) {
+ outflowDate = part.substring(2);
+ } else if (part.startsWith("t/")) {
+ outflowTime = part.substring(2);
+ }
+ }
+ String outflowDateTime = outflowDate + " " + outflowTime;
- Outflow outflow = new Outflow(outflowName, outflowAmount, outflowDate);
+ Outflow outflow = new Outflow(outflowName, outflowAmount, outflowDateTime);
manager.addTransaction(outflow);
ui.printMessage("Ok. Added outflow");
return "Ok. Added outflow";
@@ -56,7 +93,7 @@ public String parseCommand(String command, TransactionManager manager) {
//manager.removeTransaction(1, false);
break;
case "view-history":
- int numTransactions = Integer.parseInt(commandParts[1].trim());
+ int numTransactions = Integer.parseInt(commandParts[1].substring(2));
manager.showLastNTransactions(numTransactions);
break;
case "quit":
diff --git a/src/test/java/parser/ParserTest.java b/src/test/java/parser/ParserTest.java
index cca60856c9..4be3b16de9 100644
--- a/src/test/java/parser/ParserTest.java
+++ b/src/test/java/parser/ParserTest.java
@@ -11,14 +11,14 @@ public class ParserTest {
@Test
public void addInflow_success() {
Parser test1 = new Parser();
- assertEquals("Ok. Added inflow", test1.parseCommand("add-inflow Salary 5000 14/03/2024 1700", manager));
- assertEquals("Ok. Added inflow", test1.parseCommand("add-inflow Investment 600 03/03/2024 1900", manager));
+ assertEquals("Ok. Added inflow", test1.parseCommand("add-inflow n/Salary a/5000 d/14/03/2024 t/1700", manager));
+ assertEquals("Ok. Added inflow", test1.parseCommand("add-inflow n/Investment a/600 d/03/03/2024 t/1900", manager));
}
public void addOutflow_success() {
Parser test1 = new Parser();
- assertEquals("Ok. Added outflow", test1.parseCommand("add-outflow Rent 1000 18/02/2024 1100", manager));
- assertEquals("Ok. Added outflow", test1.parseCommand("add-outflow Shopping 150 30/01/2024 1430", manager));
+ assertEquals("Ok. Added outflow", test1.parseCommand("add-outflow n/Rent a/1000 d/18/02/2024 t/1100", manager));
+ assertEquals("Ok. Added outflow", test1.parseCommand("add-outflow n/Shopping a/150 d/30/01/2024 t/1430", manager));
}
}
From ebccd8edf610610fda9978da851cdaaedb6fa168 Mon Sep 17 00:00:00 2001
From: Kishen271828
Date: Mon, 18 Mar 2024 21:38:34 +0800
Subject: [PATCH 043/208] Wrap long lines in ParserTest class
---
src/test/java/parser/ParserTest.java | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/src/test/java/parser/ParserTest.java b/src/test/java/parser/ParserTest.java
index 4be3b16de9..c1b5ccaa5a 100644
--- a/src/test/java/parser/ParserTest.java
+++ b/src/test/java/parser/ParserTest.java
@@ -11,14 +11,18 @@ public class ParserTest {
@Test
public void addInflow_success() {
Parser test1 = new Parser();
- assertEquals("Ok. Added inflow", test1.parseCommand("add-inflow n/Salary a/5000 d/14/03/2024 t/1700", manager));
- assertEquals("Ok. Added inflow", test1.parseCommand("add-inflow n/Investment a/600 d/03/03/2024 t/1900", manager));
+ assertEquals("Ok. Added inflow",
+ test1.parseCommand("add-inflow n/Salary a/5000 d/14/03/2024 t/1700", manager));
+ assertEquals("Ok. Added inflow",
+ test1.parseCommand("add-inflow n/Investment a/600 d/03/03/2024 t/1900", manager));
}
public void addOutflow_success() {
Parser test1 = new Parser();
- assertEquals("Ok. Added outflow", test1.parseCommand("add-outflow n/Rent a/1000 d/18/02/2024 t/1100", manager));
- assertEquals("Ok. Added outflow", test1.parseCommand("add-outflow n/Shopping a/150 d/30/01/2024 t/1430", manager));
+ assertEquals("Ok. Added outflow",
+ test1.parseCommand("add-outflow n/Rent a/1000 d/18/02/2024 t/1100", manager));
+ assertEquals("Ok. Added outflow",
+ test1.parseCommand("add-outflow n/Shopping a/150 d/30/01/2024 t/1430", manager));
}
}
From 234cf8eb186bd243e4687f519779b9502713fa0d Mon Sep 17 00:00:00 2001
From: Kishen271828
Date: Mon, 18 Mar 2024 21:43:12 +0800
Subject: [PATCH 044/208] Modify input.txt
---
text-ui-test/input.txt | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt
index 43622c6200..de7a1069be 100644
--- a/text-ui-test/input.txt
+++ b/text-ui-test/input.txt
@@ -1,4 +1,4 @@
-login Bob password
-add-inflow Salary 400.00 23/05/2022 1900
-add-outflow Salary 400.00 23/05/2022 1900
+login u/Bob p/password
+add-inflow n/Salary a/400.00 d/23/05/2022 t/1900
+add-outflow n/Salary a/400.00 d/23/05/2022 t/1900
quit
From 3ecf46853b7b2d83aa9b4dd2341f3d66de2515c4 Mon Sep 17 00:00:00 2001
From: Kishen271828
Date: Tue, 19 Mar 2024 17:36:13 +0800
Subject: [PATCH 045/208] Update Parser format for view-history
---
src/main/java/financeproject/Main.java | 2 +-
.../TransactionManager.java | 3 +++
src/main/java/parser/Parser.java | 17 +++++++++++------
text-ui-test/EXPECTED.TXT | 2 +-
4 files changed, 16 insertions(+), 8 deletions(-)
diff --git a/src/main/java/financeproject/Main.java b/src/main/java/financeproject/Main.java
index 50c641ac3f..c741065540 100644
--- a/src/main/java/financeproject/Main.java
+++ b/src/main/java/financeproject/Main.java
@@ -18,7 +18,7 @@ public static void main(String[] args) {
TransactionManager manager = new TransactionManager();
Parser parser = new Parser();
- while (parser.getIsContinue()) {
+ while (parser.isContinue) {
String command = ui.readInput();
parser.parseCommand(command, manager);
storage.saveFile(manager);
diff --git a/src/main/java/financialtransactions/TransactionManager.java b/src/main/java/financialtransactions/TransactionManager.java
index 4c7f7587bb..5ce3b76ebf 100644
--- a/src/main/java/financialtransactions/TransactionManager.java
+++ b/src/main/java/financialtransactions/TransactionManager.java
@@ -51,6 +51,9 @@ public String toString() {
public void showLastNTransactions(int n) {
int listSize = transactionList.getTransactionListSize();
+ if (n > listSize) {
+ return;
+ }
int index = 1;
System.out.println("Inflows:\nTransactions:");
diff --git a/src/main/java/parser/Parser.java b/src/main/java/parser/Parser.java
index 7d79ed418b..319984fb25 100644
--- a/src/main/java/parser/Parser.java
+++ b/src/main/java/parser/Parser.java
@@ -95,11 +95,20 @@ public String parseCommand(String command, TransactionManager manager) {
//manager.removeTransaction(1, false);
break;
case "view-history":
- int numTransactions = Integer.parseInt(commandParts[1].substring(2));
+ String numTransactionsString = null;
+ for (String part : commandParts) {
+ if (part.startsWith("n/")) {
+ numTransactionsString = part.substring(2);
+ }
+ }
+ int numTransactions = 0;
+ if (numTransactionsString != null) {
+ numTransactions = Integer.parseInt(numTransactionsString);
+ }
manager.showLastNTransactions(numTransactions);
break;
case "quit":
- isContinue = false;
+ this.isContinue = false;
break;
default:
System.out.println("Invalid command");
@@ -107,9 +116,5 @@ public String parseCommand(String command, TransactionManager manager) {
}
return null;
}
-
- public boolean getIsContinue(){
- return this.isContinue;
- }
}
diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT
index 344033d263..fec57dd47f 100644
--- a/text-ui-test/EXPECTED.TXT
+++ b/text-ui-test/EXPECTED.TXT
@@ -1,4 +1,4 @@
-Welcome. Inorder to login, type your command in the format:
+Welcome. In order to login, type your command in the format:
login u/USERNAME p/PASSWORD
Password is correct. You are now logged in
Unable to save tasks!
From 98e4e304153aa69271691936023669b56c93bcd2 Mon Sep 17 00:00:00 2001
From: Kishen271828
Date: Tue, 19 Mar 2024 19:17:49 +0800
Subject: [PATCH 046/208] Add category input for parser; Storage working
---
src/main/java/financeproject/Main.java | 3 ++-
src/main/java/parser/Parser.java | 12 ++++++++----
text-ui-test/EXPECTED.TXT | 12 ++++++++----
text-ui-test/input.txt | 6 ++++--
4 files changed, 22 insertions(+), 11 deletions(-)
diff --git a/src/main/java/financeproject/Main.java b/src/main/java/financeproject/Main.java
index c741065540..497f614543 100644
--- a/src/main/java/financeproject/Main.java
+++ b/src/main/java/financeproject/Main.java
@@ -14,8 +14,9 @@ public static void main(String[] args) {
Storage storage = new Storage("./data");
UI ui = new UI();
ui.printMessage("Welcome. In order to login, type your command in the format:\nlogin u/USERNAME p/PASSWORD");
- //TransactionManager manager = storage.loadFile();
TransactionManager manager = new TransactionManager();
+ manager = storage.loadFile();
+
Parser parser = new Parser();
while (parser.isContinue) {
diff --git a/src/main/java/parser/Parser.java b/src/main/java/parser/Parser.java
index 319984fb25..5c7d7a217f 100644
--- a/src/main/java/parser/Parser.java
+++ b/src/main/java/parser/Parser.java
@@ -45,6 +45,7 @@ public String parseCommand(String command, TransactionManager manager) {
double inflowAmount = 0;
String inflowDate = null;
String inflowTime = null;
+ String inflowCategory = null;
for (String part : commandParts) {
if (part.startsWith("n/")) {
@@ -55,11 +56,13 @@ public String parseCommand(String command, TransactionManager manager) {
inflowDate = part.substring(2);
} else if (part.startsWith("t/")) {
inflowTime = part.substring(2);
+ } else if (part.startsWith("c/")) {
+ inflowCategory = part.substring(2);
}
}
String inflowDateTime = inflowDate + " " + inflowTime;
-
Inflow inflow = new Inflow(inflowName, inflowAmount, inflowDateTime);
+ inflow.setCategory(Inflow.Category.valueOf(inflowCategory.toUpperCase()));
manager.addTransaction(inflow);
ui.printMessage("Ok. Added inflow");
return "Ok. Added inflow";
@@ -68,6 +71,7 @@ public String parseCommand(String command, TransactionManager manager) {
double outflowAmount = 0;
String outflowDate = null;
String outflowTime = null;
+ String outflowCategory = null;
for (String part : commandParts) {
if (part.startsWith("n/")) {
@@ -78,11 +82,14 @@ public String parseCommand(String command, TransactionManager manager) {
outflowDate = part.substring(2);
} else if (part.startsWith("t/")) {
outflowTime = part.substring(2);
+ } else if (part.startsWith("c/")) {
+ outflowCategory = part.substring(2);
}
}
String outflowDateTime = outflowDate + " " + outflowTime;
Outflow outflow = new Outflow(outflowName, outflowAmount, outflowDateTime);
+ outflow.setCategory(Outflow.Category.valueOf(outflowCategory.toUpperCase()));
manager.addTransaction(outflow);
ui.printMessage("Ok. Added outflow");
return "Ok. Added outflow";
@@ -90,9 +97,6 @@ public String parseCommand(String command, TransactionManager manager) {
case "delete-outflow":
String index = commandParts[1];
manager.removeTransaction(Integer.parseInt(index));
- //manager.removeTransaction(1, true);
- //break;
- //manager.removeTransaction(1, false);
break;
case "view-history":
String numTransactionsString = null;
diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT
index fec57dd47f..a66a0248bf 100644
--- a/text-ui-test/EXPECTED.TXT
+++ b/text-ui-test/EXPECTED.TXT
@@ -1,9 +1,13 @@
Welcome. In order to login, type your command in the format:
login u/USERNAME p/PASSWORD
Password is correct. You are now logged in
-Unable to save tasks!
Ok. Added inflow
-Unable to save tasks!
Ok. Added outflow
-Unable to save tasks!
-Unable to save tasks!
+Ok. Added inflow
+Inflows:
+Transactions:
+1) Name: Stocks, Amount: 400.00, Date: Oct 24 2024 12:00PM
+
+Outflows:
+Transactions:
+1) Name: Rent, Amount: -1500.00, Date: Jun 23 2023 06:00PM
diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt
index de7a1069be..68b1978fc1 100644
--- a/text-ui-test/input.txt
+++ b/text-ui-test/input.txt
@@ -1,4 +1,6 @@
login u/Bob p/password
-add-inflow n/Salary a/400.00 d/23/05/2022 t/1900
-add-outflow n/Salary a/400.00 d/23/05/2022 t/1900
+add-inflow n/Salary a/400.00 d/23/05/2022 t/1900 c/income
+add-outflow n/Rent a/1500.00 d/23/06/2023 t/1800 c/rent
+add-inflow n/Stocks a/400.00 d/24/10/2024 t/1200 c/investment
+view-history n/2
quit
From 3633f2d912a1817060c3715097736caf8fff4477 Mon Sep 17 00:00:00 2001
From: Kishen271828
Date: Tue, 19 Mar 2024 19:24:02 +0800
Subject: [PATCH 047/208] Include category input for ParserTest
---
src/test/java/parser/ParserTest.java | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/test/java/parser/ParserTest.java b/src/test/java/parser/ParserTest.java
index c1b5ccaa5a..cde1e9ae3c 100644
--- a/src/test/java/parser/ParserTest.java
+++ b/src/test/java/parser/ParserTest.java
@@ -12,17 +12,17 @@ public class ParserTest {
public void addInflow_success() {
Parser test1 = new Parser();
assertEquals("Ok. Added inflow",
- test1.parseCommand("add-inflow n/Salary a/5000 d/14/03/2024 t/1700", manager));
+ test1.parseCommand("add-inflow n/Salary a/5000 d/14/03/2024 t/1700 c/income", manager));
assertEquals("Ok. Added inflow",
- test1.parseCommand("add-inflow n/Investment a/600 d/03/03/2024 t/1900", manager));
+ test1.parseCommand("add-inflow n/Stocks a/600 d/03/03/2024 t/1900 c/investment", manager));
}
public void addOutflow_success() {
Parser test1 = new Parser();
assertEquals("Ok. Added outflow",
- test1.parseCommand("add-outflow n/Rent a/1000 d/18/02/2024 t/1100", manager));
+ test1.parseCommand("add-outflow n/Rent a/1000 d/18/02/2024 t/1100 c/rent", manager));
assertEquals("Ok. Added outflow",
- test1.parseCommand("add-outflow n/Shopping a/150 d/30/01/2024 t/1430", manager));
+ test1.parseCommand("add-outflow n/Shopping a/150 d/30/01/2024 t/1430 c/shopping", manager));
}
}
From cdf7c01906c100fea91289a7a2a9d71c0011867a Mon Sep 17 00:00:00 2001
From: dylansiew <88567790+dylansiew@users.noreply.github.com>
Date: Tue, 19 Mar 2024 23:02:04 +0800
Subject: [PATCH 048/208] update: command class
---
.vscode/settings.json | 3 +
data/data.txt | 3 +
src/main/java/command/AddInflowCommand.java | 38 +++++++
src/main/java/command/AddOutflowCommand.java | 39 +++++++
src/main/java/command/BaseCommand.java | 18 +++
src/main/java/command/ExitCommand.java | 14 +++
src/main/java/command/ViewHistoryCommand.java | 24 ++++
src/main/java/financeproject/Main.java | 82 +++++++++-----
.../java/financialtransactions/Inflow.java | 1 -
.../java/financialtransactions/Outflow.java | 1 -
.../financialtransactions/Transaction.java | 5 -
.../TransactionList.java | 5 +-
.../TransactionManager.java | 21 ++--
src/main/java/parser/Parser.java | 107 ++----------------
src/main/java/storage/Storage.java | 1 +
src/main/java/user/Authentication.java | 17 ++-
src/main/java/user/BaseUser.java | 8 +-
.../UI.java | 2 +-
src/test/java/parser/ParserTest.java | 25 ++--
src/test/java/user/BaseUserTest.java | 5 +-
text-ui-test/EXPECTED.TXT | 10 +-
text-ui-test/data/data.txt | 3 +
text-ui-test/input.txt | 3 +-
23 files changed, 272 insertions(+), 163 deletions(-)
create mode 100644 .vscode/settings.json
create mode 100644 src/main/java/command/AddInflowCommand.java
create mode 100644 src/main/java/command/AddOutflowCommand.java
create mode 100644 src/main/java/command/BaseCommand.java
create mode 100644 src/main/java/command/ExitCommand.java
create mode 100644 src/main/java/command/ViewHistoryCommand.java
rename src/main/java/{userinteraction => userinterface}/UI.java (93%)
create mode 100644 text-ui-test/data/data.txt
diff --git a/.vscode/settings.json b/.vscode/settings.json
new file mode 100644
index 0000000000..c5f3f6b9c7
--- /dev/null
+++ b/.vscode/settings.json
@@ -0,0 +1,3 @@
+{
+ "java.configuration.updateBuildConfiguration": "interactive"
+}
\ No newline at end of file
diff --git a/data/data.txt b/data/data.txt
index e69de29bb2..7e1badc063 100644
--- a/data/data.txt
+++ b/data/data.txt
@@ -0,0 +1,3 @@
+Salary|400.00|May 23 2022 07:00PM|INCOME
+Stocks|400.00|Oct 24 2024 12:00PM|INVESTMENT
+Rent|-1500.00|Jun 23 2023 06:00PM|RENT
diff --git a/src/main/java/command/AddInflowCommand.java b/src/main/java/command/AddInflowCommand.java
new file mode 100644
index 0000000000..185eddb844
--- /dev/null
+++ b/src/main/java/command/AddInflowCommand.java
@@ -0,0 +1,38 @@
+package command;
+
+import financialtransactions.Inflow;
+import financialtransactions.TransactionManager;
+
+public class AddInflowCommand extends BaseCommand {
+
+ public AddInflowCommand(String[] commandParts) {
+ super(false, commandParts);
+ }
+
+ public String execute(TransactionManager manager) {
+ String inflowName = null;
+ double inflowAmount = 0;
+ String inflowDate = null;
+ String inflowTime = null;
+ String inflowCategory = null;
+
+ for (String part : commandParts) {
+ if (part.startsWith("n/")) {
+ inflowName = part.substring(2);
+ } else if (part.startsWith("a/")) {
+ inflowAmount = Double.parseDouble(part.substring(2));
+ } else if (part.startsWith("d/")) {
+ inflowDate = part.substring(2);
+ } else if (part.startsWith("t/")) {
+ inflowTime = part.substring(2);
+ } else if (part.startsWith("c/")) {
+ inflowCategory = part.substring(2);
+ }
+ }
+ String inflowDateTime = inflowDate + " " + inflowTime;
+ Inflow inflow = new Inflow(inflowName, inflowAmount, inflowDateTime);
+ inflow.setCategory(Inflow.Category.valueOf(inflowCategory.toUpperCase()));
+ manager.addTransaction(inflow);
+ return "Ok. Added inflow";
+ }
+}
diff --git a/src/main/java/command/AddOutflowCommand.java b/src/main/java/command/AddOutflowCommand.java
new file mode 100644
index 0000000000..c8de2a708b
--- /dev/null
+++ b/src/main/java/command/AddOutflowCommand.java
@@ -0,0 +1,39 @@
+package command;
+
+import financialtransactions.Outflow;
+import financialtransactions.TransactionManager;
+
+public class AddOutflowCommand extends BaseCommand {
+
+ public AddOutflowCommand(String[] commandParts) {
+ super(false, commandParts);
+ }
+
+ public String execute(TransactionManager manager) {
+ String outflowName = null;
+ double outflowAmount = 0.0;
+ String outflowDate = null;
+ String outflowTime = null;
+ String outflowCategory = null;
+
+ for (String part : commandParts) {
+ if (part.startsWith("n/")) {
+ outflowName = part.substring(2);
+ } else if (part.startsWith("a/")) {
+ outflowAmount = Double.parseDouble(part.substring(2));
+ } else if (part.startsWith("d/")) {
+ outflowDate = part.substring(2);
+ } else if (part.startsWith("t/")) {
+ outflowTime = part.substring(2);
+ } else if (part.startsWith("c/")) {
+ outflowCategory = part.substring(2);
+ }
+ }
+ String outflowDateTime = outflowDate + " " + outflowTime;
+
+ Outflow outflow = new Outflow(outflowName, outflowAmount, outflowDateTime);
+ outflow.setCategory(Outflow.Category.valueOf(outflowCategory.toUpperCase()));
+ manager.addTransaction(outflow);
+ return "Ok. Added outflow";
+ }
+}
diff --git a/src/main/java/command/BaseCommand.java b/src/main/java/command/BaseCommand.java
new file mode 100644
index 0000000000..b3be4c9782
--- /dev/null
+++ b/src/main/java/command/BaseCommand.java
@@ -0,0 +1,18 @@
+package command;
+
+import financialtransactions.TransactionManager;
+
+public abstract class BaseCommand {
+ public boolean isExit;
+ String[] commandParts;
+
+ public BaseCommand(Boolean isExit, String[] commandParts){
+ this.isExit = isExit;
+ this.commandParts = commandParts;
+ }
+ public abstract String execute(TransactionManager manager) throws Exception;
+
+ public boolean isExit() {
+ return this.isExit;
+ }
+}
diff --git a/src/main/java/command/ExitCommand.java b/src/main/java/command/ExitCommand.java
new file mode 100644
index 0000000000..7e80bc869d
--- /dev/null
+++ b/src/main/java/command/ExitCommand.java
@@ -0,0 +1,14 @@
+package command;
+
+import financialtransactions.TransactionManager;
+
+public class ExitCommand extends BaseCommand {
+
+ public ExitCommand(String[] commandParts) {
+ super(true,commandParts);
+ }
+
+ public String execute(TransactionManager manager) {
+ return "Exiting application";
+ }
+}
diff --git a/src/main/java/command/ViewHistoryCommand.java b/src/main/java/command/ViewHistoryCommand.java
new file mode 100644
index 0000000000..09c0223969
--- /dev/null
+++ b/src/main/java/command/ViewHistoryCommand.java
@@ -0,0 +1,24 @@
+package command;
+
+import financialtransactions.TransactionManager;
+
+public class ViewHistoryCommand extends BaseCommand {
+
+ public ViewHistoryCommand(String[] commandParts) {
+ super(false,commandParts);
+ }
+
+ public String execute(TransactionManager manager) throws Exception{
+ String numTransactionsString = null;
+ for (String part : commandParts) {
+ if (part.startsWith("n/")) {
+ numTransactionsString = part.substring(2);
+ }
+ }
+ int numTransactions = 0;
+ if (numTransactionsString != null) {
+ numTransactions = Integer.parseInt(numTransactionsString);
+ }
+ return manager.showLastNTransactions(numTransactions);
+ }
+}
diff --git a/src/main/java/financeproject/Main.java b/src/main/java/financeproject/Main.java
index 497f614543..cff95c29d3 100644
--- a/src/main/java/financeproject/Main.java
+++ b/src/main/java/financeproject/Main.java
@@ -1,52 +1,72 @@
package financeproject;
+import command.BaseCommand;
//import financialtransactions.Inflow;
//import financialtransactions.Outflow;
import financialtransactions.TransactionManager;
import parser.Parser;
import storage.Storage;
-//import user.Authentication;
-//import user.BaseUser;
-import userinteraction.UI;
+import user.Authentication;
+import user.BaseUser;
+import userinterface.UI;
public class Main {
public static void main(String[] args) {
Storage storage = new Storage("./data");
- UI ui = new UI();
- ui.printMessage("Welcome. In order to login, type your command in the format:\nlogin u/USERNAME p/PASSWORD");
TransactionManager manager = new TransactionManager();
manager = storage.loadFile();
-
+ UI ui = new UI();
+ ui.printMessage("Welcome. In order to login, type your command in the format:\nlogin u/USERNAME p/PASSWORD");
+
Parser parser = new Parser();
- while (parser.isContinue) {
+ BaseCommand baseCommand = null;
+ String response = "";
+
+ BaseUser tempUser = new BaseUser("Bob", ui);
+ Authentication auth = tempUser.getAuthentication();
+ if (!auth.authenticate()) {
+ ui.printMessage("Authentication error");
+ ui.closeScanner();
+ return;
+ } else{
+ ui.printMessage("Password is correct. You are now logged in");
+ }
+ do {
String command = ui.readInput();
- parser.parseCommand(command, manager);
+ try {
+ baseCommand = parser.parseCommand(command, manager);
+ response = baseCommand.execute(manager);
+ ui.printMessage(response);
+ } catch (Exception e) {
+ ui.printMessage(e.getMessage());
+ }
storage.saveFile(manager);
- }
+ } while (!baseCommand.isExit());
ui.closeScanner();
/*
- Inflow income = new Inflow("Salary payment", 400.00, "23/05/2022 1900");
- income.setCategory(Inflow.Category.INCOME);
- manager.addTransaction(income);
-
- Inflow investment = new Inflow("Investment", 500.00, "23/05/2022 1900");
- investment.setCategory(Inflow.Category.INVESTMENT);
- manager.addTransaction(investment);
-
- Inflow loan = new Inflow("Loan payment", 400.00, "23/05/2022 1900");
- loan.setCategory(Inflow.Category.LOAN);
- manager.addTransaction(loan);
-
- Outflow rent = new Outflow("Rent", 50000, "23/05/2022 1900");
- rent.setCategory(Outflow.Category.RENT);
- manager.addTransaction(rent);
-
- Outflow shopping = new Outflow("Shopping", 200, "23/05/2022 2000");
- shopping.setCategory(Outflow.Category.SHOPPING);
- manager.addTransaction(shopping);
-
-
- ui.printMessage(manager.toString()); */
+ * Inflow income = new Inflow("Salary payment", 400.00, "23/05/2022 1900");
+ * income.setCategory(Inflow.Category.INCOME);
+ * manager.addTransaction(income);
+ *
+ * Inflow investment = new Inflow("Investment", 500.00, "23/05/2022 1900");
+ * investment.setCategory(Inflow.Category.INVESTMENT);
+ * manager.addTransaction(investment);
+ *
+ * Inflow loan = new Inflow("Loan payment", 400.00, "23/05/2022 1900");
+ * loan.setCategory(Inflow.Category.LOAN);
+ * manager.addTransaction(loan);
+ *
+ * Outflow rent = new Outflow("Rent", 50000, "23/05/2022 1900");
+ * rent.setCategory(Outflow.Category.RENT);
+ * manager.addTransaction(rent);
+ *
+ * Outflow shopping = new Outflow("Shopping", 200, "23/05/2022 2000");
+ * shopping.setCategory(Outflow.Category.SHOPPING);
+ * manager.addTransaction(shopping);
+ *
+ *
+ * ui.printMessage(manager.toString());
+ */
}
}
diff --git a/src/main/java/financialtransactions/Inflow.java b/src/main/java/financialtransactions/Inflow.java
index d7d361a9eb..28480e8527 100644
--- a/src/main/java/financialtransactions/Inflow.java
+++ b/src/main/java/financialtransactions/Inflow.java
@@ -6,7 +6,6 @@ public enum Category {
}
public Inflow(String name, double amount, String date) {
super(name, amount, date);
- super.transactionType = "I";
}
public void setCategory(Category category) {
super.category = category;
diff --git a/src/main/java/financialtransactions/Outflow.java b/src/main/java/financialtransactions/Outflow.java
index 22fa2b6b53..6c428c5731 100644
--- a/src/main/java/financialtransactions/Outflow.java
+++ b/src/main/java/financialtransactions/Outflow.java
@@ -7,7 +7,6 @@ public enum Category {
public Outflow(String name, double amount, String date) {
super(name, -1.00 * amount, date);
- super.transactionType = "O";
}
public void setCategory(Category category) {
diff --git a/src/main/java/financialtransactions/Transaction.java b/src/main/java/financialtransactions/Transaction.java
index 284a5d0e17..5f4f7e7c8a 100644
--- a/src/main/java/financialtransactions/Transaction.java
+++ b/src/main/java/financialtransactions/Transaction.java
@@ -11,7 +11,6 @@ public abstract class Transaction {
protected double amount;
protected BaseDate date;
protected T category;
- protected String transactionType; // Indicates type of task, either "O" for outflow or "I" for inflow
public Transaction(String name, double amount, String date) {
this.name = name;
@@ -31,10 +30,6 @@ public double getAmount() {
return amount;
}
- public String getTransactionType() {
- return this.transactionType;
- }
-
public T getCategory() {
return category;
}
diff --git a/src/main/java/financialtransactions/TransactionList.java b/src/main/java/financialtransactions/TransactionList.java
index e7b6b8750b..344e2a8622 100644
--- a/src/main/java/financialtransactions/TransactionList.java
+++ b/src/main/java/financialtransactions/TransactionList.java
@@ -13,7 +13,10 @@ public int getTransactionListSize() {
return this.transactionList.size();
}
- public T getNthTransaction(int n) {
+ public T getNthTransaction(int n) throws Exception{
+ if(n >= this.transactionList.size()){
+ throw new Exception("Invalid index");
+ }
return this.transactionList.get(n);
}
diff --git a/src/main/java/financialtransactions/TransactionManager.java b/src/main/java/financialtransactions/TransactionManager.java
index 5ce3b76ebf..70d78b2ccc 100644
--- a/src/main/java/financialtransactions/TransactionManager.java
+++ b/src/main/java/financialtransactions/TransactionManager.java
@@ -25,14 +25,13 @@ public boolean addTransaction(Transaction> transaction) {
return false;
}
- public boolean removeTransaction(int index) {
+ public boolean removeTransaction(int index) throws Exception{
transactionList.removeTransactionIndex(index);
Transaction> transactionRemoved = transactionList.getNthTransaction(index);
- String transactionType = transactionRemoved.getTransactionType();
- if (transactionType.equals("I")) {
+ if (transactionRemoved instanceof Inflow) {
return inflows.removeTransactionIndex(index);
}
- if (transactionType.equals("O")){
+ if (transactionRemoved instanceof Outflow){
return outflows.removeTransactionIndex(index);
}
return false;
@@ -49,31 +48,31 @@ public String toString() {
return "Inflows:\n" + inflows.toString() + "\nOutflows:\n" + outflows.toString();
}
- public void showLastNTransactions(int n) {
+ public String showLastNTransactions(int n) throws Exception{
int listSize = transactionList.getTransactionListSize();
if (n > listSize) {
- return;
+ throw new Exception("Invalid index");
}
int index = 1;
-
- System.out.println("Inflows:\nTransactions:");
+ String returnedText = "Inflows:\nTransactions:";
for (int i = listSize - 1; i > listSize - n - 1; i--) {
Transaction> transaction = transactionList.getNthTransaction(i);
if (transaction instanceof Inflow) {
- System.out.println(index + ") " + transactionList.getNthTransaction(i).toString());
+ returnedText += String.format("%d) %s\n", index, transactionList.getNthTransaction(i).toString());
index++;
}
}
index = 1;
- System.out.println("\nOutflows:\nTransactions:");
+ returnedText += "\nOutflows:\nTransactions:";
for (int i = listSize - 1; i > listSize - n - 1; i--) {
Transaction> transaction = transactionList.getNthTransaction(i);
if (transaction instanceof Outflow) {
- System.out.println(index + ") " + transactionList.getNthTransaction(i).toString());
+ returnedText += String.format("%d) %s\n", index, transactionList.getNthTransaction(i).toString());
index++;
}
}
+ return returnedText;
}
public String toSave() {
diff --git a/src/main/java/parser/Parser.java b/src/main/java/parser/Parser.java
index 5c7d7a217f..a7ccca94cd 100644
--- a/src/main/java/parser/Parser.java
+++ b/src/main/java/parser/Parser.java
@@ -1,124 +1,41 @@
package parser;
-import financialtransactions.Inflow;
-import financialtransactions.Outflow;
-import userinteraction.UI;
+import command.AddInflowCommand;
+import command.AddOutflowCommand;
+import command.BaseCommand;
+import command.ExitCommand;
+import command.ViewHistoryCommand;
import financialtransactions.TransactionManager;
-import user.Authentication;
-import user.BaseUser;
+import userinterface.UI;
public class Parser {
- public boolean isContinue;
UI ui;
public Parser() {
- this.isContinue = true;
this.ui = new UI();
}
- public String parseCommand(String command, TransactionManager manager) {
+ public BaseCommand parseCommand(String command, TransactionManager manager) throws Exception {
String[] commandParts = command.split("\\s+");
String action = commandParts[0];
-
switch (action) {
- case "login":
- String username = "";
- String password = null;
- for (String part : commandParts) {
- if (part.startsWith("u/")) {
- username = part.substring(2);
- } else if (part.startsWith("p/")) {
- password = part.substring(2);
- }
- }
-
- BaseUser user = new BaseUser(username);
- Authentication auth = user.getAuthentication();
- if (auth.checkPassword(user.getName(), password)) {
- ui.printMessage("Password is correct. You are now logged in");
- } else {
- ui.printMessage("Password is incorrect");
- }
- break;
case "add-inflow":
- String inflowName = null;
- double inflowAmount = 0;
- String inflowDate = null;
- String inflowTime = null;
- String inflowCategory = null;
-
- for (String part : commandParts) {
- if (part.startsWith("n/")) {
- inflowName = part.substring(2);
- } else if (part.startsWith("a/")) {
- inflowAmount = Double.parseDouble(part.substring(2));
- } else if (part.startsWith("d/")) {
- inflowDate = part.substring(2);
- } else if (part.startsWith("t/")) {
- inflowTime = part.substring(2);
- } else if (part.startsWith("c/")) {
- inflowCategory = part.substring(2);
- }
- }
- String inflowDateTime = inflowDate + " " + inflowTime;
- Inflow inflow = new Inflow(inflowName, inflowAmount, inflowDateTime);
- inflow.setCategory(Inflow.Category.valueOf(inflowCategory.toUpperCase()));
- manager.addTransaction(inflow);
- ui.printMessage("Ok. Added inflow");
- return "Ok. Added inflow";
+ return new AddInflowCommand(commandParts);
case "add-outflow":
- String outflowName = null;
- double outflowAmount = 0;
- String outflowDate = null;
- String outflowTime = null;
- String outflowCategory = null;
-
- for (String part : commandParts) {
- if (part.startsWith("n/")) {
- outflowName = part.substring(2);
- } else if (part.startsWith("a/")) {
- outflowAmount = Double.parseDouble(part.substring(2));
- } else if (part.startsWith("d/")) {
- outflowDate = part.substring(2);
- } else if (part.startsWith("t/")) {
- outflowTime = part.substring(2);
- } else if (part.startsWith("c/")) {
- outflowCategory = part.substring(2);
- }
- }
- String outflowDateTime = outflowDate + " " + outflowTime;
-
- Outflow outflow = new Outflow(outflowName, outflowAmount, outflowDateTime);
- outflow.setCategory(Outflow.Category.valueOf(outflowCategory.toUpperCase()));
- manager.addTransaction(outflow);
- ui.printMessage("Ok. Added outflow");
- return "Ok. Added outflow";
+ return new AddOutflowCommand(commandParts);
case "delete-inflow":
case "delete-outflow":
String index = commandParts[1];
manager.removeTransaction(Integer.parseInt(index));
break;
case "view-history":
- String numTransactionsString = null;
- for (String part : commandParts) {
- if (part.startsWith("n/")) {
- numTransactionsString = part.substring(2);
- }
- }
- int numTransactions = 0;
- if (numTransactionsString != null) {
- numTransactions = Integer.parseInt(numTransactionsString);
- }
- manager.showLastNTransactions(numTransactions);
- break;
+ return new ViewHistoryCommand(commandParts);
case "quit":
- this.isContinue = false;
- break;
+ return new ExitCommand(commandParts);
default:
System.out.println("Invalid command");
break;
}
- return null;
+ throw new Exception("Error parsing");
}
}
-
diff --git a/src/main/java/storage/Storage.java b/src/main/java/storage/Storage.java
index 78d6e5d30e..c5527cc5b3 100644
--- a/src/main/java/storage/Storage.java
+++ b/src/main/java/storage/Storage.java
@@ -34,6 +34,7 @@ public TransactionManager loadFile() {
manager.addTransaction(outflow);
}
}
+ sc.close();
} catch (FileNotFoundException e) {
createFileDir();
}
diff --git a/src/main/java/user/Authentication.java b/src/main/java/user/Authentication.java
index 73aff39e30..a79080ec92 100644
--- a/src/main/java/user/Authentication.java
+++ b/src/main/java/user/Authentication.java
@@ -1,12 +1,17 @@
package user;
+import userinterface.UI;
+
public class Authentication {
String username;
+ UI ui;
private String password;
+
- public Authentication(String password, String username) {
+ public Authentication(String password, String username, UI ui) {
this.password = password;
this.username = username;
+ this.ui = ui;
}
public String getUsername() {
@@ -24,4 +29,14 @@ public Boolean changePassword(String username, String oldPassword, String newPas
this.password = newPassword;
return true;
}
+
+ public Boolean authenticate(){
+ System.out.println("username: ");
+ String inputUsername = this.ui.readInput();
+ System.out.println("password: ");
+ String inputPassword = this.ui.readInput();
+ return this.checkPassword(inputUsername, inputPassword);
+ }
+
+
}
diff --git a/src/main/java/user/BaseUser.java b/src/main/java/user/BaseUser.java
index 38c88f3340..012c99cc82 100644
--- a/src/main/java/user/BaseUser.java
+++ b/src/main/java/user/BaseUser.java
@@ -1,13 +1,17 @@
package user;
+import userinterface.UI;
+
public class BaseUser {
String name;
Authentication auth;
+ UI ui;
- public BaseUser(String name) {
+ public BaseUser(String name, UI ui) {
this.name = name;
String username = name.replace(" ", "_");
- this.auth = new Authentication("password", username);
+ this.auth = new Authentication("password", username, ui);
+ this.ui = ui;
}
public String getName() {
diff --git a/src/main/java/userinteraction/UI.java b/src/main/java/userinterface/UI.java
similarity index 93%
rename from src/main/java/userinteraction/UI.java
rename to src/main/java/userinterface/UI.java
index 81dacce5b0..fd244e5df6 100644
--- a/src/main/java/userinteraction/UI.java
+++ b/src/main/java/userinterface/UI.java
@@ -1,4 +1,4 @@
-package userinteraction;
+package userinterface;
import java.util.Scanner;
diff --git a/src/test/java/parser/ParserTest.java b/src/test/java/parser/ParserTest.java
index cde1e9ae3c..8e77ba6ebe 100644
--- a/src/test/java/parser/ParserTest.java
+++ b/src/test/java/parser/ParserTest.java
@@ -11,18 +11,27 @@ public class ParserTest {
@Test
public void addInflow_success() {
Parser test1 = new Parser();
- assertEquals("Ok. Added inflow",
- test1.parseCommand("add-inflow n/Salary a/5000 d/14/03/2024 t/1700 c/income", manager));
- assertEquals("Ok. Added inflow",
- test1.parseCommand("add-inflow n/Stocks a/600 d/03/03/2024 t/1900 c/investment", manager));
+ try {
+ assertEquals("Ok. Added inflow",
+ test1.parseCommand("add-inflow n/Salary a/5000 d/14/03/2024 t/1700 c/income", manager));
+ assertEquals("Ok. Added inflow",
+ test1.parseCommand("add-inflow n/Stocks a/600 d/03/03/2024 t/1900 c/investment", manager));
+ } catch (Exception e) {
+ System.out.println(e.getMessage());
+ }
+
}
public void addOutflow_success() {
Parser test1 = new Parser();
- assertEquals("Ok. Added outflow",
- test1.parseCommand("add-outflow n/Rent a/1000 d/18/02/2024 t/1100 c/rent", manager));
- assertEquals("Ok. Added outflow",
- test1.parseCommand("add-outflow n/Shopping a/150 d/30/01/2024 t/1430 c/shopping", manager));
+ try {
+ assertEquals("Ok. Added outflow",
+ test1.parseCommand("add-outflow n/Rent a/1000 d/18/02/2024 t/1100 c/rent", manager));
+ assertEquals("Ok. Added outflow",
+ test1.parseCommand("add-outflow n/Shopping a/150 d/30/01/2024 t/1430 c/shopping", manager));
+ } catch (Exception e) {
+ System.out.println(e.getMessage());
+ }
}
}
diff --git a/src/test/java/user/BaseUserTest.java b/src/test/java/user/BaseUserTest.java
index 5f20888351..199b8f1e85 100644
--- a/src/test/java/user/BaseUserTest.java
+++ b/src/test/java/user/BaseUserTest.java
@@ -2,12 +2,15 @@
import org.junit.jupiter.api.Test;
+import userinterface.UI;
+
import static org.junit.jupiter.api.Assertions.assertTrue;
public class BaseUserTest {
@Test
public void sampleTest() {
- BaseUser user = new BaseUser("Bob");
+ UI ui = new UI();
+ BaseUser user = new BaseUser("Bob", ui);
Authentication auth = user.getAuthentication();
assertTrue(auth.checkPassword("Bob", "password"));
}
diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT
index a66a0248bf..df264d467d 100644
--- a/text-ui-test/EXPECTED.TXT
+++ b/text-ui-test/EXPECTED.TXT
@@ -1,13 +1,15 @@
Welcome. In order to login, type your command in the format:
login u/USERNAME p/PASSWORD
+username:
+password:
Password is correct. You are now logged in
Ok. Added inflow
Ok. Added outflow
Ok. Added inflow
Inflows:
-Transactions:
-1) Name: Stocks, Amount: 400.00, Date: Oct 24 2024 12:00PM
+Transactions:1) Name: Stocks, Amount: 400.00, Date: Oct 24 2024 12:00PM
Outflows:
-Transactions:
-1) Name: Rent, Amount: -1500.00, Date: Jun 23 2023 06:00PM
+Transactions:1) Name: Rent, Amount: -1500.00, Date: Jun 23 2023 06:00PM
+
+Exiting application
diff --git a/text-ui-test/data/data.txt b/text-ui-test/data/data.txt
new file mode 100644
index 0000000000..7e1badc063
--- /dev/null
+++ b/text-ui-test/data/data.txt
@@ -0,0 +1,3 @@
+Salary|400.00|May 23 2022 07:00PM|INCOME
+Stocks|400.00|Oct 24 2024 12:00PM|INVESTMENT
+Rent|-1500.00|Jun 23 2023 06:00PM|RENT
diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt
index 68b1978fc1..7f2a2ee23e 100644
--- a/text-ui-test/input.txt
+++ b/text-ui-test/input.txt
@@ -1,4 +1,5 @@
-login u/Bob p/password
+Bob
+password
add-inflow n/Salary a/400.00 d/23/05/2022 t/1900 c/income
add-outflow n/Rent a/1500.00 d/23/06/2023 t/1800 c/rent
add-inflow n/Stocks a/400.00 d/24/10/2024 t/1200 c/investment
From baee009d2a7e61230145812023de93ec8a0d2cb8 Mon Sep 17 00:00:00 2001
From: dylansiew <88567790+dylansiew@users.noreply.github.com>
Date: Tue, 19 Mar 2024 23:16:33 +0800
Subject: [PATCH 049/208] delete parsertest
---
src/test/java/parser/ParserTest.java | 37 ----------------------------
1 file changed, 37 deletions(-)
delete mode 100644 src/test/java/parser/ParserTest.java
diff --git a/src/test/java/parser/ParserTest.java b/src/test/java/parser/ParserTest.java
deleted file mode 100644
index 8e77ba6ebe..0000000000
--- a/src/test/java/parser/ParserTest.java
+++ /dev/null
@@ -1,37 +0,0 @@
-package parser;
-
-import financialtransactions.TransactionManager;
-import org.junit.jupiter.api.Test;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-//import static org.junit.jupiter.api.Assertions.fail;
-
-public class ParserTest {
- TransactionManager manager = new TransactionManager();
-
- @Test
- public void addInflow_success() {
- Parser test1 = new Parser();
- try {
- assertEquals("Ok. Added inflow",
- test1.parseCommand("add-inflow n/Salary a/5000 d/14/03/2024 t/1700 c/income", manager));
- assertEquals("Ok. Added inflow",
- test1.parseCommand("add-inflow n/Stocks a/600 d/03/03/2024 t/1900 c/investment", manager));
- } catch (Exception e) {
- System.out.println(e.getMessage());
- }
-
- }
-
- public void addOutflow_success() {
- Parser test1 = new Parser();
- try {
- assertEquals("Ok. Added outflow",
- test1.parseCommand("add-outflow n/Rent a/1000 d/18/02/2024 t/1100 c/rent", manager));
- assertEquals("Ok. Added outflow",
- test1.parseCommand("add-outflow n/Shopping a/150 d/30/01/2024 t/1430 c/shopping", manager));
- } catch (Exception e) {
- System.out.println(e.getMessage());
- }
- }
-
-}
From 65329cc2db9f616ca2cef15e2210c9f91ff2e6f7 Mon Sep 17 00:00:00 2001
From: Chong Xern <104547209+ChongXern@users.noreply.github.com>
Date: Wed, 20 Mar 2024 17:45:36 +0800
Subject: [PATCH 050/208] Add taxes to outflow
---
src/main/java/financialtransactions/Outflow.java | 2 ++
1 file changed, 2 insertions(+)
diff --git a/src/main/java/financialtransactions/Outflow.java b/src/main/java/financialtransactions/Outflow.java
index 22fa2b6b53..66dacdf293 100644
--- a/src/main/java/financialtransactions/Outflow.java
+++ b/src/main/java/financialtransactions/Outflow.java
@@ -1,6 +1,7 @@
package financialtransactions;
public class Outflow extends Transaction {
+ private static final double TAX_AMOUNT = 0.09;
public enum Category {
RENT, DEBT, SHOPPING, TREAT, EDUCATION, OTHER
}
@@ -8,6 +9,7 @@ public enum Category {
public Outflow(String name, double amount, String date) {
super(name, -1.00 * amount, date);
super.transactionType = "O";
+ super.amount *= TAX_AMOUNT;
}
public void setCategory(Category category) {
From 605cd58d798959269b927051a79e72c9862d750d Mon Sep 17 00:00:00 2001
From: Kishen271828
Date: Wed, 20 Mar 2024 20:38:03 +0800
Subject: [PATCH 051/208] Add data.txt to .gitignore
---
.gitignore | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.gitignore b/.gitignore
index 8fb41d88e1..80baecd9b7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -15,5 +15,5 @@ bin/
/text-ui-test/ACTUAL.TXT
text-ui-test/EXPECTED-UNIX.TXT
-
+data/data.txt
/*.class
\ No newline at end of file
From 183e1f1e8d1b66734caac1752760da97f42b8202 Mon Sep 17 00:00:00 2001
From: Kishen271828
Date: Wed, 20 Mar 2024 20:39:20 +0800
Subject: [PATCH 052/208] Add ..gitignore.un~ to .gitignore
---
.gitignore | 1 +
1 file changed, 1 insertion(+)
diff --git a/.gitignore b/.gitignore
index 80baecd9b7..6b1c18ce77 100644
--- a/.gitignore
+++ b/.gitignore
@@ -16,4 +16,5 @@ bin/
/text-ui-test/ACTUAL.TXT
text-ui-test/EXPECTED-UNIX.TXT
data/data.txt
+..gitignore.un~
/*.class
\ No newline at end of file
From f005ae52a2499b1210b7d3f28bea12e2c62ac7c8 Mon Sep 17 00:00:00 2001
From: Chong Xern <104547209+ChongXern@users.noreply.github.com>
Date: Wed, 20 Mar 2024 22:04:12 +0800
Subject: [PATCH 053/208] Add inactivity timer with associated exception to
throw and catch
---
.../InactivityTimeoutException.java | 14 ++++++++++
src/main/java/financeproject/Main.java | 23 ++++++++++++++++
.../TransactionManager.java | 18 ++++++++-----
src/main/java/parser/Parser.java | 19 ++++---------
src/main/java/user/InactivityTimer.java | 27 +++++++++++++++++++
5 files changed, 80 insertions(+), 21 deletions(-)
create mode 100644 src/main/java/user/InactivityTimer.java
diff --git a/src/main/java/customexceptions/InactivityTimeoutException.java b/src/main/java/customexceptions/InactivityTimeoutException.java
index a4b4c89c2d..0efd0b8162 100644
--- a/src/main/java/customexceptions/InactivityTimeoutException.java
+++ b/src/main/java/customexceptions/InactivityTimeoutException.java
@@ -1,4 +1,18 @@
package customexceptions;
public class InactivityTimeoutException extends Exception {
+ private boolean isTimeOut = false; //Returns true if system is past 3 min, false otherwise
+ private boolean isGracePeriod = false; //Returns true if system is past 2.5 min, false otherwise
+
+ public InactivityTimeoutException(boolean isTimeOut, boolean isGracePeriod) {
+ this.isTimeOut = isTimeOut;
+ this.isGracePeriod = isGracePeriod;
+ }
+
+ public boolean isTimeOut() {
+ return isTimeOut;
+ }
+ public boolean isGracePeriod() {
+ return isGracePeriod;
+ }
}
diff --git a/src/main/java/financeproject/Main.java b/src/main/java/financeproject/Main.java
index d09e6a2d42..eeaf746c13 100644
--- a/src/main/java/financeproject/Main.java
+++ b/src/main/java/financeproject/Main.java
@@ -1,11 +1,15 @@
package financeproject;
+import java.lang.reflect.InaccessibleObjectException;
+
+import customexceptions.InactivityTimeoutException;
//import financialtransactions.Inflow;
//import financialtransactions.Outflow;
import customexceptions.IncompletePromptException;
import financialtransactions.TransactionManager;
import parser.Parser;
import storage.Storage;
+import user.InactivityTimer;
//import user.Authentication;
//import user.BaseUser;
import userinteraction.UI;
@@ -19,7 +23,26 @@ public static void main(String[] args) throws IncompletePromptException {
TransactionManager manager = new TransactionManager();
Parser parser = new Parser();
+ InactivityTimer inactivityTimer = new InactivityTimer();
while (parser.getIsContinue()) {
+ try {
+ inactivityTimer.checkTimeElapsed();
+ } catch (InactivityTimeoutException e) {
+ if (e.isTimeOut()) {
+ parser.setIsContinue(false);
+ }
+ else if (e.isGracePeriod()) {
+ ui.printMessage("Some time has passed. Would you still like to continue: ");
+ String wantToContinue = ui.readInput();
+ if (wantToContinue.equalsIgnoreCase("y") ||
+ wantToContinue.equalsIgnoreCase("yes")) {
+ inactivityTimer.resetTimer();
+ }
+ else if (wantToContinue.equalsIgnoreCase("n") ||
+ wantToContinue.equalsIgnoreCase("no")) {
+ parser.setIsContinue(false);
+ }
+ }
String command = ui.readInput();
parser.parseCommand(command, manager);
storage.saveFile(manager);
diff --git a/src/main/java/financialtransactions/TransactionManager.java b/src/main/java/financialtransactions/TransactionManager.java
index 47710da58d..f53b986b76 100644
--- a/src/main/java/financialtransactions/TransactionManager.java
+++ b/src/main/java/financialtransactions/TransactionManager.java
@@ -1,10 +1,7 @@
package financialtransactions;
-import java.util.ArrayList;
public class TransactionManager {
- private static final String[] INSTRUCTIONS = {"add-inflow", "add-outflow", "delete-inflow",
- "delete-outflow", "export-csv", "login", "quit", "view-history"};
private TransactionList> transactionList;
private TransactionList inflows;
private TransactionList outflows;
@@ -20,7 +17,8 @@ public boolean addTransaction(Transaction> transaction) {
if (transaction instanceof Inflow) {
Inflow inflow = (Inflow) transaction;
return inflows.addTransaction(inflow);
- } else if (transaction instanceof Outflow) {
+ }
+ if (transaction instanceof Outflow) {
Outflow outflow = (Outflow) transaction;
return outflows.addTransaction(outflow);
}
@@ -28,13 +26,19 @@ public boolean addTransaction(Transaction> transaction) {
return false;
}
- public boolean removeTransaction(int index, boolean isInflow) {
+ public boolean removeTransaction(int index) {
transactionList.removeTransactionIndex(index);
- if (isInflow) {
+ Transaction> transactionRemoved = transactionList.getNthTransaction(index);
+ //String transactionType = transactionRemoved.getTransactionType();
+ //if (transactionType.equals("I")) {
+ if (transactionRemoved instanceof Inflow) {
return inflows.removeTransactionIndex(index);
- } else {
+ }
+ //if (transactionType.equals("O")){
+ if (transactionRemoved instanceof Outflow) {
return outflows.removeTransactionIndex(index);
}
+ return false;
}
public double getTotalBalance() {
diff --git a/src/main/java/parser/Parser.java b/src/main/java/parser/Parser.java
index 8a64f8ec04..2cda7433b5 100644
--- a/src/main/java/parser/Parser.java
+++ b/src/main/java/parser/Parser.java
@@ -1,6 +1,5 @@
package parser;
-import customexceptions.IncompletePromptException;
import financialtransactions.Inflow;
import financialtransactions.Outflow;
import userinteraction.UI;
@@ -17,7 +16,7 @@ public Parser() {
this.ui = new UI();
}
- public String parseCommand(String command, TransactionManager manager) throws IncompletePromptException {
+ public String parseCommand(String command, TransactionManager manager) {
String[] commandParts = command.split(" ");
String action = commandParts[0];
@@ -33,9 +32,6 @@ public String parseCommand(String command, TransactionManager manager) throws In
}
break;
case "add-inflow":
- if (commandParts.length != 5) {
- throw new IncompletePromptException();
- }
String inflowName = commandParts[1];
double inflowAmount = Double.parseDouble(commandParts[2]);
String inflowDate = commandParts[3] + " " + commandParts[4];
@@ -45,9 +41,6 @@ public String parseCommand(String command, TransactionManager manager) throws In
ui.printMessage("Ok. Added inflow");
return "Ok. Added inflow";
case "add-outflow":
- if (commandParts.length != 5) {
- throw new IncompletePromptException();
- }
String outflowName = commandParts[1];
double outflowAmount = Double.parseDouble(commandParts[2]);
String outflowDate = commandParts[3] + " " + commandParts[4];
@@ -57,15 +50,9 @@ public String parseCommand(String command, TransactionManager manager) throws In
ui.printMessage("Ok. Added outflow");
return "Ok. Added outflow";
case "delete-inflow":
- if (commandParts.length != 2) {
- throw new IncompletePromptException();
- }
//manager.removeTransaction(1, true);
break;
case "delete-outflow":
- if (commandParts.length != 2) {
- throw new IncompletePromptException();
- }
//manager.removeTransaction(1, false);
break;
case "view-history":
@@ -85,5 +72,9 @@ public String parseCommand(String command, TransactionManager manager) throws In
public boolean getIsContinue(){
return this.isContinue;
}
+
+ public void setIsContinue(boolean isContinue) {
+ this.isContinue = isContinue;
+ }
}
diff --git a/src/main/java/user/InactivityTimer.java b/src/main/java/user/InactivityTimer.java
new file mode 100644
index 0000000000..76eef60bc8
--- /dev/null
+++ b/src/main/java/user/InactivityTimer.java
@@ -0,0 +1,27 @@
+package user;
+
+import customexceptions.InactivityTimeoutException;
+
+public class InactivityTimer {
+ public static final int INACTIVITY_TIME = 180_000;
+ public static final int GRACE_TIME = 30_000;
+ private long startTime;
+
+ public InactivityTimer() {
+ startTime = System.currentTimeMillis();
+ }
+
+ public void resetTimer() {
+ startTime = System.currentTimeMillis();
+ }
+
+ public void checkTimeElapsed() throws InactivityTimeoutException {
+ long timeDifference = System.currentTimeMillis() - startTime;
+ if (timeDifference >= INACTIVITY_TIME) {
+ throw new InactivityTimeoutException(true, false);
+ }
+ else if (timeDifference >= GRACE_TIME) {
+ throw new InactivityTimeoutException(false, true);
+ }
+ }
+}
From e9c39fd4614ebb24684b3d9f2d124f5f091c289a Mon Sep 17 00:00:00 2001
From: Kishen271828
Date: Wed, 20 Mar 2024 23:25:49 +0800
Subject: [PATCH 054/208] Add back ParserTest - JUnit code
---
src/test/java/parser/ParserTest.java | 37 ++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
create mode 100644 src/test/java/parser/ParserTest.java
diff --git a/src/test/java/parser/ParserTest.java b/src/test/java/parser/ParserTest.java
new file mode 100644
index 0000000000..b214126440
--- /dev/null
+++ b/src/test/java/parser/ParserTest.java
@@ -0,0 +1,37 @@
+package parser;
+
+import command.BaseCommand;
+import org.junit.jupiter.api.Test;
+
+import command.AddInflowCommand;
+import command.AddOutflowCommand;
+import financialtransactions.TransactionManager;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+public class ParserTest {
+ Parser parser = new Parser();
+ TransactionManager manager = new TransactionManager();
+
+ @Test
+ public void addInflow_success() throws Exception {
+ String command = "add-inflow n/Stocks a/700 d/28/07/2019 t/1300 c/investment";
+ BaseCommand test1 = parser.parseCommand(command, manager);
+ assertEquals("Ok. Added inflow", test1.execute(manager));
+ }
+
+ @Test
+ public void addOutflow_success() throws Exception {
+ String command = "add-outflow n/Rent a/2000 d/29/09/2021 t/1100 c/rent";
+ BaseCommand test1 = parser.parseCommand(command, manager);
+ assertEquals("Ok. Added outflow", test1.execute(manager));
+ }
+
+ @Test
+ public void sampleTest() throws Exception{
+ String assert1 = "add-inflow n/Salary a/400.00 d/23/05/2022 t/1900 c/income";
+ String assert2 = "add-outflow n/Rent a/1500.00 d/23/06/2023 t/1800 c/rent\n";
+ assertInstanceOf(AddInflowCommand.class, parser.parseCommand(assert1, manager));
+ assertInstanceOf(AddOutflowCommand.class, parser.parseCommand(assert2, manager));
+ }
+}
From 1028f25335c59718950f2d7259edd32bfb09c9bc Mon Sep 17 00:00:00 2001
From: ChongXern
Date: Thu, 21 Mar 2024 01:15:07 +0800
Subject: [PATCH 055/208] Adjust unknown prompt exception
---
.../IncompletePromptException.java | 4 ---
.../UnknownPromptException.java | 5 +++
src/main/java/financeproject/Main.java | 33 ++++++++++---------
src/main/java/parser/Parser.java | 6 ++--
src/test/java/parser/ParserTest.java | 6 ++--
5 files changed, 29 insertions(+), 25 deletions(-)
delete mode 100644 src/main/java/customexceptions/IncompletePromptException.java
create mode 100644 src/main/java/customexceptions/UnknownPromptException.java
diff --git a/src/main/java/customexceptions/IncompletePromptException.java b/src/main/java/customexceptions/IncompletePromptException.java
deleted file mode 100644
index 129f528bd0..0000000000
--- a/src/main/java/customexceptions/IncompletePromptException.java
+++ /dev/null
@@ -1,4 +0,0 @@
-package customexceptions;
-
-public class IncompletePromptException extends Exception {
-}
diff --git a/src/main/java/customexceptions/UnknownPromptException.java b/src/main/java/customexceptions/UnknownPromptException.java
new file mode 100644
index 0000000000..37ca7bb857
--- /dev/null
+++ b/src/main/java/customexceptions/UnknownPromptException.java
@@ -0,0 +1,5 @@
+package customexceptions;
+
+public class UnknownPromptException extends Exception {
+
+}
diff --git a/src/main/java/financeproject/Main.java b/src/main/java/financeproject/Main.java
index eeaf746c13..6059203d71 100644
--- a/src/main/java/financeproject/Main.java
+++ b/src/main/java/financeproject/Main.java
@@ -5,7 +5,7 @@
import customexceptions.InactivityTimeoutException;
//import financialtransactions.Inflow;
//import financialtransactions.Outflow;
-import customexceptions.IncompletePromptException;
+import customexceptions.UnknownPromptException;
import financialtransactions.TransactionManager;
import parser.Parser;
import storage.Storage;
@@ -15,7 +15,7 @@
import userinteraction.UI;
public class Main {
- public static void main(String[] args) throws IncompletePromptException {
+ public static void main(String[] args) {
Storage storage = new Storage("./data");
UI ui = new UI();
ui.printMessage("Welcome. Inorder to login, type your command in the format:\nlogin u/USERNAME p/PASSWORD");
@@ -28,23 +28,26 @@ public static void main(String[] args) throws IncompletePromptException {
try {
inactivityTimer.checkTimeElapsed();
} catch (InactivityTimeoutException e) {
- if (e.isTimeOut()) {
- parser.setIsContinue(false);
- }
- else if (e.isGracePeriod()) {
- ui.printMessage("Some time has passed. Would you still like to continue: ");
- String wantToContinue = ui.readInput();
- if (wantToContinue.equalsIgnoreCase("y") ||
- wantToContinue.equalsIgnoreCase("yes")) {
+ if (e.isTimeOut()) {
+ parser.setIsContinue(false);
+ } else if (e.isGracePeriod()) {
+ ui.printMessage("Some time has passed. Would you still like to continue: ");
+ String wantToContinue = ui.readInput();
+ if (wantToContinue.equalsIgnoreCase("y") ||
+ wantToContinue.equalsIgnoreCase("yes")) {
inactivityTimer.resetTimer();
- }
- else if (wantToContinue.equalsIgnoreCase("n") ||
- wantToContinue.equalsIgnoreCase("no")) {
+ } else if (wantToContinue.equalsIgnoreCase("n") ||
+ wantToContinue.equalsIgnoreCase("no")) {
parser.setIsContinue(false);
+ }
}
- }
+ }
String command = ui.readInput();
- parser.parseCommand(command, manager);
+ try {
+ parser.parseCommand(command, manager);
+ } catch (UnknownPromptException e) {
+ System.out.println("Invalid command");
+ }
storage.saveFile(manager);
}
ui.closeScanner();
diff --git a/src/main/java/parser/Parser.java b/src/main/java/parser/Parser.java
index 2cda7433b5..5ee471f85f 100644
--- a/src/main/java/parser/Parser.java
+++ b/src/main/java/parser/Parser.java
@@ -1,5 +1,6 @@
package parser;
+import customexceptions.UnknownPromptException;
import financialtransactions.Inflow;
import financialtransactions.Outflow;
import userinteraction.UI;
@@ -16,7 +17,7 @@ public Parser() {
this.ui = new UI();
}
- public String parseCommand(String command, TransactionManager manager) {
+ public String parseCommand(String command, TransactionManager manager) throws UnknownPromptException, UnknownPromptException {
String[] commandParts = command.split(" ");
String action = commandParts[0];
@@ -63,8 +64,7 @@ public String parseCommand(String command, TransactionManager manager) {
isContinue = false;
break;
default:
- System.out.println("Invalid command");
- break;
+ throw new UnknownPromptException();
}
return null;
}
diff --git a/src/test/java/parser/ParserTest.java b/src/test/java/parser/ParserTest.java
index 0150b15731..baecb6f1bd 100644
--- a/src/test/java/parser/ParserTest.java
+++ b/src/test/java/parser/ParserTest.java
@@ -1,6 +1,6 @@
package parser;
-import customexceptions.IncompletePromptException;
+import customexceptions.UnknownPromptException;
import financialtransactions.TransactionManager;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -10,13 +10,13 @@ public class ParserTest {
TransactionManager manager = new TransactionManager();
@Test
- public void addInflow_success() throws IncompletePromptException {
+ public void addInflow_success() throws UnknownPromptException {
Parser test1 = new Parser();
assertEquals("Ok. Added inflow", test1.parseCommand("add-inflow Salary 5000 14/03/2024 1700", manager));
assertEquals("Ok. Added inflow", test1.parseCommand("add-inflow Investment 600 03/03/2024 1900", manager));
}
- public void addOutflow_success() throws IncompletePromptException {
+ public void addOutflow_success() throws UnknownPromptException {
Parser test1 = new Parser();
assertEquals("Ok. Added outflow", test1.parseCommand("add-outflow Rent 1000 18/02/2024 1100", manager));
assertEquals("Ok. Added outflow", test1.parseCommand("add-outflow Shopping 150 30/01/2024 1430", manager));
From 213ca4ee2de8c63cf6cd66b5855001060b5f791d Mon Sep 17 00:00:00 2001
From: ChongXern
Date: Thu, 21 Mar 2024 01:45:53 +0800
Subject: [PATCH 056/208] Add and implement incomplete prompt exception with
typo detector
---
.../IncompletePromptException.java | 29 +++++++++++++++++++
.../java/customexceptions/TypoException.java | 4 ---
.../UnknownPromptException.java | 5 ----
src/main/java/financeproject/Main.java | 10 +++++--
.../financialtransactions/Transaction.java | 2 +-
src/main/java/parser/Parser.java | 19 ++++++++++--
src/test/java/parser/ParserTest.java | 6 ++--
7 files changed, 56 insertions(+), 19 deletions(-)
create mode 100644 src/main/java/customexceptions/IncompletePromptException.java
delete mode 100644 src/main/java/customexceptions/TypoException.java
delete mode 100644 src/main/java/customexceptions/UnknownPromptException.java
diff --git a/src/main/java/customexceptions/IncompletePromptException.java b/src/main/java/customexceptions/IncompletePromptException.java
new file mode 100644
index 0000000000..9252e25a9d
--- /dev/null
+++ b/src/main/java/customexceptions/IncompletePromptException.java
@@ -0,0 +1,29 @@
+package customexceptions;
+
+public class IncompletePromptException extends Exception {
+ public static final String[] INSTRUCTIONS = {"add-inflow", "add-outflow", "delete-inflow", "delete-outflow",
+ "login", "quit", "view-history"};
+ private boolean isTypo = false;
+ public IncompletePromptException(String line) {
+ int spaceIndex = line.indexOf(" ");
+ String firstWord = (spaceIndex == -1) ? line : line.substring(0, spaceIndex);
+ checkTypo(firstWord);
+ }
+ public boolean getIsTypo() {
+ return this.isTypo;
+ }
+ public void checkTypo(String word) {
+ for (String instruction : INSTRUCTIONS) {
+ if (!instruction.equals(word) && instruction.contains(word)) {
+ if (!isTypo) {
+ isTypo = true;
+ System.out.println("Did you mean: ");
+ }
+ System.out.print(instruction + " ");
+ }
+ }
+ if (isTypo) {
+ System.out.println("?");
+ }
+ }
+}
diff --git a/src/main/java/customexceptions/TypoException.java b/src/main/java/customexceptions/TypoException.java
deleted file mode 100644
index 758629aa4c..0000000000
--- a/src/main/java/customexceptions/TypoException.java
+++ /dev/null
@@ -1,4 +0,0 @@
-package customexceptions;
-
-public class TypoException extends Exception {
-}
diff --git a/src/main/java/customexceptions/UnknownPromptException.java b/src/main/java/customexceptions/UnknownPromptException.java
deleted file mode 100644
index 37ca7bb857..0000000000
--- a/src/main/java/customexceptions/UnknownPromptException.java
+++ /dev/null
@@ -1,5 +0,0 @@
-package customexceptions;
-
-public class UnknownPromptException extends Exception {
-
-}
diff --git a/src/main/java/financeproject/Main.java b/src/main/java/financeproject/Main.java
index 6059203d71..30d8687f72 100644
--- a/src/main/java/financeproject/Main.java
+++ b/src/main/java/financeproject/Main.java
@@ -5,7 +5,7 @@
import customexceptions.InactivityTimeoutException;
//import financialtransactions.Inflow;
//import financialtransactions.Outflow;
-import customexceptions.UnknownPromptException;
+import customexceptions.IncompletePromptException;
import financialtransactions.TransactionManager;
import parser.Parser;
import storage.Storage;
@@ -45,8 +45,12 @@ public static void main(String[] args) {
String command = ui.readInput();
try {
parser.parseCommand(command, manager);
- } catch (UnknownPromptException e) {
- System.out.println("Invalid command");
+ } catch (IncompletePromptException e) {
+ if (e.getIsTypo()) {
+ System.out.println("Sorry, your prompt appears incomplete. Could you finish your sentence?");
+ } else {
+ System.out.println("Sorry, unknown prompt detected.");
+ }
}
storage.saveFile(manager);
}
diff --git a/src/main/java/financialtransactions/Transaction.java b/src/main/java/financialtransactions/Transaction.java
index 43c2f48a16..e9e089d3b2 100644
--- a/src/main/java/financialtransactions/Transaction.java
+++ b/src/main/java/financialtransactions/Transaction.java
@@ -14,7 +14,7 @@ public abstract class Transaction {
public Transaction(String name, double amount, String date) {
this.name = name;
this.amount = amount;
- if(date == null){
+ if (date == null){
this.date = new BaseDate(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")));
} else{
this.date = new BaseDate(date);
diff --git a/src/main/java/parser/Parser.java b/src/main/java/parser/Parser.java
index 5ee471f85f..355b9fadb3 100644
--- a/src/main/java/parser/Parser.java
+++ b/src/main/java/parser/Parser.java
@@ -1,6 +1,6 @@
package parser;
-import customexceptions.UnknownPromptException;
+import customexceptions.IncompletePromptException;
import financialtransactions.Inflow;
import financialtransactions.Outflow;
import userinteraction.UI;
@@ -17,7 +17,8 @@ public Parser() {
this.ui = new UI();
}
- public String parseCommand(String command, TransactionManager manager) throws UnknownPromptException, UnknownPromptException {
+ public String parseCommand(String command, TransactionManager manager)
+ throws IncompletePromptException {
String[] commandParts = command.split(" ");
String action = commandParts[0];
@@ -33,6 +34,9 @@ public String parseCommand(String command, TransactionManager manager) throws Un
}
break;
case "add-inflow":
+ if (commandParts.length < 3) {
+ throw new IncompletePromptException(command);
+ }
String inflowName = commandParts[1];
double inflowAmount = Double.parseDouble(commandParts[2]);
String inflowDate = commandParts[3] + " " + commandParts[4];
@@ -42,6 +46,9 @@ public String parseCommand(String command, TransactionManager manager) throws Un
ui.printMessage("Ok. Added inflow");
return "Ok. Added inflow";
case "add-outflow":
+ if (commandParts.length < 3) {
+ throw new IncompletePromptException(command);
+ }
String outflowName = commandParts[1];
double outflowAmount = Double.parseDouble(commandParts[2]);
String outflowDate = commandParts[3] + " " + commandParts[4];
@@ -51,9 +58,15 @@ public String parseCommand(String command, TransactionManager manager) throws Un
ui.printMessage("Ok. Added outflow");
return "Ok. Added outflow";
case "delete-inflow":
+ if (commandParts.length < 2) {
+ throw new IncompletePromptException(command);
+ }
//manager.removeTransaction(1, true);
break;
case "delete-outflow":
+ if (commandParts.length < 2) {
+ throw new IncompletePromptException(command);
+ }
//manager.removeTransaction(1, false);
break;
case "view-history":
@@ -64,7 +77,7 @@ public String parseCommand(String command, TransactionManager manager) throws Un
isContinue = false;
break;
default:
- throw new UnknownPromptException();
+ throw new IncompletePromptException(command);
}
return null;
}
diff --git a/src/test/java/parser/ParserTest.java b/src/test/java/parser/ParserTest.java
index baecb6f1bd..0150b15731 100644
--- a/src/test/java/parser/ParserTest.java
+++ b/src/test/java/parser/ParserTest.java
@@ -1,6 +1,6 @@
package parser;
-import customexceptions.UnknownPromptException;
+import customexceptions.IncompletePromptException;
import financialtransactions.TransactionManager;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -10,13 +10,13 @@ public class ParserTest {
TransactionManager manager = new TransactionManager();
@Test
- public void addInflow_success() throws UnknownPromptException {
+ public void addInflow_success() throws IncompletePromptException {
Parser test1 = new Parser();
assertEquals("Ok. Added inflow", test1.parseCommand("add-inflow Salary 5000 14/03/2024 1700", manager));
assertEquals("Ok. Added inflow", test1.parseCommand("add-inflow Investment 600 03/03/2024 1900", manager));
}
- public void addOutflow_success() throws UnknownPromptException {
+ public void addOutflow_success() throws IncompletePromptException {
Parser test1 = new Parser();
assertEquals("Ok. Added outflow", test1.parseCommand("add-outflow Rent 1000 18/02/2024 1100", manager));
assertEquals("Ok. Added outflow", test1.parseCommand("add-outflow Shopping 150 30/01/2024 1430", manager));
From 4d3190016af6d56085f35d389f738cc740ab2852 Mon Sep 17 00:00:00 2001
From: Kishen271828
Date: Thu, 21 Mar 2024 10:47:00 +0800
Subject: [PATCH 057/208] Implement delete inflow and outflow properly
---
.../java/command/DeleteInflowCommand.java | 22 +++++++++++++
.../java/command/DeleteOutflowCommand.java | 22 +++++++++++++
src/main/java/financeproject/Main.java | 4 +--
.../TransactionList.java | 16 +++++++--
.../TransactionManager.java | 20 +++++++++--
src/main/java/parser/Parser.java | 17 +++++++---
text-ui-test/EXPECTED.TXT | 33 ++++++++++++++++---
text-ui-test/input.txt | 6 ++++
8 files changed, 123 insertions(+), 17 deletions(-)
create mode 100644 src/main/java/command/DeleteInflowCommand.java
create mode 100644 src/main/java/command/DeleteOutflowCommand.java
diff --git a/src/main/java/command/DeleteInflowCommand.java b/src/main/java/command/DeleteInflowCommand.java
new file mode 100644
index 0000000000..f0870b6bbd
--- /dev/null
+++ b/src/main/java/command/DeleteInflowCommand.java
@@ -0,0 +1,22 @@
+package command;
+
+import financialtransactions.Outflow;
+import financialtransactions.TransactionManager;
+
+public class DeleteInflowCommand extends BaseCommand {
+ public DeleteInflowCommand(String[] commandParts) {
+ super(false, commandParts);
+ }
+
+ public String execute(TransactionManager manager) throws Exception {
+ String inflowIndex = null;
+ for (String part : commandParts) {
+ if (part.startsWith("n/")) {
+ inflowIndex = part.substring(2);
+ }
+ }
+ assert inflowIndex != null;
+ manager.removeInflow(Integer.parseInt(inflowIndex));
+ return "Ok. Inflow deleted";
+ }
+}
diff --git a/src/main/java/command/DeleteOutflowCommand.java b/src/main/java/command/DeleteOutflowCommand.java
new file mode 100644
index 0000000000..b41b46eb65
--- /dev/null
+++ b/src/main/java/command/DeleteOutflowCommand.java
@@ -0,0 +1,22 @@
+package command;
+
+import financialtransactions.Outflow;
+import financialtransactions.TransactionManager;
+
+public class DeleteOutflowCommand extends BaseCommand {
+ public DeleteOutflowCommand(String[] commandParts) {
+ super(false, commandParts);
+ }
+
+ public String execute(TransactionManager manager) throws Exception {
+ String outflowIndex = null;
+ for (String part : commandParts) {
+ if (part.startsWith("n/")) {
+ outflowIndex = part.substring(2);
+ }
+ }
+ assert outflowIndex != null;
+ manager.removeOutflow(Integer.parseInt(outflowIndex));
+ return "Ok. Outflow deleted";
+ }
+}
diff --git a/src/main/java/financeproject/Main.java b/src/main/java/financeproject/Main.java
index cff95c29d3..a8fdffb976 100644
--- a/src/main/java/financeproject/Main.java
+++ b/src/main/java/financeproject/Main.java
@@ -17,7 +17,7 @@ public static void main(String[] args) {
manager = storage.loadFile();
UI ui = new UI();
- ui.printMessage("Welcome. In order to login, type your command in the format:\nlogin u/USERNAME p/PASSWORD");
+ ui.printMessage("Welcome. Enter your username and password to login.");
Parser parser = new Parser();
BaseCommand baseCommand = null;
@@ -44,7 +44,7 @@ public static void main(String[] args) {
storage.saveFile(manager);
} while (!baseCommand.isExit());
ui.closeScanner();
- /*
+ /*B
* Inflow income = new Inflow("Salary payment", 400.00, "23/05/2022 1900");
* income.setCategory(Inflow.Category.INCOME);
* manager.addTransaction(income);
diff --git a/src/main/java/financialtransactions/TransactionList.java b/src/main/java/financialtransactions/TransactionList.java
index 344e2a8622..3a858d2691 100644
--- a/src/main/java/financialtransactions/TransactionList.java
+++ b/src/main/java/financialtransactions/TransactionList.java
@@ -20,6 +20,10 @@ public T getNthTransaction(int n) throws Exception{
return this.transactionList.get(n);
}
+ public int getIndexOfParticularTransaction(T particularTransaction) {
+ return this.transactionList.indexOf(particularTransaction);
+ }
+
public boolean addTransaction(T newTransaction){
if (newTransaction != null){
transactionList.add(newTransaction);
@@ -28,13 +32,19 @@ public boolean addTransaction(T newTransaction){
return false;
}
- public boolean removeTransactionIndex (int index){
- printTransactionsSafeInfo();
+ public boolean removeTransactionIndex (int index) throws Exception{
+ //printTransactionsSafeInfo();
+ transactionList.remove(index);
+ return true;
+ }
+
+ public boolean editTransactionIndex (int index, T transaction) {
+ //printTransactionsSafeInfo();
if (index >= transactionList.size() || index < 0){
System.out.println("Invalid Index");
return false;
}
- transactionList.remove(index);
+ transactionList.set(index, transaction);
return true;
}
diff --git a/src/main/java/financialtransactions/TransactionManager.java b/src/main/java/financialtransactions/TransactionManager.java
index 70d78b2ccc..2c42c57df2 100644
--- a/src/main/java/financialtransactions/TransactionManager.java
+++ b/src/main/java/financialtransactions/TransactionManager.java
@@ -31,12 +31,26 @@ public boolean removeTransaction(int index) throws Exception{
if (transactionRemoved instanceof Inflow) {
return inflows.removeTransactionIndex(index);
}
- if (transactionRemoved instanceof Outflow){
+ if (transactionRemoved instanceof Outflow) {
return outflows.removeTransactionIndex(index);
}
return false;
}
+ public boolean removeInflow(int index) throws Exception {
+ int numOfInflows = inflows.getTransactionListSize();
+ Transaction> transactionRemoved = inflows.getNthTransaction(numOfInflows - index);
+ transactionList.removeTransactionIndex(transactionList.getIndexOfParticularTransaction(transactionRemoved));
+ return inflows.removeTransactionIndex(numOfInflows - index);
+ }
+
+ public boolean removeOutflow(int index) throws Exception {
+ int numOfOutflows = outflows.getTransactionListSize();
+ Transaction> transactionRemoved = outflows.getNthTransaction(numOfOutflows - index);
+ transactionList.removeTransactionIndex(transactionList.getIndexOfParticularTransaction(transactionRemoved));
+ return outflows.removeTransactionIndex(numOfOutflows - index);
+ }
+
public double getTotalBalance() {
double inflowBalance = inflows.getBalance();
double outflowBalance = outflows.getBalance();
@@ -54,7 +68,7 @@ public String showLastNTransactions(int n) throws Exception{
throw new Exception("Invalid index");
}
int index = 1;
- String returnedText = "Inflows:\nTransactions:";
+ String returnedText = "Inflows:\nTransactions:\n";
for (int i = listSize - 1; i > listSize - n - 1; i--) {
Transaction> transaction = transactionList.getNthTransaction(i);
if (transaction instanceof Inflow) {
@@ -64,7 +78,7 @@ public String showLastNTransactions(int n) throws Exception{
}
index = 1;
- returnedText += "\nOutflows:\nTransactions:";
+ returnedText += "\nOutflows:\nTransactions:\n";
for (int i = listSize - 1; i > listSize - n - 1; i--) {
Transaction> transaction = transactionList.getNthTransaction(i);
if (transaction instanceof Outflow) {
diff --git a/src/main/java/parser/Parser.java b/src/main/java/parser/Parser.java
index a7ccca94cd..1ab4a765cc 100644
--- a/src/main/java/parser/Parser.java
+++ b/src/main/java/parser/Parser.java
@@ -3,6 +3,8 @@
import command.AddInflowCommand;
import command.AddOutflowCommand;
import command.BaseCommand;
+import command.DeleteInflowCommand;
+import command.DeleteOutflowCommand;
import command.ExitCommand;
import command.ViewHistoryCommand;
import financialtransactions.TransactionManager;
@@ -19,23 +21,28 @@ public BaseCommand parseCommand(String command, TransactionManager manager) thro
String[] commandParts = command.split("\\s+");
String action = commandParts[0];
switch (action) {
+ case "help":
+ //implement help command
+ break;
case "add-inflow":
return new AddInflowCommand(commandParts);
case "add-outflow":
return new AddOutflowCommand(commandParts);
case "delete-inflow":
+ return new DeleteInflowCommand(commandParts);
case "delete-outflow":
- String index = commandParts[1];
- manager.removeTransaction(Integer.parseInt(index));
+ return new DeleteOutflowCommand(commandParts);
+ case "edit-inflow":
+ case "edit-outflow":
+ // implement edit transaction command
break;
case "view-history":
return new ViewHistoryCommand(commandParts);
case "quit":
return new ExitCommand(commandParts);
default:
- System.out.println("Invalid command");
- break;
+ throw new Exception("Invalid command");
}
- throw new Exception("Error parsing");
+ return null;
}
}
diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT
index df264d467d..48bc32db1c 100644
--- a/text-ui-test/EXPECTED.TXT
+++ b/text-ui-test/EXPECTED.TXT
@@ -1,5 +1,4 @@
-Welcome. In order to login, type your command in the format:
-login u/USERNAME p/PASSWORD
+Welcome. Enter your username and password to login.
username:
password:
Password is correct. You are now logged in
@@ -7,9 +6,35 @@ Ok. Added inflow
Ok. Added outflow
Ok. Added inflow
Inflows:
-Transactions:1) Name: Stocks, Amount: 400.00, Date: Oct 24 2024 12:00PM
+Transactions:
+1) Name: Stocks, Amount: 400.00, Date: Oct 24 2024 12:00PM
Outflows:
-Transactions:1) Name: Rent, Amount: -1500.00, Date: Jun 23 2023 06:00PM
+Transactions:
+1) Name: Rent, Amount: -1500.00, Date: Jun 23 2023 06:00PM
+
+Ok. Added outflow
+Ok. Added inflow
+Inflows:
+Transactions:
+1) Name: Refund, Amount: 50.00, Date: Jun 23 2023 06:00PM
+2) Name: Stocks, Amount: 400.00, Date: Oct 24 2024 12:00PM
+3) Name: Salary, Amount: 400.00, Date: May 23 2022 07:00PM
+
+Outflows:
+Transactions:
+1) Name: Groceries, Amount: -100.00, Date: Jun 23 2023 06:00PM
+2) Name: Rent, Amount: -1500.00, Date: Jun 23 2023 06:00PM
+
+Ok. Inflow deleted
+Ok. Outflow deleted
+Inflows:
+Transactions:
+1) Name: Refund, Amount: 50.00, Date: Jun 23 2023 06:00PM
+2) Name: Stocks, Amount: 400.00, Date: Oct 24 2024 12:00PM
+
+Outflows:
+Transactions:
+1) Name: Groceries, Amount: -100.00, Date: Jun 23 2023 06:00PM
Exiting application
diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt
index 7f2a2ee23e..49acb10dad 100644
--- a/text-ui-test/input.txt
+++ b/text-ui-test/input.txt
@@ -4,4 +4,10 @@ add-inflow n/Salary a/400.00 d/23/05/2022 t/1900 c/income
add-outflow n/Rent a/1500.00 d/23/06/2023 t/1800 c/rent
add-inflow n/Stocks a/400.00 d/24/10/2024 t/1200 c/investment
view-history n/2
+add-outflow n/Groceries a/100.00 d/23/06/2023 t/1800 c/shopping
+add-inflow n/Refund a/50.00 d/23/06/2023 t/1800 c/refund
+view-history n/5
+delete-inflow n/3
+delete-outflow n/2
+view-history n/3
quit
From 9a6a752823dc079f1cbba75eb77ebdd878dc1427 Mon Sep 17 00:00:00 2001
From: Kishen271828
Date: Thu, 21 Mar 2024 11:19:21 +0800
Subject: [PATCH 058/208] Fix gradle issues
---
.../java/command/DeleteInflowCommand.java | 1 -
.../java/command/DeleteOutflowCommand.java | 1 -
src/main/java/financeproject/Main.java | 6 +++---
src/main/java/parser/Parser.java | 21 ++-----------------
4 files changed, 5 insertions(+), 24 deletions(-)
diff --git a/src/main/java/command/DeleteInflowCommand.java b/src/main/java/command/DeleteInflowCommand.java
index f0870b6bbd..b90c39bdb0 100644
--- a/src/main/java/command/DeleteInflowCommand.java
+++ b/src/main/java/command/DeleteInflowCommand.java
@@ -1,6 +1,5 @@
package command;
-import financialtransactions.Outflow;
import financialtransactions.TransactionManager;
public class DeleteInflowCommand extends BaseCommand {
diff --git a/src/main/java/command/DeleteOutflowCommand.java b/src/main/java/command/DeleteOutflowCommand.java
index b41b46eb65..b9fee8cd04 100644
--- a/src/main/java/command/DeleteOutflowCommand.java
+++ b/src/main/java/command/DeleteOutflowCommand.java
@@ -1,6 +1,5 @@
package command;
-import financialtransactions.Outflow;
import financialtransactions.TransactionManager;
public class DeleteOutflowCommand extends BaseCommand {
diff --git a/src/main/java/financeproject/Main.java b/src/main/java/financeproject/Main.java
index 5af3d67342..554a1cb15f 100644
--- a/src/main/java/financeproject/Main.java
+++ b/src/main/java/financeproject/Main.java
@@ -1,12 +1,12 @@
package financeproject;
-import java.lang.reflect.InaccessibleObjectException;
+//import java.lang.reflect.InaccessibleObjectException;
-import customexceptions.InactivityTimeoutException;
+//import customexceptions.InactivityTimeoutException;
import command.BaseCommand;
//import financialtransactions.Inflow;
//import financialtransactions.Outflow;
-import customexceptions.IncompletePromptException;
+//import customexceptions.IncompletePromptException;
import financialtransactions.TransactionManager;
import parser.Parser;
import storage.Storage;
diff --git a/src/main/java/parser/Parser.java b/src/main/java/parser/Parser.java
index 5019953928..1ef81c66ff 100644
--- a/src/main/java/parser/Parser.java
+++ b/src/main/java/parser/Parser.java
@@ -20,8 +20,7 @@ public Parser() {
this.isContinue = true;
}
- public BaseCommand parseCommand(String command, TransactionManager manager) throws
- IncompletePromptException, Exception {
+ public BaseCommand parseCommand(String command, TransactionManager manager) throws IncompletePromptException, Exception {
String[] commandParts = command.split("\\s+");
String action = commandParts[0];
switch (action) {
@@ -33,27 +32,11 @@ public BaseCommand parseCommand(String command, TransactionManager manager) thro
throw new IncompletePromptException(command);
}
return new AddInflowCommand(commandParts);
- /*String inflowName = commandParts[1];
- double inflowAmount = Double.parseDouble(commandParts[2]);
- String inflowDate = commandParts[3] + " " + commandParts[4];
-
- Inflow inflow = new Inflow(inflowName, inflowAmount, inflowDate);
- manager.addTransaction(inflow);
- ui.printMessage("Ok. Added inflow");*/
- //return "Ok. Added inflow";*/
case "add-outflow":
if (commandParts.length < 3) {
throw new IncompletePromptException(command);
}
return new AddOutflowCommand(commandParts);
- /*String outflowName = commandParts[1];
- double outflowAmount = Double.parseDouble(commandParts[2]);
- String outflowDate = commandParts[3] + " " + commandParts[4];
-
- Outflow outflow = new Outflow(outflowName, outflowAmount, outflowDate);
- manager.addTransaction(outflow);
- ui.printMessage("Ok. Added outflow");*/
- //return "Ok. Added outflow";
case "delete-inflow":
if (commandParts.length < 2) {
throw new IncompletePromptException(command);
@@ -66,7 +49,7 @@ public BaseCommand parseCommand(String command, TransactionManager manager) thro
return new DeleteOutflowCommand(commandParts);
case "edit-inflow":
case "edit-outflow":
- String index = commandParts[1];
+ // implement edit function
break;
case "view-history":
return new ViewHistoryCommand(commandParts);
From 3286fee92a9c3890d8c7c196802a96a71d80a0e8 Mon Sep 17 00:00:00 2001
From: Kishen271828
Date: Thu, 21 Mar 2024 11:45:05 +0800
Subject: [PATCH 059/208] Add config/.idea/ to .gitignore
---
.gitignore | 1 +
1 file changed, 1 insertion(+)
diff --git a/.gitignore b/.gitignore
index 6b1c18ce77..52cc8a9464 100644
--- a/.gitignore
+++ b/.gitignore
@@ -17,4 +17,5 @@ bin/
text-ui-test/EXPECTED-UNIX.TXT
data/data.txt
..gitignore.un~
+config/.idea/
/*.class
\ No newline at end of file
From 6d8a85bc6160f29b61cd99bca83580b73849640a Mon Sep 17 00:00:00 2001
From: ChongXern
Date: Thu, 21 Mar 2024 11:58:24 +0800
Subject: [PATCH 060/208] Fix bugs from previous merge
---
data/data.txt | 2 +-
src/main/java/command/BaseCommand.java | 3 +
src/main/java/financeproject/Main.java | 77 +++++++++----------
.../java/financialtransactions/Outflow.java | 2 +-
4 files changed, 42 insertions(+), 42 deletions(-)
diff --git a/data/data.txt b/data/data.txt
index 7e1badc063..82f8dfc5b0 100644
--- a/data/data.txt
+++ b/data/data.txt
@@ -1,3 +1,3 @@
Salary|400.00|May 23 2022 07:00PM|INCOME
Stocks|400.00|Oct 24 2024 12:00PM|INVESTMENT
-Rent|-1500.00|Jun 23 2023 06:00PM|RENT
+Rent|-1.09|Jun 23 2023 06:00PM|RENT
diff --git a/src/main/java/command/BaseCommand.java b/src/main/java/command/BaseCommand.java
index b3be4c9782..4d725ba882 100644
--- a/src/main/java/command/BaseCommand.java
+++ b/src/main/java/command/BaseCommand.java
@@ -15,4 +15,7 @@ public BaseCommand(Boolean isExit, String[] commandParts){
public boolean isExit() {
return this.isExit;
}
+ public void setIsExit(boolean isExit) {
+ this.isExit = isExit;
+ }
}
diff --git a/src/main/java/financeproject/Main.java b/src/main/java/financeproject/Main.java
index 65053034f2..67b5fc86d3 100644
--- a/src/main/java/financeproject/Main.java
+++ b/src/main/java/financeproject/Main.java
@@ -1,22 +1,15 @@
package financeproject;
-import java.lang.reflect.InaccessibleObjectException;
-
import customexceptions.InactivityTimeoutException;
import command.BaseCommand;
-//import financialtransactions.Inflow;
-//import financialtransactions.Outflow;
import customexceptions.IncompletePromptException;
import financialtransactions.TransactionManager;
import parser.Parser;
import storage.Storage;
import user.InactivityTimer;
-//import user.Authentication;
-//import user.BaseUser;
-//import userinteraction.UI;
import user.Authentication;
import user.BaseUser;
-//import userinterface.UI;
+import userinterface.UI;
public class Main {
public static void main(String[] args) {
@@ -26,15 +19,32 @@ public static void main(String[] args) {
UI ui = new UI();
ui.printMessage("Welcome. In order to login, type your command in the format:\nlogin u/USERNAME p/PASSWORD");
-
+
Parser parser = new Parser();
+ BaseCommand baseCommand = null;
+ String response = "";
+
+ BaseUser tempUser = new BaseUser("Bob", ui);
+ Authentication auth = tempUser.getAuthentication();
InactivityTimer inactivityTimer = new InactivityTimer();
- while (parser.getIsContinue()) {
+
+ if (!auth.authenticate()) {
+ ui.printMessage("Authentication error");
+ ui.closeScanner();
+ return;
+ } else {
+ ui.printMessage("Password is correct. You are now logged in");
+ }
+
+ do {
+ //System.out.println("Welcome to FinTrack! How can we help?");
try {
inactivityTimer.checkTimeElapsed();
} catch (InactivityTimeoutException e) {
if (e.isTimeOut()) {
- parser.setIsContinue(false);
+ //parser.setIsContinue(false);
+ assert baseCommand != null;
+ baseCommand.setIsExit(true);
} else if (e.isGracePeriod()) {
ui.printMessage("Some time has passed. Would you still like to continue: ");
String wantToContinue = ui.readInput();
@@ -43,68 +53,55 @@ public static void main(String[] args) {
inactivityTimer.resetTimer();
} else if (wantToContinue.equalsIgnoreCase("n") ||
wantToContinue.equalsIgnoreCase("no")) {
- parser.setIsContinue(false);
+ //parser.setIsContinue(false);
+ assert baseCommand != null;
+ baseCommand.setIsExit(true);
}
}
}
+
String command = ui.readInput();
try {
- parser.parseCommand(command, manager);
+ baseCommand = parser.parseCommand(command, manager);
+ response = baseCommand.execute(manager);
+ ui.printMessage(response);
} catch (IncompletePromptException e) {
if (e.getIsTypo()) {
System.out.println("Sorry, your prompt appears incomplete. Could you finish your sentence?");
} else {
System.out.println("Sorry, unknown prompt detected.");
}
- }
- storage.saveFile(manager);
- BaseCommand baseCommand = null;
- String response = "";
-
- BaseUser tempUser = new BaseUser("Bob", ui);
- Authentication auth = tempUser.getAuthentication();
- if (!auth.authenticate()) {
- ui.printMessage("Authentication error");
- ui.closeScanner();
- return;
- } else{
- ui.printMessage("Password is correct. You are now logged in");
- }
- do {
- String command = ui.readInput();
- try {
- baseCommand = parser.parseCommand(command, manager);
- response = baseCommand.execute(manager);
- ui.printMessage(response);
} catch (Exception e) {
- ui.printMessage(e.getMessage());
+ System.out.println("Uh-oh, something went wrong: " + e.getMessage());
}
storage.saveFile(manager);
} while (!baseCommand.isExit());
ui.closeScanner();
+
/*
* Inflow income = new Inflow("Salary payment", 400.00, "23/05/2022 1900");
* income.setCategory(Inflow.Category.INCOME);
* manager.addTransaction(income);
- *
+ *
* Inflow investment = new Inflow("Investment", 500.00, "23/05/2022 1900");
* investment.setCategory(Inflow.Category.INVESTMENT);
* manager.addTransaction(investment);
- *
+ *
* Inflow loan = new Inflow("Loan payment", 400.00, "23/05/2022 1900");
* loan.setCategory(Inflow.Category.LOAN);
* manager.addTransaction(loan);
- *
+ *
* Outflow rent = new Outflow("Rent", 50000, "23/05/2022 1900");
* rent.setCategory(Outflow.Category.RENT);
* manager.addTransaction(rent);
- *
+ *
* Outflow shopping = new Outflow("Shopping", 200, "23/05/2022 2000");
* shopping.setCategory(Outflow.Category.SHOPPING);
* manager.addTransaction(shopping);
- *
- *
+ *
+ *
* ui.printMessage(manager.toString());
*/
}
}
+
diff --git a/src/main/java/financialtransactions/Outflow.java b/src/main/java/financialtransactions/Outflow.java
index 66dacdf293..ff280eb759 100644
--- a/src/main/java/financialtransactions/Outflow.java
+++ b/src/main/java/financialtransactions/Outflow.java
@@ -8,7 +8,7 @@ public enum Category {
public Outflow(String name, double amount, String date) {
super(name, -1.00 * amount, date);
- super.transactionType = "O";
+ //super.transactionType = "O";
super.amount *= TAX_AMOUNT;
}
From 25b5c1c1259efd8ea257b9cf4bd8736ed87051fa Mon Sep 17 00:00:00 2001
From: Kishen271828
Date: Thu, 21 Mar 2024 13:00:13 +0800
Subject: [PATCH 061/208] Add edit inflow and outflow functionality
---
src/main/java/command/EditInflowCommand.java | 41 +++++++++++++++++++
src/main/java/command/EditOutflowCommand.java | 41 +++++++++++++++++++
src/main/java/financeproject/Main.java | 2 -
.../TransactionList.java | 7 +---
.../TransactionManager.java | 14 +++++++
src/main/java/parser/Parser.java | 25 ++++++-----
text-ui-test/EXPECTED.TXT | 6 ++-
text-ui-test/input.txt | 2 +
8 files changed, 117 insertions(+), 21 deletions(-)
create mode 100644 src/main/java/command/EditInflowCommand.java
create mode 100644 src/main/java/command/EditOutflowCommand.java
diff --git a/src/main/java/command/EditInflowCommand.java b/src/main/java/command/EditInflowCommand.java
new file mode 100644
index 0000000000..1cb7c0f1b0
--- /dev/null
+++ b/src/main/java/command/EditInflowCommand.java
@@ -0,0 +1,41 @@
+package command;
+
+import financialtransactions.Inflow;
+import financialtransactions.TransactionManager;
+
+public class EditInflowCommand extends BaseCommand {
+ public EditInflowCommand(String[] commandParts) {
+ super(false, commandParts);
+ }
+
+ public String execute(TransactionManager manager) throws Exception {
+ int inflowIndex = -1;
+ String inflowName = null;
+ double inflowAmount = 0;
+ String inflowDate = null;
+ String inflowTime = null;
+ String inflowCategory = null;
+
+ for (String part : commandParts) {
+ if (part.startsWith("i/")) {
+ inflowIndex = Integer.parseInt(part.substring(2));
+ } else if (part.startsWith("n/")) {
+ inflowName = part.substring(2);
+ } else if (part.startsWith("a/")) {
+ inflowAmount = Double.parseDouble(part.substring(2));
+ } else if (part.startsWith("d/")) {
+ inflowDate = part.substring(2);
+ } else if (part.startsWith("t/")) {
+ inflowTime = part.substring(2);
+ } else if (part.startsWith("c/")) {
+ inflowCategory = part.substring(2);
+ }
+ }
+
+ String inflowDateTime = inflowDate + " " + inflowTime;
+ Inflow updatedInflow = new Inflow(inflowName, inflowAmount, inflowDateTime);
+ updatedInflow.setCategory(Inflow.Category.valueOf(inflowCategory.toUpperCase()));
+ manager.editInflow(inflowIndex, updatedInflow);
+ return "Ok. Edited inflow";
+ }
+}
diff --git a/src/main/java/command/EditOutflowCommand.java b/src/main/java/command/EditOutflowCommand.java
new file mode 100644
index 0000000000..cbb3027962
--- /dev/null
+++ b/src/main/java/command/EditOutflowCommand.java
@@ -0,0 +1,41 @@
+package command;
+
+import financialtransactions.Outflow;
+import financialtransactions.TransactionManager;
+
+public class EditOutflowCommand extends BaseCommand {
+ public EditOutflowCommand(String[] commandParts) {
+ super(false, commandParts);
+ }
+
+ public String execute(TransactionManager manager) throws Exception {
+ int outflowIndex = -1;
+ String outflowName = null;
+ double outflowAmount = 0.0;
+ String outflowDate = null;
+ String outflowTime = null;
+ String outflowCategory = null;
+
+ for (String part : commandParts) {
+ if (part.startsWith("i/")) {
+ outflowIndex = Integer.parseInt(part.substring(2));
+ } else if (part.startsWith("n/")) {
+ outflowName = part.substring(2);
+ } else if (part.startsWith("a/")) {
+ outflowAmount = Double.parseDouble(part.substring(2));
+ } else if (part.startsWith("d/")) {
+ outflowDate = part.substring(2);
+ } else if (part.startsWith("t/")) {
+ outflowTime = part.substring(2);
+ } else if (part.startsWith("c/")) {
+ outflowCategory = part.substring(2);
+ }
+ }
+
+ String outflowDateTime = outflowDate + " " + outflowTime;
+ Outflow updatedOutflow = new Outflow(outflowName, outflowAmount, outflowDateTime);
+ updatedOutflow.setCategory(Outflow.Category.valueOf(outflowCategory.toUpperCase()));
+ manager.editOutflow(outflowIndex, updatedOutflow);
+ return "Ok. Edited outflow";
+ }
+}
diff --git a/src/main/java/financeproject/Main.java b/src/main/java/financeproject/Main.java
index 554a1cb15f..56e980bbf5 100644
--- a/src/main/java/financeproject/Main.java
+++ b/src/main/java/financeproject/Main.java
@@ -11,8 +11,6 @@
import parser.Parser;
import storage.Storage;
import user.InactivityTimer;
-//import user.Authentication;
-//import user.BaseUser;
import user.Authentication;
import user.BaseUser;
import userinterface.UI;
diff --git a/src/main/java/financialtransactions/TransactionList.java b/src/main/java/financialtransactions/TransactionList.java
index 3a858d2691..4a1be88b35 100644
--- a/src/main/java/financialtransactions/TransactionList.java
+++ b/src/main/java/financialtransactions/TransactionList.java
@@ -38,12 +38,7 @@ public boolean removeTransactionIndex (int index) throws Exception{
return true;
}
- public boolean editTransactionIndex (int index, T transaction) {
- //printTransactionsSafeInfo();
- if (index >= transactionList.size() || index < 0){
- System.out.println("Invalid Index");
- return false;
- }
+ public boolean editTransactionIndex (int index, T transaction) throws Exception {
transactionList.set(index, transaction);
return true;
}
diff --git a/src/main/java/financialtransactions/TransactionManager.java b/src/main/java/financialtransactions/TransactionManager.java
index fc94892284..7cc6d8dfaf 100644
--- a/src/main/java/financialtransactions/TransactionManager.java
+++ b/src/main/java/financialtransactions/TransactionManager.java
@@ -52,6 +52,20 @@ public boolean removeOutflow(int index) throws Exception {
return outflows.removeTransactionIndex(numOfOutflows - index);
}
+ public boolean editInflow(int index, Transaction> updatedTransaction) throws Exception {
+ int numOfInflows = inflows.getTransactionListSize();
+ Transaction> transactionEdited = inflows.getNthTransaction(numOfInflows - index);
+ transactionList.editTransactionIndex(transactionList.getIndexOfParticularTransaction(transactionEdited), updatedTransaction);
+ return inflows.editTransactionIndex(numOfInflows - index, (Inflow) updatedTransaction);
+ }
+
+ public boolean editOutflow(int index, Transaction> updatedTransaction) throws Exception {
+ int numOfOutflows = outflows.getTransactionListSize();
+ Transaction> transactionEdited = outflows.getNthTransaction(numOfOutflows - index);
+ transactionList.editTransactionIndex(transactionList.getIndexOfParticularTransaction(transactionEdited), updatedTransaction);
+ return outflows.editTransactionIndex(numOfOutflows - index, (Outflow) updatedTransaction);
+ }
+
public double getTotalBalance() {
double inflowBalance = inflows.getBalance();
double outflowBalance = outflows.getBalance();
diff --git a/src/main/java/parser/Parser.java b/src/main/java/parser/Parser.java
index 1ef81c66ff..c0c208434f 100644
--- a/src/main/java/parser/Parser.java
+++ b/src/main/java/parser/Parser.java
@@ -1,13 +1,7 @@
package parser;
+import command.*;
import customexceptions.IncompletePromptException;
-import command.AddInflowCommand;
-import command.AddOutflowCommand;
-import command.BaseCommand;
-import command.DeleteInflowCommand;
-import command.DeleteOutflowCommand;
-import command.ExitCommand;
-import command.ViewHistoryCommand;
import financialtransactions.TransactionManager;
import userinterface.UI;
@@ -28,12 +22,12 @@ public BaseCommand parseCommand(String command, TransactionManager manager) thro
//implement help command
break;
case "add-inflow":
- if (commandParts.length < 3) {
+ if (commandParts.length < 6) {
throw new IncompletePromptException(command);
}
return new AddInflowCommand(commandParts);
case "add-outflow":
- if (commandParts.length < 3) {
+ if (commandParts.length < 6) {
throw new IncompletePromptException(command);
}
return new AddOutflowCommand(commandParts);
@@ -48,10 +42,19 @@ public BaseCommand parseCommand(String command, TransactionManager manager) thro
}
return new DeleteOutflowCommand(commandParts);
case "edit-inflow":
+ if (commandParts.length < 7) {
+ throw new IncompletePromptException(command);
+ }
+ return new EditInflowCommand(commandParts);
case "edit-outflow":
- // implement edit function
- break;
+ if (commandParts.length < 7) {
+ throw new IncompletePromptException(command);
+ }
+ return new EditOutflowCommand(commandParts);
case "view-history":
+ if (commandParts.length < 2) {
+ throw new IncompletePromptException(command);
+ }
return new ViewHistoryCommand(commandParts);
case "quit":
this.isContinue = false;
diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT
index 48bc32db1c..9cd3de5780 100644
--- a/text-ui-test/EXPECTED.TXT
+++ b/text-ui-test/EXPECTED.TXT
@@ -28,13 +28,15 @@ Transactions:
Ok. Inflow deleted
Ok. Outflow deleted
+Ok. Edited inflow
+Ok. Edited outflow
Inflows:
Transactions:
-1) Name: Refund, Amount: 50.00, Date: Jun 23 2023 06:00PM
+1) Name: Refund, Amount: 100.00, Date: Jun 23 2023 05:00PM
2) Name: Stocks, Amount: 400.00, Date: Oct 24 2024 12:00PM
Outflows:
Transactions:
-1) Name: Groceries, Amount: -100.00, Date: Jun 23 2023 06:00PM
+1) Name: Groceries, Amount: -150.00, Date: Jun 23 2023 06:30PM
Exiting application
diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt
index 49acb10dad..fb56b7ff68 100644
--- a/text-ui-test/input.txt
+++ b/text-ui-test/input.txt
@@ -9,5 +9,7 @@ add-inflow n/Refund a/50.00 d/23/06/2023 t/1800 c/refund
view-history n/5
delete-inflow n/3
delete-outflow n/2
+edit-inflow i/1 n/Refund a/100.00 d/23/06/2023 t/1700 c/refund
+edit-outflow i/1 n/Groceries a/150.00 d/23/06/2023 t/1830 c/shopping
view-history n/3
quit
From e4d350bba9e98ecb125b12fd21b57db32055171c Mon Sep 17 00:00:00 2001
From: Kishen271828
Date: Thu, 21 Mar 2024 15:57:52 +0800
Subject: [PATCH 062/208] Modify input format for delete transaction
---
src/main/java/command/DeleteInflowCommand.java | 2 +-
src/main/java/command/DeleteOutflowCommand.java | 2 +-
text-ui-test/input.txt | 4 ++--
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/main/java/command/DeleteInflowCommand.java b/src/main/java/command/DeleteInflowCommand.java
index b90c39bdb0..54dc063246 100644
--- a/src/main/java/command/DeleteInflowCommand.java
+++ b/src/main/java/command/DeleteInflowCommand.java
@@ -10,7 +10,7 @@ public DeleteInflowCommand(String[] commandParts) {
public String execute(TransactionManager manager) throws Exception {
String inflowIndex = null;
for (String part : commandParts) {
- if (part.startsWith("n/")) {
+ if (part.startsWith("i/")) {
inflowIndex = part.substring(2);
}
}
diff --git a/src/main/java/command/DeleteOutflowCommand.java b/src/main/java/command/DeleteOutflowCommand.java
index b9fee8cd04..2b18a9e229 100644
--- a/src/main/java/command/DeleteOutflowCommand.java
+++ b/src/main/java/command/DeleteOutflowCommand.java
@@ -10,7 +10,7 @@ public DeleteOutflowCommand(String[] commandParts) {
public String execute(TransactionManager manager) throws Exception {
String outflowIndex = null;
for (String part : commandParts) {
- if (part.startsWith("n/")) {
+ if (part.startsWith("i/")) {
outflowIndex = part.substring(2);
}
}
diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt
index fb56b7ff68..8e33dfd304 100644
--- a/text-ui-test/input.txt
+++ b/text-ui-test/input.txt
@@ -7,8 +7,8 @@ view-history n/2
add-outflow n/Groceries a/100.00 d/23/06/2023 t/1800 c/shopping
add-inflow n/Refund a/50.00 d/23/06/2023 t/1800 c/refund
view-history n/5
-delete-inflow n/3
-delete-outflow n/2
+delete-inflow i/3
+delete-outflow i/2
edit-inflow i/1 n/Refund a/100.00 d/23/06/2023 t/1700 c/refund
edit-outflow i/1 n/Groceries a/150.00 d/23/06/2023 t/1830 c/shopping
view-history n/3
From d9ea107bfe595178d5f55ad7c5289305cc6ebdbc Mon Sep 17 00:00:00 2001
From: Kishen271828
Date: Thu, 21 Mar 2024 16:10:32 +0800
Subject: [PATCH 063/208] Modify input format for add and edit outflow
---
src/main/java/command/AddOutflowCommand.java | 2 +-
src/main/java/command/EditOutflowCommand.java | 2 +-
text-ui-test/input.txt | 6 +++---
3 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/main/java/command/AddOutflowCommand.java b/src/main/java/command/AddOutflowCommand.java
index c8de2a708b..739c0e16b6 100644
--- a/src/main/java/command/AddOutflowCommand.java
+++ b/src/main/java/command/AddOutflowCommand.java
@@ -17,7 +17,7 @@ public String execute(TransactionManager manager) {
String outflowCategory = null;
for (String part : commandParts) {
- if (part.startsWith("n/")) {
+ if (part.startsWith("r/")) {
outflowName = part.substring(2);
} else if (part.startsWith("a/")) {
outflowAmount = Double.parseDouble(part.substring(2));
diff --git a/src/main/java/command/EditOutflowCommand.java b/src/main/java/command/EditOutflowCommand.java
index cbb3027962..f13e78e418 100644
--- a/src/main/java/command/EditOutflowCommand.java
+++ b/src/main/java/command/EditOutflowCommand.java
@@ -19,7 +19,7 @@ public String execute(TransactionManager manager) throws Exception {
for (String part : commandParts) {
if (part.startsWith("i/")) {
outflowIndex = Integer.parseInt(part.substring(2));
- } else if (part.startsWith("n/")) {
+ } else if (part.startsWith("r/")) {
outflowName = part.substring(2);
} else if (part.startsWith("a/")) {
outflowAmount = Double.parseDouble(part.substring(2));
diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt
index 8e33dfd304..6fd5fce837 100644
--- a/text-ui-test/input.txt
+++ b/text-ui-test/input.txt
@@ -1,15 +1,15 @@
Bob
password
add-inflow n/Salary a/400.00 d/23/05/2022 t/1900 c/income
-add-outflow n/Rent a/1500.00 d/23/06/2023 t/1800 c/rent
+add-outflow r/Rent a/1500.00 d/23/06/2023 t/1800 c/rent
add-inflow n/Stocks a/400.00 d/24/10/2024 t/1200 c/investment
view-history n/2
-add-outflow n/Groceries a/100.00 d/23/06/2023 t/1800 c/shopping
+add-outflow r/Groceries a/100.00 d/23/06/2023 t/1800 c/shopping
add-inflow n/Refund a/50.00 d/23/06/2023 t/1800 c/refund
view-history n/5
delete-inflow i/3
delete-outflow i/2
edit-inflow i/1 n/Refund a/100.00 d/23/06/2023 t/1700 c/refund
-edit-outflow i/1 n/Groceries a/150.00 d/23/06/2023 t/1830 c/shopping
+edit-outflow i/1 r/Groceries a/150.00 d/23/06/2023 t/1830 c/shopping
view-history n/3
quit
From 0c8ccf5bc1fe915cd36e9fa77c62ff9e81fc45e9 Mon Sep 17 00:00:00 2001
From: ChongXern
Date: Thu, 21 Mar 2024 16:50:54 +0800
Subject: [PATCH 064/208] Remove ParserTest
---
src/test/java/parser/ParserTest.java | 25 -------------------------
1 file changed, 25 deletions(-)
delete mode 100644 src/test/java/parser/ParserTest.java
diff --git a/src/test/java/parser/ParserTest.java b/src/test/java/parser/ParserTest.java
deleted file mode 100644
index 0150b15731..0000000000
--- a/src/test/java/parser/ParserTest.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package parser;
-
-import customexceptions.IncompletePromptException;
-import financialtransactions.TransactionManager;
-import org.junit.jupiter.api.Test;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-//import static org.junit.jupiter.api.Assertions.fail;
-
-public class ParserTest {
- TransactionManager manager = new TransactionManager();
-
- @Test
- public void addInflow_success() throws IncompletePromptException {
- Parser test1 = new Parser();
- assertEquals("Ok. Added inflow", test1.parseCommand("add-inflow Salary 5000 14/03/2024 1700", manager));
- assertEquals("Ok. Added inflow", test1.parseCommand("add-inflow Investment 600 03/03/2024 1900", manager));
- }
-
- public void addOutflow_success() throws IncompletePromptException {
- Parser test1 = new Parser();
- assertEquals("Ok. Added outflow", test1.parseCommand("add-outflow Rent 1000 18/02/2024 1100", manager));
- assertEquals("Ok. Added outflow", test1.parseCommand("add-outflow Shopping 150 30/01/2024 1430", manager));
- }
-
-}
From 6674f075cca96febc0178e51d18c6ec408c53e91 Mon Sep 17 00:00:00 2001
From: ChongXern
Date: Thu, 21 Mar 2024 16:58:03 +0800
Subject: [PATCH 065/208] Change transaction manager test and outflow for taxes
---
src/main/java/financialtransactions/Outflow.java | 2 +-
src/test/java/financialtransactions/TransactionManagerTest.java | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/main/java/financialtransactions/Outflow.java b/src/main/java/financialtransactions/Outflow.java
index ff280eb759..deef6283ed 100644
--- a/src/main/java/financialtransactions/Outflow.java
+++ b/src/main/java/financialtransactions/Outflow.java
@@ -1,7 +1,7 @@
package financialtransactions;
public class Outflow extends Transaction {
- private static final double TAX_AMOUNT = 0.09;
+ private static final double TAX_AMOUNT = 1.09;
public enum Category {
RENT, DEBT, SHOPPING, TREAT, EDUCATION, OTHER
}
diff --git a/src/test/java/financialtransactions/TransactionManagerTest.java b/src/test/java/financialtransactions/TransactionManagerTest.java
index e82b58baef..56762f18d8 100644
--- a/src/test/java/financialtransactions/TransactionManagerTest.java
+++ b/src/test/java/financialtransactions/TransactionManagerTest.java
@@ -18,6 +18,6 @@ public void toSaveTest() {
managerTest.addTransaction(shopping);
assertEquals("Salary payment|400.00|May 23 2022 07:00PM|INCOME\n" +
- "Shopping|-200.00|May 23 2022 08:00PM|SHOPPING\n", managerTest.toSave());
+ "Shopping|-218.00|May 23 2022 08:00PM|SHOPPING\n", managerTest.toSave());
}
}
From 8c4bc5c9597980cec4375488cdc555cf4abda23c Mon Sep 17 00:00:00 2001
From: ChongXern
Date: Thu, 21 Mar 2024 16:58:33 +0800
Subject: [PATCH 066/208] Resolve exception handling for incomplete prompt
exception
---
data/data.txt | 3 --
.../IncompletePromptException.java | 25 +++++++++-
src/main/java/financeproject/Main.java | 47 ++++++++++---------
src/main/java/parser/Parser.java | 18 +------
src/main/java/user/InactivityTimer.java | 1 +
5 files changed, 51 insertions(+), 43 deletions(-)
diff --git a/data/data.txt b/data/data.txt
index 82f8dfc5b0..e69de29bb2 100644
--- a/data/data.txt
+++ b/data/data.txt
@@ -1,3 +0,0 @@
-Salary|400.00|May 23 2022 07:00PM|INCOME
-Stocks|400.00|Oct 24 2024 12:00PM|INVESTMENT
-Rent|-1.09|Jun 23 2023 06:00PM|RENT
diff --git a/src/main/java/customexceptions/IncompletePromptException.java b/src/main/java/customexceptions/IncompletePromptException.java
index 9252e25a9d..14c3318e19 100644
--- a/src/main/java/customexceptions/IncompletePromptException.java
+++ b/src/main/java/customexceptions/IncompletePromptException.java
@@ -1,20 +1,38 @@
package customexceptions;
+import java.util.Arrays;
+import java.util.List;
+
public class IncompletePromptException extends Exception {
public static final String[] INSTRUCTIONS = {"add-inflow", "add-outflow", "delete-inflow", "delete-outflow",
"login", "quit", "view-history"};
private boolean isTypo = false;
+ private boolean isIncomplete = false;
+ private boolean isUnknown = false;
+
public IncompletePromptException(String line) {
int spaceIndex = line.indexOf(" ");
String firstWord = (spaceIndex == -1) ? line : line.substring(0, spaceIndex);
- checkTypo(firstWord);
+ if (!Arrays.asList(INSTRUCTIONS).contains(firstWord)) {
+ checkTypo(firstWord);
+ } else {
+ isIncomplete = true;
+ }
}
+
public boolean getIsTypo() {
return this.isTypo;
}
+ public boolean getIsIncomplete() {
+ return this.isIncomplete;
+ }
+ public boolean getIsUnknown() {
+ return this.isUnknown;
+ }
+
public void checkTypo(String word) {
for (String instruction : INSTRUCTIONS) {
- if (!instruction.equals(word) && instruction.contains(word)) {
+ if (instruction.contains(word)) {
if (!isTypo) {
isTypo = true;
System.out.println("Did you mean: ");
@@ -23,7 +41,10 @@ public void checkTypo(String word) {
}
}
if (isTypo) {
+ this.isIncomplete = true;
System.out.println("?");
+ } else {
+ this.isUnknown = true;
}
}
}
diff --git a/src/main/java/financeproject/Main.java b/src/main/java/financeproject/Main.java
index 67b5fc86d3..3cadb5fb8c 100644
--- a/src/main/java/financeproject/Main.java
+++ b/src/main/java/financeproject/Main.java
@@ -14,7 +14,7 @@
public class Main {
public static void main(String[] args) {
Storage storage = new Storage("./data");
- TransactionManager manager = new TransactionManager();
+ TransactionManager manager;
manager = storage.loadFile();
UI ui = new UI();
@@ -34,10 +34,30 @@ public static void main(String[] args) {
return;
} else {
ui.printMessage("Password is correct. You are now logged in");
+ manager = new TransactionManager();
}
do {
- //System.out.println("Welcome to FinTrack! How can we help?");
+ String command = ui.readInput();
+ try {
+ baseCommand = parser.parseCommand(command, manager);
+ response = baseCommand.execute(manager);
+ ui.printMessage(response);
+ inactivityTimer.resetTimer();
+ } catch (IncompletePromptException e) {
+ if (e.getIsTypo()) {
+ System.out.println("Please prompt again with correct spelling.");
+ } else if (e.getIsIncomplete()) {
+ System.out.println("Sorry, your prompt appears incomplete. Could you finish your sentence?");
+ } else if (e.getIsUnknown()) {
+ System.out.println("Sorry, prompt inputted is unknown. ");
+ }
+ } catch (Exception e) {
+ System.out.println("Uh-oh, something went wrong: " + e.getMessage());
+ }
+
+ storage.saveFile(manager);
+
try {
inactivityTimer.checkTimeElapsed();
} catch (InactivityTimeoutException e) {
@@ -50,35 +70,20 @@ public static void main(String[] args) {
String wantToContinue = ui.readInput();
if (wantToContinue.equalsIgnoreCase("y") ||
wantToContinue.equalsIgnoreCase("yes")) {
+ System.out.println("Session continued.");
inactivityTimer.resetTimer();
} else if (wantToContinue.equalsIgnoreCase("n") ||
wantToContinue.equalsIgnoreCase("no")) {
//parser.setIsContinue(false);
+ System.out.println("Session ended. ");
assert baseCommand != null;
baseCommand.setIsExit(true);
}
}
}
-
- String command = ui.readInput();
- try {
- baseCommand = parser.parseCommand(command, manager);
- response = baseCommand.execute(manager);
- ui.printMessage(response);
- } catch (IncompletePromptException e) {
- if (e.getIsTypo()) {
- System.out.println("Sorry, your prompt appears incomplete. Could you finish your sentence?");
- } else {
- System.out.println("Sorry, unknown prompt detected.");
- }
- } catch (Exception e) {
- System.out.println("Uh-oh, something went wrong: " + e.getMessage());
- }
- storage.saveFile(manager);
- } while (!baseCommand.isExit());
+ } while (baseCommand == null || !baseCommand.isExit());
ui.closeScanner();
-
- /*
+/*
* Inflow income = new Inflow("Salary payment", 400.00, "23/05/2022 1900");
* income.setCategory(Inflow.Category.INCOME);
* manager.addTransaction(income);
diff --git a/src/main/java/parser/Parser.java b/src/main/java/parser/Parser.java
index 9f4cf91459..1fe7edc4f7 100644
--- a/src/main/java/parser/Parser.java
+++ b/src/main/java/parser/Parser.java
@@ -21,7 +21,7 @@ public Parser() {
}
public BaseCommand parseCommand(String command, TransactionManager manager) throws
- IncompletePromptException, Exception {
+ Exception {
String[] commandParts = command.split("\\s+");
String action = commandParts[0];
switch (action) {
@@ -30,27 +30,11 @@ public BaseCommand parseCommand(String command, TransactionManager manager) thro
throw new IncompletePromptException(command);
}
return new AddInflowCommand(commandParts);
- /*String inflowName = commandParts[1];
- double inflowAmount = Double.parseDouble(commandParts[2]);
- String inflowDate = commandParts[3] + " " + commandParts[4];
-
- Inflow inflow = new Inflow(inflowName, inflowAmount, inflowDate);
- manager.addTransaction(inflow);
- ui.printMessage("Ok. Added inflow");*/
- //return "Ok. Added inflow";*/
case "add-outflow":
if (commandParts.length < 3) {
throw new IncompletePromptException(command);
}
return new AddOutflowCommand(commandParts);
- /*String outflowName = commandParts[1];
- double outflowAmount = Double.parseDouble(commandParts[2]);
- String outflowDate = commandParts[3] + " " + commandParts[4];
-
- Outflow outflow = new Outflow(outflowName, outflowAmount, outflowDate);
- manager.addTransaction(outflow);
- ui.printMessage("Ok. Added outflow");*/
- //return "Ok. Added outflow";
case "delete-inflow":
case "delete-outflow":
if (commandParts.length < 2) {
diff --git a/src/main/java/user/InactivityTimer.java b/src/main/java/user/InactivityTimer.java
index 76eef60bc8..0c9c86f6e4 100644
--- a/src/main/java/user/InactivityTimer.java
+++ b/src/main/java/user/InactivityTimer.java
@@ -18,6 +18,7 @@ public void resetTimer() {
public void checkTimeElapsed() throws InactivityTimeoutException {
long timeDifference = System.currentTimeMillis() - startTime;
if (timeDifference >= INACTIVITY_TIME) {
+ System.out.println("Sorry, your session has ended. Please log in again.");
throw new InactivityTimeoutException(true, false);
}
else if (timeDifference >= GRACE_TIME) {
From 32e2e18399fd8ddc2d1ed25575b991995cb54bf7 Mon Sep 17 00:00:00 2001
From: ChongXern
Date: Thu, 21 Mar 2024 17:07:13 +0800
Subject: [PATCH 067/208] Fix Gradle checkstyle issues
---
.../IncompletePromptException.java | 4 ++--
src/main/java/financeproject/Main.java | 24 -------------------
src/main/java/parser/Parser.java | 3 ---
text-ui-test/EXPECTED.TXT | 2 +-
4 files changed, 3 insertions(+), 30 deletions(-)
diff --git a/src/main/java/customexceptions/IncompletePromptException.java b/src/main/java/customexceptions/IncompletePromptException.java
index 14c3318e19..776485ccf4 100644
--- a/src/main/java/customexceptions/IncompletePromptException.java
+++ b/src/main/java/customexceptions/IncompletePromptException.java
@@ -1,10 +1,10 @@
package customexceptions;
import java.util.Arrays;
-import java.util.List;
public class IncompletePromptException extends Exception {
- public static final String[] INSTRUCTIONS = {"add-inflow", "add-outflow", "delete-inflow", "delete-outflow",
+ public static final String[] INSTRUCTIONS = {
+ "add-inflow", "add-outflow", "delete-inflow", "delete-outflow",
"login", "quit", "view-history"};
private boolean isTypo = false;
private boolean isIncomplete = false;
diff --git a/src/main/java/financeproject/Main.java b/src/main/java/financeproject/Main.java
index 3cadb5fb8c..093f3eefdf 100644
--- a/src/main/java/financeproject/Main.java
+++ b/src/main/java/financeproject/Main.java
@@ -83,30 +83,6 @@ public static void main(String[] args) {
}
} while (baseCommand == null || !baseCommand.isExit());
ui.closeScanner();
-/*
- * Inflow income = new Inflow("Salary payment", 400.00, "23/05/2022 1900");
- * income.setCategory(Inflow.Category.INCOME);
- * manager.addTransaction(income);
- *
- * Inflow investment = new Inflow("Investment", 500.00, "23/05/2022 1900");
- * investment.setCategory(Inflow.Category.INVESTMENT);
- * manager.addTransaction(investment);
- *
- * Inflow loan = new Inflow("Loan payment", 400.00, "23/05/2022 1900");
- * loan.setCategory(Inflow.Category.LOAN);
- * manager.addTransaction(loan);
- *
- * Outflow rent = new Outflow("Rent", 50000, "23/05/2022 1900");
- * rent.setCategory(Outflow.Category.RENT);
- * manager.addTransaction(rent);
- *
- * Outflow shopping = new Outflow("Shopping", 200, "23/05/2022 2000");
- * shopping.setCategory(Outflow.Category.SHOPPING);
- * manager.addTransaction(shopping);
- *
- *
- * ui.printMessage(manager.toString());
- */
}
}
diff --git a/src/main/java/parser/Parser.java b/src/main/java/parser/Parser.java
index 1fe7edc4f7..d4d0f5cf5d 100644
--- a/src/main/java/parser/Parser.java
+++ b/src/main/java/parser/Parser.java
@@ -1,9 +1,6 @@
package parser;
import customexceptions.IncompletePromptException;
-import financialtransactions.Inflow;
-import financialtransactions.Outflow;
-//import userinteraction.UI;
import command.AddInflowCommand;
import command.AddOutflowCommand;
import command.BaseCommand;
diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT
index df264d467d..42d9a46ada 100644
--- a/text-ui-test/EXPECTED.TXT
+++ b/text-ui-test/EXPECTED.TXT
@@ -10,6 +10,6 @@ Inflows:
Transactions:1) Name: Stocks, Amount: 400.00, Date: Oct 24 2024 12:00PM
Outflows:
-Transactions:1) Name: Rent, Amount: -1500.00, Date: Jun 23 2023 06:00PM
+Transactions:1) Name: Rent, Amount: -1635.00, Date: Jun 23 2023 06:00PM
Exiting application
From 2d2724c80d029688052e98d76a5a446bb8eeee51 Mon Sep 17 00:00:00 2001
From: ChongXern
Date: Thu, 21 Mar 2024 17:22:42 +0800
Subject: [PATCH 068/208] Adjust indentation for instructions list
---
src/main/java/customexceptions/IncompletePromptException.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/main/java/customexceptions/IncompletePromptException.java b/src/main/java/customexceptions/IncompletePromptException.java
index 776485ccf4..047506a41e 100644
--- a/src/main/java/customexceptions/IncompletePromptException.java
+++ b/src/main/java/customexceptions/IncompletePromptException.java
@@ -4,8 +4,8 @@
public class IncompletePromptException extends Exception {
public static final String[] INSTRUCTIONS = {
- "add-inflow", "add-outflow", "delete-inflow", "delete-outflow",
- "login", "quit", "view-history"};
+ "add-inflow", "add-outflow", "delete-inflow", "delete-outflow",
+ "login", "quit", "view-history"};
private boolean isTypo = false;
private boolean isIncomplete = false;
private boolean isUnknown = false;
From 653f4bf20d65d4e776af004abac4b99b20f7545d Mon Sep 17 00:00:00 2001
From: Kishen271828
Date: Thu, 21 Mar 2024 19:28:26 +0800
Subject: [PATCH 069/208] Fix gradle issues
---
src/main/java/financeproject/Main.java | 7 +------
.../java/financialtransactions/TransactionManager.java | 6 ++++--
.../java/financialtransactions/TransactionManagerTest.java | 2 +-
3 files changed, 6 insertions(+), 9 deletions(-)
diff --git a/src/main/java/financeproject/Main.java b/src/main/java/financeproject/Main.java
index aa47040307..3b7db8ba8f 100644
--- a/src/main/java/financeproject/Main.java
+++ b/src/main/java/financeproject/Main.java
@@ -1,7 +1,7 @@
package financeproject;
-import command.BaseCommand;
import customexceptions.InactivityTimeoutException;
+import command.BaseCommand;
import customexceptions.IncompletePromptException;
import financialtransactions.TransactionManager;
import parser.Parser;
@@ -85,8 +85,3 @@ public static void main(String[] args) {
ui.closeScanner();
}
}
-
-
-
-
-
diff --git a/src/main/java/financialtransactions/TransactionManager.java b/src/main/java/financialtransactions/TransactionManager.java
index 7cc6d8dfaf..8355be5360 100644
--- a/src/main/java/financialtransactions/TransactionManager.java
+++ b/src/main/java/financialtransactions/TransactionManager.java
@@ -55,14 +55,16 @@ public boolean removeOutflow(int index) throws Exception {
public boolean editInflow(int index, Transaction> updatedTransaction) throws Exception {
int numOfInflows = inflows.getTransactionListSize();
Transaction> transactionEdited = inflows.getNthTransaction(numOfInflows - index);
- transactionList.editTransactionIndex(transactionList.getIndexOfParticularTransaction(transactionEdited), updatedTransaction);
+ transactionList.editTransactionIndex(transactionList.getIndexOfParticularTransaction(transactionEdited),
+ updatedTransaction);
return inflows.editTransactionIndex(numOfInflows - index, (Inflow) updatedTransaction);
}
public boolean editOutflow(int index, Transaction> updatedTransaction) throws Exception {
int numOfOutflows = outflows.getTransactionListSize();
Transaction> transactionEdited = outflows.getNthTransaction(numOfOutflows - index);
- transactionList.editTransactionIndex(transactionList.getIndexOfParticularTransaction(transactionEdited), updatedTransaction);
+ transactionList.editTransactionIndex(transactionList.getIndexOfParticularTransaction(transactionEdited),
+ updatedTransaction);
return outflows.editTransactionIndex(numOfOutflows - index, (Outflow) updatedTransaction);
}
diff --git a/src/test/java/financialtransactions/TransactionManagerTest.java b/src/test/java/financialtransactions/TransactionManagerTest.java
index 56762f18d8..e82b58baef 100644
--- a/src/test/java/financialtransactions/TransactionManagerTest.java
+++ b/src/test/java/financialtransactions/TransactionManagerTest.java
@@ -18,6 +18,6 @@ public void toSaveTest() {
managerTest.addTransaction(shopping);
assertEquals("Salary payment|400.00|May 23 2022 07:00PM|INCOME\n" +
- "Shopping|-218.00|May 23 2022 08:00PM|SHOPPING\n", managerTest.toSave());
+ "Shopping|-200.00|May 23 2022 08:00PM|SHOPPING\n", managerTest.toSave());
}
}
From f01264214adaec106c4c54a25d3ef2eb2551bf49 Mon Sep 17 00:00:00 2001
From: chowy
Date: Thu, 21 Mar 2024 20:53:49 +0800
Subject: [PATCH 070/208] Added help command
---
src/main/java/command/HelpCommand.java | 25 +++++++++++++++++++++++++
src/main/java/parser/Parser.java | 5 ++---
src/main/java/user/InactivityTimer.java | 3 +--
3 files changed, 28 insertions(+), 5 deletions(-)
create mode 100644 src/main/java/command/HelpCommand.java
diff --git a/src/main/java/command/HelpCommand.java b/src/main/java/command/HelpCommand.java
new file mode 100644
index 0000000000..3489428200
--- /dev/null
+++ b/src/main/java/command/HelpCommand.java
@@ -0,0 +1,25 @@
+package command;
+
+import financialtransactions.TransactionManager;
+
+public class HelpCommand extends BaseCommand {
+ public HelpCommand(String[] commandParts) {
+ super(false, commandParts);
+ }
+
+ @Override
+ public String execute(TransactionManager manager) throws Exception {
+ String baseString = "";
+ baseString += "Here are the available commands: \n";
+ baseString += "1) add-inflow n/ a/ d/ t/ c/\n";
+ baseString += "2) add-outflow n/ a/ d/ t/ c/\n";
+ baseString += "3) delete-inflow i/\n";
+ baseString += "4) delete-outflow i/\n";
+ baseString += "5) edit-inflow i/ n/ a/ d/ t/ c/\n";
+ baseString += "6) edit-outflow i/ n/ a/ d/ t/ c/\n";
+ baseString += "7) view-history INDEX \n";
+ baseString += "8) quit \n";
+ baseString += "_____________";
+ return baseString;
+ }
+}
diff --git a/src/main/java/parser/Parser.java b/src/main/java/parser/Parser.java
index 39f48276f8..72bdae627f 100644
--- a/src/main/java/parser/Parser.java
+++ b/src/main/java/parser/Parser.java
@@ -9,6 +9,7 @@
import command.EditOutflowCommand;
import command.ExitCommand;
import command.ViewHistoryCommand;
+import command.HelpCommand;
import customexceptions.IncompletePromptException;
import financialtransactions.TransactionManager;
import userinterface.UI;
@@ -27,8 +28,7 @@ public BaseCommand parseCommand(String command, TransactionManager manager) thro
String action = commandParts[0];
switch (action) {
case "help":
- //implement help command
- break;
+ return new HelpCommand(commandParts);
case "add-inflow":
if (commandParts.length < 6) {
throw new IncompletePromptException(command);
@@ -70,7 +70,6 @@ public BaseCommand parseCommand(String command, TransactionManager manager) thro
default:
throw new Exception("Invalid command");
}
- return null;
}
}
diff --git a/src/main/java/user/InactivityTimer.java b/src/main/java/user/InactivityTimer.java
index 0c9c86f6e4..f6fb5378cb 100644
--- a/src/main/java/user/InactivityTimer.java
+++ b/src/main/java/user/InactivityTimer.java
@@ -20,8 +20,7 @@ public void checkTimeElapsed() throws InactivityTimeoutException {
if (timeDifference >= INACTIVITY_TIME) {
System.out.println("Sorry, your session has ended. Please log in again.");
throw new InactivityTimeoutException(true, false);
- }
- else if (timeDifference >= GRACE_TIME) {
+ } else if (timeDifference >= GRACE_TIME) {
throw new InactivityTimeoutException(false, true);
}
}
From bc73d6318f409866c532f1ac66d91167d90a0273 Mon Sep 17 00:00:00 2001
From: chowy
Date: Thu, 21 Mar 2024 20:55:46 +0800
Subject: [PATCH 071/208] Added assertion for transactionInfo
---
src/main/java/storage/Storage.java | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/main/java/storage/Storage.java b/src/main/java/storage/Storage.java
index c5527cc5b3..6fbce01a93 100644
--- a/src/main/java/storage/Storage.java
+++ b/src/main/java/storage/Storage.java
@@ -23,6 +23,7 @@ public TransactionManager loadFile() {
Scanner sc = new Scanner(f);
while (sc.hasNext()) {
String[] transactionInfo = sc.nextLine().split("\\|");
+ assert transactionInfo.length == 4 : "Transaction info should have 4 arguments";
double amount = Double.parseDouble(transactionInfo[1]);
if (!transactionInfo[1].startsWith("-")) {
Inflow inflow = new Inflow(transactionInfo[0], amount, transactionInfo[2]);
From 8118dcc07be09d9037f7e4e4997d102c8649faa3 Mon Sep 17 00:00:00 2001
From: dylansiew <88567790+dylansiew@users.noreply.github.com>
Date: Thu, 21 Mar 2024 21:31:25 +0800
Subject: [PATCH 072/208] refactor
---
.../java/command/DeleteOutflowCommand.java | 19 +++++
src/main/java/financeproject/Main.java | 4 +-
src/main/java/parser/Parser.java | 78 ++++++-------------
src/test/java/parser/ParserTest.java | 25 ------
4 files changed, 46 insertions(+), 80 deletions(-)
create mode 100644 src/main/java/command/DeleteOutflowCommand.java
delete mode 100644 src/test/java/parser/ParserTest.java
diff --git a/src/main/java/command/DeleteOutflowCommand.java b/src/main/java/command/DeleteOutflowCommand.java
new file mode 100644
index 0000000000..525db211bb
--- /dev/null
+++ b/src/main/java/command/DeleteOutflowCommand.java
@@ -0,0 +1,19 @@
+package command;
+
+import financialtransactions.TransactionManager;
+
+public class DeleteOutflowCommand extends BaseCommand {
+
+ public DeleteOutflowCommand(String[] commandParts) {
+ super(false, commandParts);
+ }
+
+ public String execute(TransactionManager manager) throws Exception{
+ if(manager.removeTransaction(Integer.parseInt(this.commandParts[1]))){
+ return "Transaction has been removed";
+ } else{
+ throw new Exception("Error while removing outflow");
+ }
+
+ }
+}
diff --git a/src/main/java/financeproject/Main.java b/src/main/java/financeproject/Main.java
index 67b5fc86d3..dbd84ad073 100644
--- a/src/main/java/financeproject/Main.java
+++ b/src/main/java/financeproject/Main.java
@@ -20,7 +20,7 @@ public static void main(String[] args) {
UI ui = new UI();
ui.printMessage("Welcome. In order to login, type your command in the format:\nlogin u/USERNAME p/PASSWORD");
- Parser parser = new Parser();
+ Parser parser = new Parser(ui);
BaseCommand baseCommand = null;
String response = "";
@@ -62,7 +62,7 @@ public static void main(String[] args) {
String command = ui.readInput();
try {
- baseCommand = parser.parseCommand(command, manager);
+ baseCommand = parser.parseCommand(command);
response = baseCommand.execute(manager);
ui.printMessage(response);
} catch (IncompletePromptException e) {
diff --git a/src/main/java/parser/Parser.java b/src/main/java/parser/Parser.java
index 9f4cf91459..7601a16af9 100644
--- a/src/main/java/parser/Parser.java
+++ b/src/main/java/parser/Parser.java
@@ -1,75 +1,47 @@
package parser;
import customexceptions.IncompletePromptException;
-import financialtransactions.Inflow;
-import financialtransactions.Outflow;
-//import userinteraction.UI;
import command.AddInflowCommand;
import command.AddOutflowCommand;
import command.BaseCommand;
+import command.DeleteOutflowCommand;
import command.ExitCommand;
import command.ViewHistoryCommand;
-import financialtransactions.TransactionManager;
import userinterface.UI;
public class Parser {
- public boolean isContinue;
UI ui;
- public Parser() {
- this.ui = new UI();
+ public Parser(UI ui) {
+ this.ui = ui;
}
- public BaseCommand parseCommand(String command, TransactionManager manager) throws
- IncompletePromptException, Exception {
+ public BaseCommand parseCommand(String command) throws IncompletePromptException, Exception {
String[] commandParts = command.split("\\s+");
String action = commandParts[0];
switch (action) {
- case "add-inflow":
- if (commandParts.length < 3) {
+ case "add-inflow":
+ if (commandParts.length < 3) {
+ throw new IncompletePromptException(command);
+ }
+ return new AddInflowCommand(commandParts);
+ case "add-outflow":
+ if (commandParts.length < 3) {
+ throw new IncompletePromptException(command);
+ }
+ return new AddOutflowCommand(commandParts);
+ case "delete-inflow":
+ case "delete-outflow":
+ if (commandParts.length < 2) {
+ throw new IncompletePromptException(command);
+ }
+ return new DeleteOutflowCommand(commandParts);
+ case "view-history":
+ return new ViewHistoryCommand(commandParts);
+ case "quit":
+ return new ExitCommand(commandParts);
+ default:
throw new IncompletePromptException(command);
- }
- return new AddInflowCommand(commandParts);
- /*String inflowName = commandParts[1];
- double inflowAmount = Double.parseDouble(commandParts[2]);
- String inflowDate = commandParts[3] + " " + commandParts[4];
-
- Inflow inflow = new Inflow(inflowName, inflowAmount, inflowDate);
- manager.addTransaction(inflow);
- ui.printMessage("Ok. Added inflow");*/
- //return "Ok. Added inflow";*/
- case "add-outflow":
- if (commandParts.length < 3) {
- throw new IncompletePromptException(command);
- }
- return new AddOutflowCommand(commandParts);
- /*String outflowName = commandParts[1];
- double outflowAmount = Double.parseDouble(commandParts[2]);
- String outflowDate = commandParts[3] + " " + commandParts[4];
-
- Outflow outflow = new Outflow(outflowName, outflowAmount, outflowDate);
- manager.addTransaction(outflow);
- ui.printMessage("Ok. Added outflow");*/
- //return "Ok. Added outflow";
- case "delete-inflow":
- case "delete-outflow":
- if (commandParts.length < 2) {
- throw new IncompletePromptException(command);
- }
- String index = commandParts[1];
- manager.removeTransaction(Integer.parseInt(index));
- break;
- case "view-history":
- return new ViewHistoryCommand(commandParts);
- case "quit":
- return new ExitCommand(commandParts);
- default:
- throw new IncompletePromptException(command);
}
- throw new Exception("Error parsing");
- }
-
- public void setIsContinue(boolean isContinue) {
- this.isContinue = isContinue;
}
}
diff --git a/src/test/java/parser/ParserTest.java b/src/test/java/parser/ParserTest.java
deleted file mode 100644
index 0150b15731..0000000000
--- a/src/test/java/parser/ParserTest.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package parser;
-
-import customexceptions.IncompletePromptException;
-import financialtransactions.TransactionManager;
-import org.junit.jupiter.api.Test;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-//import static org.junit.jupiter.api.Assertions.fail;
-
-public class ParserTest {
- TransactionManager manager = new TransactionManager();
-
- @Test
- public void addInflow_success() throws IncompletePromptException {
- Parser test1 = new Parser();
- assertEquals("Ok. Added inflow", test1.parseCommand("add-inflow Salary 5000 14/03/2024 1700", manager));
- assertEquals("Ok. Added inflow", test1.parseCommand("add-inflow Investment 600 03/03/2024 1900", manager));
- }
-
- public void addOutflow_success() throws IncompletePromptException {
- Parser test1 = new Parser();
- assertEquals("Ok. Added outflow", test1.parseCommand("add-outflow Rent 1000 18/02/2024 1100", manager));
- assertEquals("Ok. Added outflow", test1.parseCommand("add-outflow Shopping 150 30/01/2024 1430", manager));
- }
-
-}
From 169d765d97c8b4097605256c31dc2e1488c8ab0b Mon Sep 17 00:00:00 2001
From: ChongXern
Date: Thu, 21 Mar 2024 21:43:05 +0800
Subject: [PATCH 073/208] Move tax to category, adjust security exception
---
data/data.txt | 3 +++
src/main/java/command/AddInflowCommand.java | 1 +
.../IncompletePromptException.java | 8 +++++---
src/main/java/financeproject/Main.java | 3 ++-
.../java/financialtransactions/Outflow.java | 5 ++---
src/main/java/user/Authentication.java | 18 ++++++++++++++----
src/main/java/user/InactivityTimer.java | 3 ++-
.../TransactionManagerTest.java | 2 +-
src/test/java/user/BaseUserTest.java | 3 ++-
text-ui-test/EXPECTED.TXT | 2 +-
10 files changed, 33 insertions(+), 15 deletions(-)
diff --git a/data/data.txt b/data/data.txt
index e69de29bb2..b0693d7a6e 100644
--- a/data/data.txt
+++ b/data/data.txt
@@ -0,0 +1,3 @@
+Stocks|400.00|Oct 24 2024 12:00PM|INVESTMENT
+Stocks|400.00|Oct 24 2024 12:00PM|INVESTMENT
+Stocks|400.00|Oct 24 2024 12:00PM|INVESTMENT
diff --git a/src/main/java/command/AddInflowCommand.java b/src/main/java/command/AddInflowCommand.java
index 185eddb844..521ce098ef 100644
--- a/src/main/java/command/AddInflowCommand.java
+++ b/src/main/java/command/AddInflowCommand.java
@@ -31,6 +31,7 @@ public String execute(TransactionManager manager) {
}
String inflowDateTime = inflowDate + " " + inflowTime;
Inflow inflow = new Inflow(inflowName, inflowAmount, inflowDateTime);
+ assert inflowCategory != null;
inflow.setCategory(Inflow.Category.valueOf(inflowCategory.toUpperCase()));
manager.addTransaction(inflow);
return "Ok. Added inflow";
diff --git a/src/main/java/customexceptions/IncompletePromptException.java b/src/main/java/customexceptions/IncompletePromptException.java
index 047506a41e..7039ad5b4c 100644
--- a/src/main/java/customexceptions/IncompletePromptException.java
+++ b/src/main/java/customexceptions/IncompletePromptException.java
@@ -13,10 +13,12 @@ public class IncompletePromptException extends Exception {
public IncompletePromptException(String line) {
int spaceIndex = line.indexOf(" ");
String firstWord = (spaceIndex == -1) ? line : line.substring(0, spaceIndex);
- if (!Arrays.asList(INSTRUCTIONS).contains(firstWord)) {
- checkTypo(firstWord);
- } else {
+ if (Arrays.asList(INSTRUCTIONS).contains(firstWord)) {
+ isTypo = false;
isIncomplete = true;
+ isUnknown = false;
+ } else {
+ checkTypo(firstWord);
}
}
diff --git a/src/main/java/financeproject/Main.java b/src/main/java/financeproject/Main.java
index 093f3eefdf..846c8b7457 100644
--- a/src/main/java/financeproject/Main.java
+++ b/src/main/java/financeproject/Main.java
@@ -3,6 +3,7 @@
import customexceptions.InactivityTimeoutException;
import command.BaseCommand;
import customexceptions.IncompletePromptException;
+import customexceptions.SecurityException;
import financialtransactions.TransactionManager;
import parser.Parser;
import storage.Storage;
@@ -12,7 +13,7 @@
import userinterface.UI;
public class Main {
- public static void main(String[] args) {
+ public static void main(String[] args) throws SecurityException {
Storage storage = new Storage("./data");
TransactionManager manager;
manager = storage.loadFile();
diff --git a/src/main/java/financialtransactions/Outflow.java b/src/main/java/financialtransactions/Outflow.java
index deef6283ed..7e2c24d77b 100644
--- a/src/main/java/financialtransactions/Outflow.java
+++ b/src/main/java/financialtransactions/Outflow.java
@@ -1,15 +1,14 @@
package financialtransactions;
public class Outflow extends Transaction {
- private static final double TAX_AMOUNT = 1.09;
public enum Category {
- RENT, DEBT, SHOPPING, TREAT, EDUCATION, OTHER
+ RENT, DEBT, SHOPPING, TREAT, EDUCATION, TAX, OTHER
}
public Outflow(String name, double amount, String date) {
super(name, -1.00 * amount, date);
//super.transactionType = "O";
- super.amount *= TAX_AMOUNT;
+ super.amount = amount;
}
public void setCategory(Category category) {
diff --git a/src/main/java/user/Authentication.java b/src/main/java/user/Authentication.java
index a79080ec92..070184795c 100644
--- a/src/main/java/user/Authentication.java
+++ b/src/main/java/user/Authentication.java
@@ -1,28 +1,38 @@
package user;
+import customexceptions.SecurityException;
import userinterface.UI;
public class Authentication {
String username;
UI ui;
private String password;
+ private int wrongAttempts;
public Authentication(String password, String username, UI ui) {
this.password = password;
this.username = username;
this.ui = ui;
+ this.wrongAttempts = 0;
}
public String getUsername() {
return this.username;
}
- public Boolean checkPassword(String username, String password) {
- return this.password.equals(password) && this.username.equals(username);
+ public boolean checkPassword(String username, String password) throws SecurityException {
+ boolean isMatch = this.password.equals(password) && this.username.equals(username);
+ if (!isMatch) {
+ wrongAttempts++;
+ if (wrongAttempts == 3) {
+ throw new SecurityException();
+ }
+ }
+ return isMatch;
}
- public Boolean changePassword(String username, String oldPassword, String newPassword) {
+ public boolean changePassword(String username, String oldPassword, String newPassword) throws SecurityException {
if (!checkPassword(username, oldPassword)) {
return false;
}
@@ -30,7 +40,7 @@ public Boolean changePassword(String username, String oldPassword, String newPas
return true;
}
- public Boolean authenticate(){
+ public boolean authenticate() throws SecurityException {
System.out.println("username: ");
String inputUsername = this.ui.readInput();
System.out.println("password: ");
diff --git a/src/main/java/user/InactivityTimer.java b/src/main/java/user/InactivityTimer.java
index 0c9c86f6e4..9c474fcb6f 100644
--- a/src/main/java/user/InactivityTimer.java
+++ b/src/main/java/user/InactivityTimer.java
@@ -12,6 +12,7 @@ public InactivityTimer() {
}
public void resetTimer() {
+ assert startTime != System.currentTimeMillis();
startTime = System.currentTimeMillis();
}
@@ -21,7 +22,7 @@ public void checkTimeElapsed() throws InactivityTimeoutException {
System.out.println("Sorry, your session has ended. Please log in again.");
throw new InactivityTimeoutException(true, false);
}
- else if (timeDifference >= GRACE_TIME) {
+ else if (timeDifference >= INACTIVITY_TIME - GRACE_TIME) {
throw new InactivityTimeoutException(false, true);
}
}
diff --git a/src/test/java/financialtransactions/TransactionManagerTest.java b/src/test/java/financialtransactions/TransactionManagerTest.java
index 56762f18d8..e82b58baef 100644
--- a/src/test/java/financialtransactions/TransactionManagerTest.java
+++ b/src/test/java/financialtransactions/TransactionManagerTest.java
@@ -18,6 +18,6 @@ public void toSaveTest() {
managerTest.addTransaction(shopping);
assertEquals("Salary payment|400.00|May 23 2022 07:00PM|INCOME\n" +
- "Shopping|-218.00|May 23 2022 08:00PM|SHOPPING\n", managerTest.toSave());
+ "Shopping|-200.00|May 23 2022 08:00PM|SHOPPING\n", managerTest.toSave());
}
}
diff --git a/src/test/java/user/BaseUserTest.java b/src/test/java/user/BaseUserTest.java
index 199b8f1e85..a1d8d36c2e 100644
--- a/src/test/java/user/BaseUserTest.java
+++ b/src/test/java/user/BaseUserTest.java
@@ -1,5 +1,6 @@
package user;
+import customexceptions.SecurityException;
import org.junit.jupiter.api.Test;
import userinterface.UI;
@@ -8,7 +9,7 @@
public class BaseUserTest {
@Test
- public void sampleTest() {
+ public void sampleTest() throws SecurityException {
UI ui = new UI();
BaseUser user = new BaseUser("Bob", ui);
Authentication auth = user.getAuthentication();
diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT
index 42d9a46ada..df264d467d 100644
--- a/text-ui-test/EXPECTED.TXT
+++ b/text-ui-test/EXPECTED.TXT
@@ -10,6 +10,6 @@ Inflows:
Transactions:1) Name: Stocks, Amount: 400.00, Date: Oct 24 2024 12:00PM
Outflows:
-Transactions:1) Name: Rent, Amount: -1635.00, Date: Jun 23 2023 06:00PM
+Transactions:1) Name: Rent, Amount: -1500.00, Date: Jun 23 2023 06:00PM
Exiting application
From eeeae092907f252fee0cbdfe268a142cfec3ff86 Mon Sep 17 00:00:00 2001
From: Dylan Siew
Date: Thu, 21 Mar 2024 21:52:01 +0800
Subject: [PATCH 074/208] resolving errors
---
.../IncompletePromptException.java | 2 +-
src/main/java/parser/Parser.java | 42 +++++++++----------
src/main/java/user/InactivityTimer.java | 3 +-
.../TransactionManagerTest.java | 4 +-
4 files changed, 25 insertions(+), 26 deletions(-)
diff --git a/src/main/java/customexceptions/IncompletePromptException.java b/src/main/java/customexceptions/IncompletePromptException.java
index 9252e25a9d..770c275c06 100644
--- a/src/main/java/customexceptions/IncompletePromptException.java
+++ b/src/main/java/customexceptions/IncompletePromptException.java
@@ -2,7 +2,7 @@
public class IncompletePromptException extends Exception {
public static final String[] INSTRUCTIONS = {"add-inflow", "add-outflow", "delete-inflow", "delete-outflow",
- "login", "quit", "view-history"};
+ "login", "quit", "view-history"};
private boolean isTypo = false;
public IncompletePromptException(String line) {
int spaceIndex = line.indexOf(" ");
diff --git a/src/main/java/parser/Parser.java b/src/main/java/parser/Parser.java
index 7601a16af9..72b95ce5ff 100644
--- a/src/main/java/parser/Parser.java
+++ b/src/main/java/parser/Parser.java
@@ -20,28 +20,28 @@ public BaseCommand parseCommand(String command) throws IncompletePromptException
String[] commandParts = command.split("\\s+");
String action = commandParts[0];
switch (action) {
- case "add-inflow":
- if (commandParts.length < 3) {
- throw new IncompletePromptException(command);
- }
- return new AddInflowCommand(commandParts);
- case "add-outflow":
- if (commandParts.length < 3) {
- throw new IncompletePromptException(command);
- }
- return new AddOutflowCommand(commandParts);
- case "delete-inflow":
- case "delete-outflow":
- if (commandParts.length < 2) {
- throw new IncompletePromptException(command);
- }
- return new DeleteOutflowCommand(commandParts);
- case "view-history":
- return new ViewHistoryCommand(commandParts);
- case "quit":
- return new ExitCommand(commandParts);
- default:
+ case "add-inflow":
+ if (commandParts.length < 3) {
throw new IncompletePromptException(command);
+ }
+ return new AddInflowCommand(commandParts);
+ case "add-outflow":
+ if (commandParts.length < 3) {
+ throw new IncompletePromptException(command);
+ }
+ return new AddOutflowCommand(commandParts);
+ case "delete-inflow":
+ case "delete-outflow":
+ if (commandParts.length < 2) {
+ throw new IncompletePromptException(command);
+ }
+ return new DeleteOutflowCommand(commandParts);
+ case "view-history":
+ return new ViewHistoryCommand(commandParts);
+ case "quit":
+ return new ExitCommand(commandParts);
+ default:
+ throw new IncompletePromptException(command);
}
}
}
diff --git a/src/main/java/user/InactivityTimer.java b/src/main/java/user/InactivityTimer.java
index 76eef60bc8..430409b56b 100644
--- a/src/main/java/user/InactivityTimer.java
+++ b/src/main/java/user/InactivityTimer.java
@@ -19,8 +19,7 @@ public void checkTimeElapsed() throws InactivityTimeoutException {
long timeDifference = System.currentTimeMillis() - startTime;
if (timeDifference >= INACTIVITY_TIME) {
throw new InactivityTimeoutException(true, false);
- }
- else if (timeDifference >= GRACE_TIME) {
+ } else if (timeDifference >= GRACE_TIME) {
throw new InactivityTimeoutException(false, true);
}
}
diff --git a/src/test/java/financialtransactions/TransactionManagerTest.java b/src/test/java/financialtransactions/TransactionManagerTest.java
index e82b58baef..ef05cdc1d8 100644
--- a/src/test/java/financialtransactions/TransactionManagerTest.java
+++ b/src/test/java/financialtransactions/TransactionManagerTest.java
@@ -17,7 +17,7 @@ public void toSaveTest() {
shopping.setCategory(Outflow.Category.SHOPPING);
managerTest.addTransaction(shopping);
- assertEquals("Salary payment|400.00|May 23 2022 07:00PM|INCOME\n" +
- "Shopping|-200.00|May 23 2022 08:00PM|SHOPPING\n", managerTest.toSave());
+ assertEquals("Salary payment|400.00|May 23 2022 07:00PM|INCOME\n" +
+ "Shopping|-18.00|May 23 2022 08:00PM|SHOPPING\n", managerTest.toSave());
}
}
From 64eaaf9044a01edc7d053571c5be84feedfdafed Mon Sep 17 00:00:00 2001
From: Dylan Siew
Date: Thu, 21 Mar 2024 22:04:18 +0800
Subject: [PATCH 075/208] please work
---
text-ui-test/data/data.txt | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/text-ui-test/data/data.txt b/text-ui-test/data/data.txt
index 7e1badc063..1e8c2694d8 100644
--- a/text-ui-test/data/data.txt
+++ b/text-ui-test/data/data.txt
@@ -1,3 +1,3 @@
-Salary|400.00|May 23 2022 07:00PM|INCOME
Stocks|400.00|Oct 24 2024 12:00PM|INVESTMENT
-Rent|-1500.00|Jun 23 2023 06:00PM|RENT
+Refund|100.00|Jun 23 2023 05:00PM|REFUND
+Groceries|-150.00|Jun 23 2023 06:30PM|SHOPPING
From 7555d83e2f6e6fd0af259e89b06c987d5bb3211a Mon Sep 17 00:00:00 2001
From: dylansiew <88567790+dylansiew@users.noreply.github.com>
Date: Thu, 21 Mar 2024 22:09:56 +0800
Subject: [PATCH 076/208] error in printing
---
src/main/java/template/BaseDate.java | 3 ---
1 file changed, 3 deletions(-)
diff --git a/src/main/java/template/BaseDate.java b/src/main/java/template/BaseDate.java
index 094f26264c..8b48f0b794 100644
--- a/src/main/java/template/BaseDate.java
+++ b/src/main/java/template/BaseDate.java
@@ -44,9 +44,6 @@ public BaseDate(String args) {
}
}
- if (dateTime == null) {
- System.out.println("Incorrect Format");
- }
}
private static ArrayList dateTimeVary() {
From d22e4f9f6786a68f41ef0b5d93db126484304332 Mon Sep 17 00:00:00 2001
From: Kishen271828
Date: Thu, 21 Mar 2024 22:22:39 +0800
Subject: [PATCH 077/208] Add assertions for command classes
---
src/main/java/command/DeleteInflowCommand.java | 2 +-
src/main/java/command/DeleteOutflowCommand.java | 2 +-
src/main/java/command/EditInflowCommand.java | 1 +
src/main/java/command/EditOutflowCommand.java | 1 +
4 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/src/main/java/command/DeleteInflowCommand.java b/src/main/java/command/DeleteInflowCommand.java
index 54dc063246..942f58804c 100644
--- a/src/main/java/command/DeleteInflowCommand.java
+++ b/src/main/java/command/DeleteInflowCommand.java
@@ -14,7 +14,7 @@ public String execute(TransactionManager manager) throws Exception {
inflowIndex = part.substring(2);
}
}
- assert inflowIndex != null;
+ assert inflowIndex != null : "inflowIndex should not be null";
manager.removeInflow(Integer.parseInt(inflowIndex));
return "Ok. Inflow deleted";
}
diff --git a/src/main/java/command/DeleteOutflowCommand.java b/src/main/java/command/DeleteOutflowCommand.java
index 2b18a9e229..615c8e015e 100644
--- a/src/main/java/command/DeleteOutflowCommand.java
+++ b/src/main/java/command/DeleteOutflowCommand.java
@@ -14,7 +14,7 @@ public String execute(TransactionManager manager) throws Exception {
outflowIndex = part.substring(2);
}
}
- assert outflowIndex != null;
+ assert outflowIndex != null : "outflowIndex should not be null";
manager.removeOutflow(Integer.parseInt(outflowIndex));
return "Ok. Outflow deleted";
}
diff --git a/src/main/java/command/EditInflowCommand.java b/src/main/java/command/EditInflowCommand.java
index 1cb7c0f1b0..860c4a4f59 100644
--- a/src/main/java/command/EditInflowCommand.java
+++ b/src/main/java/command/EditInflowCommand.java
@@ -34,6 +34,7 @@ public String execute(TransactionManager manager) throws Exception {
String inflowDateTime = inflowDate + " " + inflowTime;
Inflow updatedInflow = new Inflow(inflowName, inflowAmount, inflowDateTime);
+ assert inflowCategory != null : "inflowCategory should not be null";
updatedInflow.setCategory(Inflow.Category.valueOf(inflowCategory.toUpperCase()));
manager.editInflow(inflowIndex, updatedInflow);
return "Ok. Edited inflow";
diff --git a/src/main/java/command/EditOutflowCommand.java b/src/main/java/command/EditOutflowCommand.java
index f13e78e418..29dbe8bf61 100644
--- a/src/main/java/command/EditOutflowCommand.java
+++ b/src/main/java/command/EditOutflowCommand.java
@@ -34,6 +34,7 @@ public String execute(TransactionManager manager) throws Exception {
String outflowDateTime = outflowDate + " " + outflowTime;
Outflow updatedOutflow = new Outflow(outflowName, outflowAmount, outflowDateTime);
+ assert outflowCategory != null : "outflowCategory should not be null";
updatedOutflow.setCategory(Outflow.Category.valueOf(outflowCategory.toUpperCase()));
manager.editOutflow(outflowIndex, updatedOutflow);
return "Ok. Edited outflow";
From 30e496c258d1b476bec97a692ae903e2c708aedd Mon Sep 17 00:00:00 2001
From: Kishen271828
Date: Thu, 21 Mar 2024 22:35:47 +0800
Subject: [PATCH 078/208] Change back input format for edit and add outflow
command, modify help command
---
src/main/java/command/AddOutflowCommand.java | 2 +-
src/main/java/command/EditOutflowCommand.java | 2 +-
src/main/java/command/HelpCommand.java | 14 +++++++-------
3 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/src/main/java/command/AddOutflowCommand.java b/src/main/java/command/AddOutflowCommand.java
index 739c0e16b6..c8de2a708b 100644
--- a/src/main/java/command/AddOutflowCommand.java
+++ b/src/main/java/command/AddOutflowCommand.java
@@ -17,7 +17,7 @@ public String execute(TransactionManager manager) {
String outflowCategory = null;
for (String part : commandParts) {
- if (part.startsWith("r/")) {
+ if (part.startsWith("n/")) {
outflowName = part.substring(2);
} else if (part.startsWith("a/")) {
outflowAmount = Double.parseDouble(part.substring(2));
diff --git a/src/main/java/command/EditOutflowCommand.java b/src/main/java/command/EditOutflowCommand.java
index 29dbe8bf61..542f45d076 100644
--- a/src/main/java/command/EditOutflowCommand.java
+++ b/src/main/java/command/EditOutflowCommand.java
@@ -19,7 +19,7 @@ public String execute(TransactionManager manager) throws Exception {
for (String part : commandParts) {
if (part.startsWith("i/")) {
outflowIndex = Integer.parseInt(part.substring(2));
- } else if (part.startsWith("r/")) {
+ } else if (part.startsWith("n/")) {
outflowName = part.substring(2);
} else if (part.startsWith("a/")) {
outflowAmount = Double.parseDouble(part.substring(2));
diff --git a/src/main/java/command/HelpCommand.java b/src/main/java/command/HelpCommand.java
index 3489428200..a0d3ed134f 100644
--- a/src/main/java/command/HelpCommand.java
+++ b/src/main/java/command/HelpCommand.java
@@ -11,13 +11,13 @@ public HelpCommand(String[] commandParts) {
public String execute(TransactionManager manager) throws Exception {
String baseString = "";
baseString += "Here are the available commands: \n";
- baseString += "1) add-inflow n/ a/ d/ t/ c/\n";
- baseString += "2) add-outflow n/ a/ d/ t/ c/\n";
- baseString += "3) delete-inflow i/\n";
- baseString += "4) delete-outflow i/\n";
- baseString += "5) edit-inflow i/ n/ a/ d/ t/ c/\n";
- baseString += "6) edit-outflow i/ n/ a/ d/ t/ c/\n";
- baseString += "7) view-history INDEX \n";
+ baseString += "1) add-inflow n/NAME a/AMOUNT d/DATE t/TIME c/CATEGORY\n";
+ baseString += "2) add-outflow n/NAME a/AMOUNT d/DATE t/TIME c/CATEGORY\n";
+ baseString += "3) delete-inflow i/INDEX\n";
+ baseString += "4) delete-outflow i/INDEX\n";
+ baseString += "5) edit-inflow i/INDEX n/NAME a/AMOUNT d/DATE t/TIME c/CATEGORY\n";
+ baseString += "6) edit-outflow i/INDEX n/NAME a/AMOUNT d/DATE t/TIME c/CATEGORY\n";
+ baseString += "7) view-history n/NUM \n";
baseString += "8) quit \n";
baseString += "_____________";
return baseString;
From 8ce45ff0d14283bc2499fbc9d26046f11fef819c Mon Sep 17 00:00:00 2001
From: Kishen271828
Date: Thu, 21 Mar 2024 22:58:35 +0800
Subject: [PATCH 079/208] Modify input.txt
---
text-ui-test/input.txt | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt
index 6fd5fce837..8e33dfd304 100644
--- a/text-ui-test/input.txt
+++ b/text-ui-test/input.txt
@@ -1,15 +1,15 @@
Bob
password
add-inflow n/Salary a/400.00 d/23/05/2022 t/1900 c/income
-add-outflow r/Rent a/1500.00 d/23/06/2023 t/1800 c/rent
+add-outflow n/Rent a/1500.00 d/23/06/2023 t/1800 c/rent
add-inflow n/Stocks a/400.00 d/24/10/2024 t/1200 c/investment
view-history n/2
-add-outflow r/Groceries a/100.00 d/23/06/2023 t/1800 c/shopping
+add-outflow n/Groceries a/100.00 d/23/06/2023 t/1800 c/shopping
add-inflow n/Refund a/50.00 d/23/06/2023 t/1800 c/refund
view-history n/5
delete-inflow i/3
delete-outflow i/2
edit-inflow i/1 n/Refund a/100.00 d/23/06/2023 t/1700 c/refund
-edit-outflow i/1 r/Groceries a/150.00 d/23/06/2023 t/1830 c/shopping
+edit-outflow i/1 n/Groceries a/150.00 d/23/06/2023 t/1830 c/shopping
view-history n/3
quit
From 7adf321827eadf82e5e721704f5c1a40bd507cbf Mon Sep 17 00:00:00 2001
From: Kishen271828
Date: Thu, 21 Mar 2024 23:12:02 +0800
Subject: [PATCH 080/208] Fix load from data issues
---
src/main/java/financeproject/Main.java | 7 ++-----
src/main/java/financialtransactions/TransactionList.java | 1 -
2 files changed, 2 insertions(+), 6 deletions(-)
diff --git a/src/main/java/financeproject/Main.java b/src/main/java/financeproject/Main.java
index 90de670be6..6abb177438 100644
--- a/src/main/java/financeproject/Main.java
+++ b/src/main/java/financeproject/Main.java
@@ -14,8 +14,7 @@
public class Main {
public static void main(String[] args) {
Storage storage = new Storage("./data");
- TransactionManager manager;
- manager = storage.loadFile();
+ TransactionManager manager = new TransactionManager();
UI ui = new UI();
ui.printMessage("Welcome. Enter your username and password to login.");
@@ -34,7 +33,7 @@ public static void main(String[] args) {
return;
} else {
ui.printMessage("Password is correct. You are now logged in");
- manager = new TransactionManager();
+ manager = storage.loadFile();
}
do {
@@ -62,7 +61,6 @@ public static void main(String[] args) {
inactivityTimer.checkTimeElapsed();
} catch (InactivityTimeoutException e) {
if (e.isTimeOut()) {
- //parser.setIsContinue(false);
assert baseCommand != null;
baseCommand.setIsExit(true);
} else if (e.isGracePeriod()) {
@@ -74,7 +72,6 @@ public static void main(String[] args) {
inactivityTimer.resetTimer();
} else if (wantToContinue.equalsIgnoreCase("n") ||
wantToContinue.equalsIgnoreCase("no")) {
- //parser.setIsContinue(false);
System.out.println("Session ended. ");
assert baseCommand != null;
baseCommand.setIsExit(true);
diff --git a/src/main/java/financialtransactions/TransactionList.java b/src/main/java/financialtransactions/TransactionList.java
index 4a1be88b35..cfef75be56 100644
--- a/src/main/java/financialtransactions/TransactionList.java
+++ b/src/main/java/financialtransactions/TransactionList.java
@@ -33,7 +33,6 @@ public boolean addTransaction(T newTransaction){
}
public boolean removeTransactionIndex (int index) throws Exception{
- //printTransactionsSafeInfo();
transactionList.remove(index);
return true;
}
From a58ba0bbf15ecb0f31f27051fec6a2d7a2f83c4f Mon Sep 17 00:00:00 2001
From: ChongXern
Date: Fri, 22 Mar 2024 11:00:04 +0800
Subject: [PATCH 081/208] Fix typo exception
---
data/data.txt | 3 ---
.../customexceptions/IncompletePromptException.java | 3 +--
.../financialtransactions/TransactionManager.java | 12 ++++++------
src/main/java/parser/Parser.java | 3 ++-
src/main/java/user/InactivityTimer.java | 3 +--
5 files changed, 10 insertions(+), 14 deletions(-)
diff --git a/data/data.txt b/data/data.txt
index b0693d7a6e..e69de29bb2 100644
--- a/data/data.txt
+++ b/data/data.txt
@@ -1,3 +0,0 @@
-Stocks|400.00|Oct 24 2024 12:00PM|INVESTMENT
-Stocks|400.00|Oct 24 2024 12:00PM|INVESTMENT
-Stocks|400.00|Oct 24 2024 12:00PM|INVESTMENT
diff --git a/src/main/java/customexceptions/IncompletePromptException.java b/src/main/java/customexceptions/IncompletePromptException.java
index 7039ad5b4c..5445d653ff 100644
--- a/src/main/java/customexceptions/IncompletePromptException.java
+++ b/src/main/java/customexceptions/IncompletePromptException.java
@@ -4,8 +4,7 @@
public class IncompletePromptException extends Exception {
public static final String[] INSTRUCTIONS = {
- "add-inflow", "add-outflow", "delete-inflow", "delete-outflow",
- "login", "quit", "view-history"};
+ "add-inflow", "add-outflow", "delete-inflow", "delete-outflow", "quit"};
private boolean isTypo = false;
private boolean isIncomplete = false;
private boolean isUnknown = false;
diff --git a/src/main/java/financialtransactions/TransactionManager.java b/src/main/java/financialtransactions/TransactionManager.java
index 8355be5360..aebdb9e910 100644
--- a/src/main/java/financialtransactions/TransactionManager.java
+++ b/src/main/java/financialtransactions/TransactionManager.java
@@ -79,31 +79,31 @@ public String toString() {
return "Inflows:\n" + inflows.toString() + "\nOutflows:\n" + outflows.toString();
}
- public String showLastNTransactions(int n) throws Exception{
+ public String showLastNTransactions(int n) throws Exception {
int listSize = transactionList.getTransactionListSize();
if (n > listSize) {
throw new Exception("Invalid index");
}
int index = 1;
- String returnedText = "Inflows:\nTransactions:\n";
+ StringBuilder returnedText = new StringBuilder("Inflows:\nTransactions:\n");
for (int i = listSize - 1; i > listSize - n - 1; i--) {
Transaction> transaction = transactionList.getNthTransaction(i);
if (transaction instanceof Inflow) {
- returnedText += String.format("%d) %s\n", index, transactionList.getNthTransaction(i).toString());
+ returnedText.append(String.format("%d) %s\n", index, transactionList.getNthTransaction(i).toString()));
index++;
}
}
index = 1;
- returnedText += "\nOutflows:\nTransactions:\n";
+ returnedText.append("\nOutflows:\nTransactions:\n");
for (int i = listSize - 1; i > listSize - n - 1; i--) {
Transaction> transaction = transactionList.getNthTransaction(i);
if (transaction instanceof Outflow) {
- returnedText += String.format("%d) %s\n", index, transactionList.getNthTransaction(i).toString());
+ returnedText.append(String.format("%d) %s\n", index, transactionList.getNthTransaction(i).toString()));
index++;
}
}
- return returnedText;
+ return returnedText.toString();
}
public String toSave() {
diff --git a/src/main/java/parser/Parser.java b/src/main/java/parser/Parser.java
index 313c133213..6f0c02ef94 100644
--- a/src/main/java/parser/Parser.java
+++ b/src/main/java/parser/Parser.java
@@ -64,7 +64,8 @@ public BaseCommand parseCommand(String command) throws IncompletePromptException
case "quit":
return new ExitCommand(commandParts);
default:
- throw new Exception("Invalid command");
+ throw new IncompletePromptException(command);
+ // throw new Exception("Invalid command");
}
}
}
diff --git a/src/main/java/user/InactivityTimer.java b/src/main/java/user/InactivityTimer.java
index 9c474fcb6f..4d4ef1dc2e 100644
--- a/src/main/java/user/InactivityTimer.java
+++ b/src/main/java/user/InactivityTimer.java
@@ -21,8 +21,7 @@ public void checkTimeElapsed() throws InactivityTimeoutException {
if (timeDifference >= INACTIVITY_TIME) {
System.out.println("Sorry, your session has ended. Please log in again.");
throw new InactivityTimeoutException(true, false);
- }
- else if (timeDifference >= INACTIVITY_TIME - GRACE_TIME) {
+ } else if (timeDifference >= INACTIVITY_TIME - GRACE_TIME) {
throw new InactivityTimeoutException(false, true);
}
}
From ac44b10dab29b22c74fdd568050ace364d36e452 Mon Sep 17 00:00:00 2001
From: ChongXern
Date: Fri, 22 Mar 2024 11:13:19 +0800
Subject: [PATCH 082/208] Add negative to outflow in transaction file
To satisfy Gradle requirements
---
src/main/java/financialtransactions/Transaction.java | 3 +++
1 file changed, 3 insertions(+)
diff --git a/src/main/java/financialtransactions/Transaction.java b/src/main/java/financialtransactions/Transaction.java
index 5f4f7e7c8a..c7c444a031 100644
--- a/src/main/java/financialtransactions/Transaction.java
+++ b/src/main/java/financialtransactions/Transaction.java
@@ -42,6 +42,9 @@ public String toString() {
}
public String toSave() {
+ if (this instanceof Outflow) {
+ amount *= -1;
+ }
return String.format("%s|%.2f|%s|%s\n", name, amount, date.toString(), category);
}
}
From b487ababcfacb04a459b8d5dbbdb9122ad51caba Mon Sep 17 00:00:00 2001
From: ChongXern
Date: Fri, 22 Mar 2024 11:14:59 +0800
Subject: [PATCH 083/208] Revert "Add negative to outflow in transaction file"
This reverts commit ac44b10dab29b22c74fdd568050ace364d36e452.
---
src/main/java/financialtransactions/Transaction.java | 3 ---
1 file changed, 3 deletions(-)
diff --git a/src/main/java/financialtransactions/Transaction.java b/src/main/java/financialtransactions/Transaction.java
index c7c444a031..5f4f7e7c8a 100644
--- a/src/main/java/financialtransactions/Transaction.java
+++ b/src/main/java/financialtransactions/Transaction.java
@@ -42,9 +42,6 @@ public String toString() {
}
public String toSave() {
- if (this instanceof Outflow) {
- amount *= -1;
- }
return String.format("%s|%.2f|%s|%s\n", name, amount, date.toString(), category);
}
}
From 855fd3e37c8dd9e1d6edbe4b344d2c7aa9d61d4b Mon Sep 17 00:00:00 2001
From: Kishen271828
Date: Sat, 23 Mar 2024 11:36:57 +0800
Subject: [PATCH 084/208] Add more JUnit test cases for ParserTest
---
src/test/java/parser/ParserTest.java | 25 ++++++++++++++++++++++---
1 file changed, 22 insertions(+), 3 deletions(-)
diff --git a/src/test/java/parser/ParserTest.java b/src/test/java/parser/ParserTest.java
index e023619f2d..3fdb0828ec 100644
--- a/src/test/java/parser/ParserTest.java
+++ b/src/test/java/parser/ParserTest.java
@@ -1,22 +1,41 @@
package parser;
+import command.BaseCommand;
+import financialtransactions.TransactionManager;
import org.junit.jupiter.api.Test;
import command.AddInflowCommand;
import command.AddOutflowCommand;
import userinterface.UI;
-import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.*;
public class ParserTest {
+ Parser parser = new Parser();
+ TransactionManager manager = new TransactionManager();
+
+ @Test
+ public void addInflow_success() throws Exception {
+ String command = "add-inflow n/Stocks a/700 d/28/07/2019 t/1300 c/investment";
+ BaseCommand test1 = parser.parseCommand(command, manager);
+ assertEquals("Ok. Added inflow", test1.execute(manager));
+ }
+
+ @Test
+ public void addOutflow_success() throws Exception {
+ String command = "add-outflow n/Rent a/2000 d/29/09/2021 t/1100 c/rent";
+ BaseCommand test1 = parser.parseCommand(command, manager);
+ assertEquals("Ok. Added outflow", test1.execute(manager));
+ }
+
@Test
public void sampleTest() throws Exception{
UI ui = new UI();
Parser parser = new Parser(ui);
String assert1 = "add-inflow n/Salary a/400.00 d/23/05/2022 t/1900 c/income";
String assert2 = "add-outflow n/Rent a/1500.00 d/23/06/2023 t/1800 c/rent\n";
- assertTrue(parser.parseCommand(assert1) instanceof AddInflowCommand);
- assertTrue(parser.parseCommand(assert2) instanceof AddOutflowCommand);
+ assertInstanceOf(AddInflowCommand.class, parser.parseCommand(assert1));
+ assertInstanceOf(AddOutflowCommand.class, parser.parseCommand(assert2));
}
}
From 7c1aae21c64d486b0ecebd9f51510293910b15d2 Mon Sep 17 00:00:00 2001
From: ChongXern
Date: Sun, 24 Mar 2024 18:17:07 +0800
Subject: [PATCH 085/208] Rename SecurityException to ExceededAttemptsException
To avoid confusion with another similarly named exception
---
.../ExceededAttemptsException.java | 11 +++++++++++
.../java/customexceptions/SecurityException.java | 4 ----
src/main/java/financeproject/Main.java | 8 ++++----
src/main/java/financeproject/data/data.txt | 0
src/main/java/financialtransactions/Outflow.java | 3 +--
src/main/java/user/Authentication.java | 14 +++++---------
src/test/java/user/BaseUserTest.java | 4 ++--
7 files changed, 23 insertions(+), 21 deletions(-)
create mode 100644 src/main/java/customexceptions/ExceededAttemptsException.java
delete mode 100644 src/main/java/customexceptions/SecurityException.java
create mode 100644 src/main/java/financeproject/data/data.txt
diff --git a/src/main/java/customexceptions/ExceededAttemptsException.java b/src/main/java/customexceptions/ExceededAttemptsException.java
new file mode 100644
index 0000000000..0e9c363ffb
--- /dev/null
+++ b/src/main/java/customexceptions/ExceededAttemptsException.java
@@ -0,0 +1,11 @@
+package customexceptions;
+
+public class ExceededAttemptsException extends Exception {
+ private boolean canTryAgain;
+ public ExceededAttemptsException(boolean canTryAgain) {
+ this.canTryAgain = canTryAgain;
+ }
+ public boolean isCanTryAgain() {
+ return this.canTryAgain;
+ }
+}
diff --git a/src/main/java/customexceptions/SecurityException.java b/src/main/java/customexceptions/SecurityException.java
deleted file mode 100644
index 17be091a0d..0000000000
--- a/src/main/java/customexceptions/SecurityException.java
+++ /dev/null
@@ -1,4 +0,0 @@
-package customexceptions;
-
-public class SecurityException extends Exception {
-}
diff --git a/src/main/java/financeproject/Main.java b/src/main/java/financeproject/Main.java
index a74635bb45..3491ecb99f 100644
--- a/src/main/java/financeproject/Main.java
+++ b/src/main/java/financeproject/Main.java
@@ -1,19 +1,19 @@
package financeproject;
-import customexceptions.InactivityTimeoutException;
import command.BaseCommand;
+import customexceptions.ExceededAttemptsException;
+import customexceptions.InactivityTimeoutException;
import customexceptions.IncompletePromptException;
-import customexceptions.SecurityException;
import financialtransactions.TransactionManager;
import parser.Parser;
import storage.Storage;
-import user.InactivityTimer;
import user.Authentication;
import user.BaseUser;
+import user.InactivityTimer;
import userinterface.UI;
public class Main {
- public static void main(String[] args) throws SecurityException {
+ public static void main(String[] args) throws SecurityException, ExceededAttemptsException {
Storage storage = new Storage("./data");
TransactionManager manager = new TransactionManager();
diff --git a/src/main/java/financeproject/data/data.txt b/src/main/java/financeproject/data/data.txt
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/src/main/java/financialtransactions/Outflow.java b/src/main/java/financialtransactions/Outflow.java
index 7e2c24d77b..9de71784aa 100644
--- a/src/main/java/financialtransactions/Outflow.java
+++ b/src/main/java/financialtransactions/Outflow.java
@@ -6,8 +6,7 @@ public enum Category {
}
public Outflow(String name, double amount, String date) {
- super(name, -1.00 * amount, date);
- //super.transactionType = "O";
+ super(name, /*-1.00 * */amount, date);
super.amount = amount;
}
diff --git a/src/main/java/user/Authentication.java b/src/main/java/user/Authentication.java
index 070184795c..76d5e1924f 100644
--- a/src/main/java/user/Authentication.java
+++ b/src/main/java/user/Authentication.java
@@ -1,6 +1,6 @@
package user;
-import customexceptions.SecurityException;
+import customexceptions.ExceededAttemptsException;
import userinterface.UI;
public class Authentication {
@@ -21,18 +21,16 @@ public String getUsername() {
return this.username;
}
- public boolean checkPassword(String username, String password) throws SecurityException {
+ public boolean checkPassword(String username, String password) throws ExceededAttemptsException {
boolean isMatch = this.password.equals(password) && this.username.equals(username);
if (!isMatch) {
wrongAttempts++;
- if (wrongAttempts == 3) {
- throw new SecurityException();
- }
+ throw new ExceededAttemptsException(wrongAttempts <= 3);
}
return isMatch;
}
- public boolean changePassword(String username, String oldPassword, String newPassword) throws SecurityException {
+ public boolean changePassword(String username, String oldPassword, String newPassword) throws SecurityException, ExceededAttemptsException {
if (!checkPassword(username, oldPassword)) {
return false;
}
@@ -40,13 +38,11 @@ public boolean changePassword(String username, String oldPassword, String newPas
return true;
}
- public boolean authenticate() throws SecurityException {
+ public boolean authenticate() throws ExceededAttemptsException {
System.out.println("username: ");
String inputUsername = this.ui.readInput();
System.out.println("password: ");
String inputPassword = this.ui.readInput();
return this.checkPassword(inputUsername, inputPassword);
}
-
-
}
diff --git a/src/test/java/user/BaseUserTest.java b/src/test/java/user/BaseUserTest.java
index a1d8d36c2e..c8f6ffc985 100644
--- a/src/test/java/user/BaseUserTest.java
+++ b/src/test/java/user/BaseUserTest.java
@@ -1,6 +1,6 @@
package user;
-import customexceptions.SecurityException;
+import customexceptions.ExceededAttemptsException;
import org.junit.jupiter.api.Test;
import userinterface.UI;
@@ -9,7 +9,7 @@
public class BaseUserTest {
@Test
- public void sampleTest() throws SecurityException {
+ public void sampleTest() throws ExceededAttemptsException {
UI ui = new UI();
BaseUser user = new BaseUser("Bob", ui);
Authentication auth = user.getAuthentication();
From 8578ef2c71a038ff44e9461eff2a98e89bd99157 Mon Sep 17 00:00:00 2001
From: ChongXern
Date: Sun, 24 Mar 2024 19:14:41 +0800
Subject: [PATCH 086/208] Fix Gradle transaction manager test error
---
.../java/financialtransactions/Outflow.java | 3 +--
.../TransactionManager.java | 20 +++++++++----------
src/main/java/user/Authentication.java | 3 ++-
.../financialtransactions/OutflowTest.java | 2 ++
.../TransactionManagerTest.java | 8 ++++----
5 files changed, 19 insertions(+), 17 deletions(-)
diff --git a/src/main/java/financialtransactions/Outflow.java b/src/main/java/financialtransactions/Outflow.java
index 9de71784aa..dd952fada6 100644
--- a/src/main/java/financialtransactions/Outflow.java
+++ b/src/main/java/financialtransactions/Outflow.java
@@ -6,8 +6,7 @@ public enum Category {
}
public Outflow(String name, double amount, String date) {
- super(name, /*-1.00 * */amount, date);
- super.amount = amount;
+ super(name, -1.00 * amount, date);
}
public void setCategory(Category category) {
diff --git a/src/main/java/financialtransactions/TransactionManager.java b/src/main/java/financialtransactions/TransactionManager.java
index aebdb9e910..10ff44d293 100644
--- a/src/main/java/financialtransactions/TransactionManager.java
+++ b/src/main/java/financialtransactions/TransactionManager.java
@@ -17,7 +17,7 @@ public boolean addTransaction(Transaction> transaction) {
if (transaction instanceof Inflow) {
Inflow inflow = (Inflow) transaction;
return inflows.addTransaction(inflow);
- }
+ }
if (transaction instanceof Outflow) {
Outflow outflow = (Outflow) transaction;
return outflows.addTransaction(outflow);
@@ -56,7 +56,7 @@ public boolean editInflow(int index, Transaction> updatedTransaction) throws E
int numOfInflows = inflows.getTransactionListSize();
Transaction> transactionEdited = inflows.getNthTransaction(numOfInflows - index);
transactionList.editTransactionIndex(transactionList.getIndexOfParticularTransaction(transactionEdited),
- updatedTransaction);
+ updatedTransaction);
return inflows.editTransactionIndex(numOfInflows - index, (Inflow) updatedTransaction);
}
@@ -64,7 +64,7 @@ public boolean editOutflow(int index, Transaction> updatedTransaction) throws
int numOfOutflows = outflows.getTransactionListSize();
Transaction> transactionEdited = outflows.getNthTransaction(numOfOutflows - index);
transactionList.editTransactionIndex(transactionList.getIndexOfParticularTransaction(transactionEdited),
- updatedTransaction);
+ updatedTransaction);
return outflows.editTransactionIndex(numOfOutflows - index, (Outflow) updatedTransaction);
}
@@ -79,34 +79,34 @@ public String toString() {
return "Inflows:\n" + inflows.toString() + "\nOutflows:\n" + outflows.toString();
}
- public String showLastNTransactions(int n) throws Exception {
+ public String showLastNTransactions(int n) throws Exception{
int listSize = transactionList.getTransactionListSize();
if (n > listSize) {
throw new Exception("Invalid index");
}
int index = 1;
- StringBuilder returnedText = new StringBuilder("Inflows:\nTransactions:\n");
+ String returnedText = "Inflows:\nTransactions:\n";
for (int i = listSize - 1; i > listSize - n - 1; i--) {
Transaction> transaction = transactionList.getNthTransaction(i);
if (transaction instanceof Inflow) {
- returnedText.append(String.format("%d) %s\n", index, transactionList.getNthTransaction(i).toString()));
+ returnedText += String.format("%d) %s\n", index, transactionList.getNthTransaction(i).toString());
index++;
}
}
index = 1;
- returnedText.append("\nOutflows:\nTransactions:\n");
+ returnedText += "\nOutflows:\nTransactions:\n";
for (int i = listSize - 1; i > listSize - n - 1; i--) {
Transaction> transaction = transactionList.getNthTransaction(i);
if (transaction instanceof Outflow) {
- returnedText.append(String.format("%d) %s\n", index, transactionList.getNthTransaction(i).toString()));
+ returnedText += String.format("%d) %s\n", index, transactionList.getNthTransaction(i).toString());
index++;
}
}
- return returnedText.toString();
+ return returnedText;
}
public String toSave() {
return inflows.toSave() + outflows.toSave();
}
-}
+}
\ No newline at end of file
diff --git a/src/main/java/user/Authentication.java b/src/main/java/user/Authentication.java
index 76d5e1924f..0e6673dfe7 100644
--- a/src/main/java/user/Authentication.java
+++ b/src/main/java/user/Authentication.java
@@ -30,7 +30,8 @@ public boolean checkPassword(String username, String password) throws ExceededAt
return isMatch;
}
- public boolean changePassword(String username, String oldPassword, String newPassword) throws SecurityException, ExceededAttemptsException {
+ public boolean changePassword(String username, String oldPassword, String newPassword)
+ throws SecurityException, ExceededAttemptsException {
if (!checkPassword(username, oldPassword)) {
return false;
}
diff --git a/src/test/java/financialtransactions/OutflowTest.java b/src/test/java/financialtransactions/OutflowTest.java
index f100a80573..7a50116c85 100644
--- a/src/test/java/financialtransactions/OutflowTest.java
+++ b/src/test/java/financialtransactions/OutflowTest.java
@@ -10,5 +10,7 @@ public void testSetCategory() {
Outflow outflow = new Outflow("2024 Sem 2 School Fees", 999999.99, "2024-02-01");
outflow.setCategory(Outflow.Category.EDUCATION);
assertEquals(Outflow.Category.EDUCATION, outflow.getCategory());
+ assertEquals(-999999.99, outflow.getAmount());
+
}
}
diff --git a/src/test/java/financialtransactions/TransactionManagerTest.java b/src/test/java/financialtransactions/TransactionManagerTest.java
index 2ea69d6da3..ddf2527a78 100644
--- a/src/test/java/financialtransactions/TransactionManagerTest.java
+++ b/src/test/java/financialtransactions/TransactionManagerTest.java
@@ -8,7 +8,7 @@ public class TransactionManagerTest {
@Test
public void toSaveTest() {
TransactionManager managerTest = new TransactionManager();
-
+
Inflow income = new Inflow("Salary payment", 400.00, "23/05/2022 1900");
income.setCategory(Inflow.Category.INCOME);
managerTest.addTransaction(income);
@@ -16,8 +16,8 @@ public void toSaveTest() {
Outflow shopping = new Outflow("Shopping", 200, "23/05/2022 2000");
shopping.setCategory(Outflow.Category.SHOPPING);
managerTest.addTransaction(shopping);
-
+
assertEquals("Salary payment|400.00|May 23 2022 07:00PM|INCOME\n" +
- "Shopping|-200.00|May 23 2022 08:00PM|SHOPPING\n", managerTest.toSave());
+ "Shopping|-200.00|May 23 2022 08:00PM|SHOPPING\n", managerTest.toSave());
}
-}
+}
\ No newline at end of file
From 21cd082ede32828ca8b575d6a70048f5c7387ada Mon Sep 17 00:00:00 2001
From: ChongXern
Date: Sun, 24 Mar 2024 19:52:06 +0800
Subject: [PATCH 087/208] Add three attempts for username and password feature
---
src/main/java/financeproject/Main.java | 25 +++++++++++++++----
.../TransactionManager.java | 2 +-
src/main/java/user/Authentication.java | 16 +++++++++++-
3 files changed, 36 insertions(+), 7 deletions(-)
diff --git a/src/main/java/financeproject/Main.java b/src/main/java/financeproject/Main.java
index 3491ecb99f..806d254534 100644
--- a/src/main/java/financeproject/Main.java
+++ b/src/main/java/financeproject/Main.java
@@ -27,14 +27,29 @@ public static void main(String[] args) throws SecurityException, ExceededAttempt
BaseUser tempUser = new BaseUser("Bob", ui);
Authentication auth = tempUser.getAuthentication();
InactivityTimer inactivityTimer = new InactivityTimer();
+ boolean isAuthenticated = false;
- if (!auth.authenticate()) {
- ui.printMessage("Authentication error");
+ while (!isAuthenticated && auth.getWrongAttempts() < 3) {
+ try {
+ if (!auth.authenticate()) {
+ ui.printMessage("Authentication error");
+ } else {
+ ui.printMessage("Password is correct. You are now logged in");
+ manager = storage.loadFile();
+ isAuthenticated = true;
+ }
+ } catch (ExceededAttemptsException e) {
+ if (e.isCanTryAgain()) {
+ ui.printMessage("Incorrect username or password. Please try again.");
+ } else {
+ ui.printMessage("Too many incorrect attempts. Authentication failed.");
+ }
+ }
+ }
+
+ if (!isAuthenticated) {
ui.closeScanner();
return;
- } else {
- ui.printMessage("Password is correct. You are now logged in");
- manager = storage.loadFile();
}
do {
diff --git a/src/main/java/financialtransactions/TransactionManager.java b/src/main/java/financialtransactions/TransactionManager.java
index 10ff44d293..2f1194c8a7 100644
--- a/src/main/java/financialtransactions/TransactionManager.java
+++ b/src/main/java/financialtransactions/TransactionManager.java
@@ -109,4 +109,4 @@ public String showLastNTransactions(int n) throws Exception{
public String toSave() {
return inflows.toSave() + outflows.toSave();
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/user/Authentication.java b/src/main/java/user/Authentication.java
index 0e6673dfe7..0ee0c06dbe 100644
--- a/src/main/java/user/Authentication.java
+++ b/src/main/java/user/Authentication.java
@@ -25,7 +25,7 @@ public boolean checkPassword(String username, String password) throws ExceededAt
boolean isMatch = this.password.equals(password) && this.username.equals(username);
if (!isMatch) {
wrongAttempts++;
- throw new ExceededAttemptsException(wrongAttempts <= 3);
+ throw new ExceededAttemptsException(wrongAttempts < 3);
}
return isMatch;
}
@@ -39,11 +39,25 @@ public boolean changePassword(String username, String oldPassword, String newPas
return true;
}
+ public int getWrongAttempts() {
+ return wrongAttempts;
+ }
+
public boolean authenticate() throws ExceededAttemptsException {
System.out.println("username: ");
String inputUsername = this.ui.readInput();
System.out.println("password: ");
String inputPassword = this.ui.readInput();
+ /*try {
+ return this.checkPassword(inputUsername, inputPassword);
+ } catch (ExceededAttemptsException e) {
+ if (e.isCanTryAgain()) {
+ System.out.println("Wrong password or username, please try again.");
+ } else {
+ System.out.println("Sorry, too many incorrect attempts.");
+ }
+ return false;
+ }*/
return this.checkPassword(inputUsername, inputPassword);
}
}
From ec85f7eb358d5fea8d3ccf52c07f9f63865d5bfb Mon Sep 17 00:00:00 2001
From: ChongXern
Date: Sun, 24 Mar 2024 19:56:42 +0800
Subject: [PATCH 088/208] Add newline in TransactionManagerTest
Highly important for the entire project
---
src/test/java/financialtransactions/TransactionManagerTest.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/test/java/financialtransactions/TransactionManagerTest.java b/src/test/java/financialtransactions/TransactionManagerTest.java
index ddf2527a78..4e423eaf28 100644
--- a/src/test/java/financialtransactions/TransactionManagerTest.java
+++ b/src/test/java/financialtransactions/TransactionManagerTest.java
@@ -20,4 +20,4 @@ public void toSaveTest() {
assertEquals("Salary payment|400.00|May 23 2022 07:00PM|INCOME\n" +
"Shopping|-200.00|May 23 2022 08:00PM|SHOPPING\n", managerTest.toSave());
}
-}
\ No newline at end of file
+}
From 2eebc4c6dccf3e6f709187e2799cdc26b543065a Mon Sep 17 00:00:00 2001
From: dylansiew <88567790+dylansiew@users.noreply.github.com>
Date: Fri, 29 Mar 2024 00:21:24 +0800
Subject: [PATCH 089/208] md
---
docs/DeveloperGuide.md | 67 +++++++++++++++++++++++++++++++++++-------
1 file changed, 57 insertions(+), 10 deletions(-)
diff --git a/docs/DeveloperGuide.md b/docs/DeveloperGuide.md
index 64e1f0ed2b..360cc374d0 100644
--- a/docs/DeveloperGuide.md
+++ b/docs/DeveloperGuide.md
@@ -6,33 +6,80 @@
## Design & implementation
-{Describe the design and implementation of the product. Use UML diagrams and short code snippets where applicable.}
+The financial manager application is designed using an object-oriented approach, focusing on user authentication, transaction management, and user interaction. The core components include:
+
+- **Main Application Loop**: Handles the initialization of the application, including loading data from storage, authenticating the user, and processing user commands until the application exits.
+- **Command Pattern**: User commands are encapsulated as objects, allowing for the addition of new commands with minimal changes to existing code.
+- **Transaction Management**: Separate classes for managing inflows and outflows, with a unified interface for adding, editing, and deleting transactions.
+- **User Authentication**: Ensures that users are authenticated before accessing their financial data, with a mechanism to track and limit failed attempts.
+- **Inactivity Timer**: Automatically logs out users after a period of inactivity, enhancing security.
+- **Storage Management**: Handles the persistent storage of transaction data, allowing users to save and load their financial information.
## Product scope
### Target user profile
-{Describe the target user profile}
+The financial manager application is designed for individual users seeking a simple yet powerful tool to manage personal finances, including tracking income and expenses, and viewing transaction history.
+
### Value proposition
-{Describe the value proposition: what problem does it solve?}
+This application simplifies personal financial management by providing an intuitive interface for tracking and analyzing income and expenses. Users can easily add, edit, or delete transactions, view recent transaction history, and ensure their data is securely managed with user authentication and automatic logout features.
+
+plaintext
+Copy code
## User Stories
-|Version| As a ... | I want to ... | So that I can ...|
-|--------|----------|---------------|------------------|
-|v1.0|new user|see usage instructions|refer to them when I forget how to use the application|
-|v2.0|user|find a to-do item by name|locate a to-do without having to go through the entire list|
+|Version| As a/an ... | I want to ... | So that ...|
+|-------|-------------|---------------|------------|
+|v1.0|user|receive alerts or notifications when I exceed my budget limits for specific expense categories|I can stay within my financial goals|
+|v1.0|user|generate monthly reports summarizing my income, expenses, and budget performance|I can track my financial progress over time|
+|v1.0|user|edit or delete past transactions|I can correct any errors or update information as needed|
+|v1.0|user|search for specific transactions based on keywords, dates, or categories|I can quickly find the information I need|
+|v1.0|user|add income transactions with details such as amount, date, and category|I can keep track of my earnings|
+|v1.0|user|add expense transactions with details such as amount, date, and category|I can monitor where my money is going|
+|v1.0|user|categorize my transactions|I can organize my finances and have a clearer view of my income and expenses|
+|v1.0|user|add instalment payments into the tracker|I can track finances for big ticket purchases such as furniture/TVs|
+|v1.0|user|Use a customisable interface for my financial goals|I can adjust these financial goals accordingly as time passes|
+|v1.0|user|add payment types such as credit card, debit card or cash|I can be reminded to pay credit card bills each month|
+|v1.0|user|Be confident that my banking information is encrypted and safe from being accessed by others|The private information is not easily leaked to others|
## Non-Functional Requirements
-{Give non-functional requirements}
+1. **Security**: User authentication must be secure, with a limit on login attempts to prevent unauthorized access.
+2. **Usability**: The application should be easy to use, with clear instructions and feedback for users.
+3. **Performance**: The application should respond quickly to user inputs, with minimal delays in processing transactions.
+4. **Reliability**: Data storage should be reliable, ensuring that user data is not lost between sessions.
+
## Glossary
-* *glossary item* - Definition
+1. **Inflow** - A financial transaction representing income or money received.
+2. **Outflow** - A financial transaction representing expenses or money spent.
+
## Instructions for manual testing
-{Give instructions on how to do a manual product testing e.g., how to load sample data to be used for testing}
+### Login Procedure:
+- Start the application and enter your username and password when prompted.
+- Test incorrect passwords to ensure the application correctly limits login attempts.
+
+### Adding Transactions:
+- Use the `add-inflow` and `add-outflow` commands to add new transactions, following the command format provided in the `help` command.
+- Attempt to add transactions with missing or incorrect information to test validation.
+
+### Editing and Deleting Transactions:
+- Use the `edit-inflow` and `edit-outflow` commands to modify existing transactions.
+- Use the `delete-inflow` and `delete-outflow` commands to remove transactions.
+- Try editing or deleting transactions that do not exist to test error handling.
+
+### Viewing Transaction History:
+- Use the `view-history` command to display recent transactions.
+- Test with different numbers of transactions to view.
+
+### Inactivity Timeout:
+- After logging in, do not input any commands for the duration specified by the inactivity timer to test automatic logout.
+
+### Data Persistence:
+- Exit the application and restart it to ensure that previously entered transactions are still present.
\ No newline at end of file
From 0e928cbdcaeeb25acedcae80b6400bf47e3c77eb Mon Sep 17 00:00:00 2001
From: Kishen271828
Date: Fri, 29 Mar 2024 10:40:51 +0800
Subject: [PATCH 090/208] Add comments
---
src/main/java/command/AddInflowCommand.java | 1 +
src/main/java/command/AddOutflowCommand.java | 1 +
src/main/java/command/ViewHistoryCommand.java | 1 +
src/main/java/parser/Parser.java | 1 +
src/test/java/parser/ParserTest.java | 7 +++----
5 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/src/main/java/command/AddInflowCommand.java b/src/main/java/command/AddInflowCommand.java
index 521ce098ef..9d1b76654d 100644
--- a/src/main/java/command/AddInflowCommand.java
+++ b/src/main/java/command/AddInflowCommand.java
@@ -10,6 +10,7 @@ public AddInflowCommand(String[] commandParts) {
}
public String execute(TransactionManager manager) {
+ //@@author Kishen271828
String inflowName = null;
double inflowAmount = 0;
String inflowDate = null;
diff --git a/src/main/java/command/AddOutflowCommand.java b/src/main/java/command/AddOutflowCommand.java
index c8de2a708b..4c64b3f860 100644
--- a/src/main/java/command/AddOutflowCommand.java
+++ b/src/main/java/command/AddOutflowCommand.java
@@ -10,6 +10,7 @@ public AddOutflowCommand(String[] commandParts) {
}
public String execute(TransactionManager manager) {
+ //@@author Kishen271828
String outflowName = null;
double outflowAmount = 0.0;
String outflowDate = null;
diff --git a/src/main/java/command/ViewHistoryCommand.java b/src/main/java/command/ViewHistoryCommand.java
index 09c0223969..645bb73527 100644
--- a/src/main/java/command/ViewHistoryCommand.java
+++ b/src/main/java/command/ViewHistoryCommand.java
@@ -9,6 +9,7 @@ public ViewHistoryCommand(String[] commandParts) {
}
public String execute(TransactionManager manager) throws Exception{
+ //@@author Kishen271828
String numTransactionsString = null;
for (String part : commandParts) {
if (part.startsWith("n/")) {
diff --git a/src/main/java/parser/Parser.java b/src/main/java/parser/Parser.java
index 6f0c02ef94..a42e08e048 100644
--- a/src/main/java/parser/Parser.java
+++ b/src/main/java/parser/Parser.java
@@ -20,6 +20,7 @@ public Parser(UI ui) {
this.ui = ui;
}
+
public BaseCommand parseCommand(String command) throws IncompletePromptException, Exception {
String[] commandParts = command.split("\\s+");
String action = commandParts[0];
diff --git a/src/test/java/parser/ParserTest.java b/src/test/java/parser/ParserTest.java
index 3fdb0828ec..6c43044cfd 100644
--- a/src/test/java/parser/ParserTest.java
+++ b/src/test/java/parser/ParserTest.java
@@ -11,20 +11,20 @@
import static org.junit.jupiter.api.Assertions.*;
public class ParserTest {
- Parser parser = new Parser();
+ Parser parser = new Parser(new UI());
TransactionManager manager = new TransactionManager();
@Test
public void addInflow_success() throws Exception {
String command = "add-inflow n/Stocks a/700 d/28/07/2019 t/1300 c/investment";
- BaseCommand test1 = parser.parseCommand(command, manager);
+ BaseCommand test1 = parser.parseCommand(command);
assertEquals("Ok. Added inflow", test1.execute(manager));
}
@Test
public void addOutflow_success() throws Exception {
String command = "add-outflow n/Rent a/2000 d/29/09/2021 t/1100 c/rent";
- BaseCommand test1 = parser.parseCommand(command, manager);
+ BaseCommand test1 = parser.parseCommand(command);
assertEquals("Ok. Added outflow", test1.execute(manager));
}
@@ -36,6 +36,5 @@ public void sampleTest() throws Exception{
String assert2 = "add-outflow n/Rent a/1500.00 d/23/06/2023 t/1800 c/rent\n";
assertInstanceOf(AddInflowCommand.class, parser.parseCommand(assert1));
assertInstanceOf(AddOutflowCommand.class, parser.parseCommand(assert2));
-
}
}
From 8f8e352181797e9ba8d5b344c47aa6c35bc779e4 Mon Sep 17 00:00:00 2001
From: ChongXern
Date: Fri, 29 Mar 2024 10:51:41 +0800
Subject: [PATCH 091/208] Add name length check to ensure description is not
too long
---
src/main/java/financeproject/data/data.txt | 3 +++
src/main/java/financialtransactions/Transaction.java | 6 ++++++
2 files changed, 9 insertions(+)
diff --git a/src/main/java/financeproject/data/data.txt b/src/main/java/financeproject/data/data.txt
index e69de29bb2..6e814e4b86 100644
--- a/src/main/java/financeproject/data/data.txt
+++ b/src/main/java/financeproject/data/data.txt
@@ -0,0 +1,3 @@
+Stocks|400.00|Oct 24 2024 12:00PM|INVESTMENT
+Stocks|400.00|Oct 24 2024 12:00PM|INVESTMENT
+Stocks|400.12|Oct 24 2024 12:00PM|INVESTMENT
diff --git a/src/main/java/financialtransactions/Transaction.java b/src/main/java/financialtransactions/Transaction.java
index 5f4f7e7c8a..c4a9417bc9 100644
--- a/src/main/java/financialtransactions/Transaction.java
+++ b/src/main/java/financialtransactions/Transaction.java
@@ -7,12 +7,18 @@
public abstract class Transaction {
+ private static final int NAME_MAX_LEN = 30;
protected String name;
protected double amount;
protected BaseDate date;
protected T category;
public Transaction(String name, double amount, String date) {
+ if (name.length() > NAME_MAX_LEN) {
+ System.out.println("Sorry, the description inputted exceeds the maximum permeable length. " +
+ "Please try again.");
+ return;
+ }
this.name = name;
this.amount = amount;
if (date == null){
From 5b56e771cd955787484f68b23de1188309a7dc53 Mon Sep 17 00:00:00 2001
From: Chong Xern <104547209+ChongXern@users.noreply.github.com>
Date: Fri, 29 Mar 2024 11:04:43 +0800
Subject: [PATCH 092/208] Update DeveloperGuide.md
---
docs/DeveloperGuide.md | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/docs/DeveloperGuide.md b/docs/DeveloperGuide.md
index 360cc374d0..a372ae22ee 100644
--- a/docs/DeveloperGuide.md
+++ b/docs/DeveloperGuide.md
@@ -44,6 +44,8 @@ Copy code
|v1.0|user|Use a customisable interface for my financial goals|I can adjust these financial goals accordingly as time passes|
|v1.0|user|add payment types such as credit card, debit card or cash|I can be reminded to pay credit card bills each month|
|v1.0|user|Be confident that my banking information is encrypted and safe from being accessed by others|The private information is not easily leaked to others|
+|v2.0|user|Export my financial reports as a CSV|I can share my expenditure with my peers|
+|v2.0|user|Visualise my transactions in more meaningful diagrams|I can better understand my spending|
## Non-Functional Requirements
@@ -80,6 +82,9 @@ Copy code
### Inactivity Timeout:
- After logging in, do not input any commands for the duration specified by the inactivity timer to test automatic logout.
+- A maximum of 2.5 minutes of inactivity will trigger the application to check with the user whether the user is still active or not. Input `yes` to indicate continued activity, otherwise input `no` to exit.
+- 30 seconds after the 2.5 min (3 min), the application will automatically exit.
+- Implemented to provide enhanced security, so no third party can access finance transactions.
### Data Persistence:
-- Exit the application and restart it to ensure that previously entered transactions are still present.
\ No newline at end of file
+- Exit the application and restart it to ensure that previously entered transactions are still present.
From f7f78e411cde817a016a234be1273e0ad2f52cc3 Mon Sep 17 00:00:00 2001
From: Kishen271828
Date: Fri, 29 Mar 2024 12:43:26 +0800
Subject: [PATCH 093/208] Describe view-history feature in DG
---
docs/DeveloperGuide.md | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/docs/DeveloperGuide.md b/docs/DeveloperGuide.md
index a372ae22ee..13ccef6fb6 100644
--- a/docs/DeveloperGuide.md
+++ b/docs/DeveloperGuide.md
@@ -15,6 +15,29 @@ The financial manager application is designed using an object-oriented approach,
- **Inactivity Timer**: Automatically logs out users after a period of inactivity, enhancing security.
- **Storage Management**: Handles the persistent storage of transaction data, allowing users to save and load their financial information.
+### View Transaction History feature:
+
+#### Implementation Details:
+
+#### Functionality:
+The View History feature allows users to retrieve a list of their recent transactions, categorized as inflows and outflows. The user can specify the number of transactions they want to view, and the system presents these transactions in reverse chronological order, with the latest transactions displayed first. Each transaction is presented with its description, date, and time of occurrence.
+
+#### Design Considerations:
+- **Data Structure**: The transaction data is stored in an instance of the `TransactionList` class, which is part of the `financialtransactions` package. This list maintains a record of all transactions made by the user, ensuring easy retrieval and manipulation of transaction data.
+- **Categorization**: Transactions are categorized as inflow or outflow based on their type. This categorization enables users to differentiate between different types of financial activities, such as income and expenses.
+- **Formatting**: The transactions are presented in a formatted string, providing clear and concise information to the user. Each transaction includes its description, date, and time.
+
+#### Implementation Details:
+- The `TransactionManager#showLastNTransactions()` method is responsible for retrieving the last N transactions from the Transaction List.
+- The method iterates over the transaction list in reverse order, starting from the latest transaction and moving towards older transactions.
+- Transactions are categorized as inflows or outflows based on their instance type (Inflow or Outflow), and the relevant transactions are added to the output string accordingly.
+- The formatted string containing the transaction details is returned to the user for display.
+
+#### Alternatives Considered:
+During the development of the View Transaction History feature, several alternatives were considered to achieve the desired functionality. These alternatives included:
+
+- Implementing a more complex data structure for storing transaction history, such as a linked list. However, a simple ArrayList-based approach was chosen for its simplicity and efficiency in managing transaction data.
+- Providing additional filtering options, such as filtering transactions by date range or transaction category. While these options could definitely enhance the feature, they were deemed unnecessary for the initial implementation and may be considered for future iterations.
## Product scope
### Target user profile
From 456aeb2dbca5b93910133da7fbf3b9eb794c6735 Mon Sep 17 00:00:00 2001
From: Kishen271828
Date: Fri, 29 Mar 2024 12:49:45 +0800
Subject: [PATCH 094/208] Replace * imports with single imports in ParserTest
---
src/test/java/parser/ParserTest.java | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/test/java/parser/ParserTest.java b/src/test/java/parser/ParserTest.java
index 6c43044cfd..fdd713a44a 100644
--- a/src/test/java/parser/ParserTest.java
+++ b/src/test/java/parser/ParserTest.java
@@ -8,7 +8,8 @@
import command.AddOutflowCommand;
import userinterface.UI;
-import static org.junit.jupiter.api.Assertions.*;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
public class ParserTest {
Parser parser = new Parser(new UI());
From 1ff6af0a1d2b072be22e37b342affcb1c0fdc3a7 Mon Sep 17 00:00:00 2001
From: ChongXern
Date: Fri, 29 Mar 2024 13:21:53 +0800
Subject: [PATCH 095/208] Update DevelopersGuide.md to include a few of the
upcoming proposed features
---
docs/DeveloperGuide.md | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/docs/DeveloperGuide.md b/docs/DeveloperGuide.md
index a372ae22ee..75d0761215 100644
--- a/docs/DeveloperGuide.md
+++ b/docs/DeveloperGuide.md
@@ -3,6 +3,7 @@
## Acknowledgements
{list here sources of all reused/adapted ideas, code, documentation, and third-party libraries -- include links to the original source as well}
+- [CS2113 Course Website](https://nus-cs2113-ay2324s2.github.io/website/index.html)
## Design & implementation
@@ -14,7 +15,9 @@ The financial manager application is designed using an object-oriented approach,
- **User Authentication**: Ensures that users are authenticated before accessing their financial data, with a mechanism to track and limit failed attempts.
- **Inactivity Timer**: Automatically logs out users after a period of inactivity, enhancing security.
- **Storage Management**: Handles the persistent storage of transaction data, allowing users to save and load their financial information.
-
+- **[Proposed] Security features**: A maximum of three login attempts are inputted, failing which would cause the application to be exited automatically.
+- **[Proposed] Financial transaction visualiser**: When viewing history of transactions, the data will be visualised using bar charts for better user friendliness.
+- **[Proposed] Undo functionality**: Allows users to undo their last prompt, but only permittable 10 seconds after the last action.
## Product scope
### Target user profile
@@ -27,8 +30,6 @@ The financial manager application is designed for individual users seeking a sim
This application simplifies personal financial management by providing an intuitive interface for tracking and analyzing income and expenses. Users can easily add, edit, or delete transactions, view recent transaction history, and ensure their data is securely managed with user authentication and automatic logout features.
-plaintext
-Copy code
## User Stories
|Version| As a/an ... | I want to ... | So that ...|
@@ -65,7 +66,8 @@ Copy code
### Login Procedure:
- Start the application and enter your username and password when prompted.
-- Test incorrect passwords to ensure the application correctly limits login attempts.
+- Test incorrect passwords to ensure the application correctly limits login attempts.
+- [v2.0] If there are three incorrect attempts, the application will automatically exit and the user has to try again.
### Adding Transactions:
- Use the `add-inflow` and `add-outflow` commands to add new transactions, following the command format provided in the `help` command.
@@ -79,6 +81,7 @@ Copy code
### Viewing Transaction History:
- Use the `view-history` command to display recent transactions.
- Test with different numbers of transactions to view.
+- [v2.0] Additional bar charts will be shown to display the different percentage of categories used in the past n transactions.
### Inactivity Timeout:
- After logging in, do not input any commands for the duration specified by the inactivity timer to test automatic logout.
From e32307ca6312022e6e0e76b671b25d7f1dae4ee5 Mon Sep 17 00:00:00 2001
From: ChongXern
Date: Fri, 29 Mar 2024 14:06:42 +0800
Subject: [PATCH 096/208] Enable assertions in build.gradle
---
build.gradle | 1 +
1 file changed, 1 insertion(+)
diff --git a/build.gradle b/build.gradle
index c9098d4f82..08d9ce4e4d 100644
--- a/build.gradle
+++ b/build.gradle
@@ -44,6 +44,7 @@ checkstyle {
run{
standardInput = System.in
+ enableAssertions = true
}
From b0a290db9764abf2fa699a24cdfab56a280d8f73 Mon Sep 17 00:00:00 2001
From: chowy
Date: Fri, 29 Mar 2024 14:14:58 +0800
Subject: [PATCH 097/208] Updated DG
---
docs/DeveloperGuide.md | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/docs/DeveloperGuide.md b/docs/DeveloperGuide.md
index 13ccef6fb6..0a707c3821 100644
--- a/docs/DeveloperGuide.md
+++ b/docs/DeveloperGuide.md
@@ -39,6 +39,29 @@ During the development of the View Transaction History feature, several alternat
- Implementing a more complex data structure for storing transaction history, such as a linked list. However, a simple ArrayList-based approach was chosen for its simplicity and efficiency in managing transaction data.
- Providing additional filtering options, such as filtering transactions by date range or transaction category. While these options could definitely enhance the feature, they were deemed unnecessary for the initial implementation and may be considered for future iterations.
+### Save File feature:
+The `Storage#saveFile()` method will be called when the user decides to quit the application, the method will then get a string of all the transactions. This string will then be written to a file whose filename will be the username of the last user.
+
+#### Implementation Details:
+- The method first creates a FileWriter object.
+- It then calls `TransactionManager#toSave()`.
+ - This method is similar to `toString()`, except that it creates a string that is more storage friendly.
+ - In this method, each transaction is returned as `name|amount|date|category\n`.
+ - Each transaction is added line by line, after adding all transactions, the string is returned in the toSave() method.
+ - It is important to note that outflows are saved with a `-` in front of the amount.
+- With the string generated in the `toSave()` method, the FileWriter will write it to the file before closing it.
+
+### Load File feature:
+The `Storage#loadFile()` method will be called after the user as logged in, it will then retrieve the transactions that were written in the past sessions, so that the user can continue using the finance manger.
+
+#### Implementation Details:
+- The method first creates a File object and a Transaction Manager object.
+- If the file exists
+ - The method will read from the file line by line, splitting each line by `|`. A new inflow or outflow object will be created with those values and then added to the Transaction Manager Object.
+- If the file does not exist
+ - An empty transaction manager object will be returned.
+- To differentiate between inflow or outflow, the `-` in front of the amount will be used.
+
## Product scope
### Target user profile
From b54285083d096048b7036d038aee97316368484e Mon Sep 17 00:00:00 2001
From: ChongXern
Date: Sat, 30 Mar 2024 01:44:37 +0800
Subject: [PATCH 098/208] Add sorting by name comparator method for sorting
transactions
---
src/main/java/financeproject/data/data.txt | 8 +++--
.../TransactionList.java | 35 +++++++++++++++++--
.../TransactionManager.java | 3 ++
3 files changed, 41 insertions(+), 5 deletions(-)
diff --git a/src/main/java/financeproject/data/data.txt b/src/main/java/financeproject/data/data.txt
index 6e814e4b86..7460e56187 100644
--- a/src/main/java/financeproject/data/data.txt
+++ b/src/main/java/financeproject/data/data.txt
@@ -1,3 +1,5 @@
-Stocks|400.00|Oct 24 2024 12:00PM|INVESTMENT
-Stocks|400.00|Oct 24 2024 12:00PM|INVESTMENT
-Stocks|400.12|Oct 24 2024 12:00PM|INVESTMENT
+Salary|400.00|May 23 2022 07:00PM|INCOME
+Salara|400.00|May 23 2022 07:00PM|INCOME
+Salarz|400.00|May 23 2022 07:00PM|INCOME
+Rent|-1500.00|Jun 23 2023 06:00PM|RENT
+Rent|-1500.00|Jun 23 2023 06:00PM|RENT
diff --git a/src/main/java/financialtransactions/TransactionList.java b/src/main/java/financialtransactions/TransactionList.java
index cfef75be56..aa457256bf 100644
--- a/src/main/java/financialtransactions/TransactionList.java
+++ b/src/main/java/financialtransactions/TransactionList.java
@@ -1,9 +1,12 @@
package financialtransactions;
import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
public class TransactionList> {
private ArrayList transactionList;
+ private String transactionsType;
public TransactionList(){
this.transactionList = new ArrayList<>();
@@ -32,12 +35,12 @@ public boolean addTransaction(T newTransaction){
return false;
}
- public boolean removeTransactionIndex (int index) throws Exception{
+ public boolean removeTransactionIndex (int index) {
transactionList.remove(index);
return true;
}
- public boolean editTransactionIndex (int index, T transaction) throws Exception {
+ public boolean editTransactionIndex (int index, T transaction) {
transactionList.set(index, transaction);
return true;
}
@@ -76,4 +79,32 @@ protected void printTransactionsSafeInfo() {
System.out.println(" " + transaction.getName() + " " + transaction.getCategory());
}
}
+
+ public String getTransactionsType() {
+ return transactionsType;
+ }
+
+ public void setTransactionsType(String transactionsType) {
+ if (transactionsType.equals("Mixed")) {
+ return;
+ }
+ if (this.transactionsType == null) {
+ this.transactionsType = transactionsType;
+ }
+ else if (!this.transactionsType.equals(transactionsType)) {
+ this.transactionsType = "Mixed";
+ }
+ }
+
+ public class NameComparator> implements Comparator {
+ @Override
+ public int compare(T o1, T o2) {
+ return o2.getName().compareToIgnoreCase(o1.getName());
+ }
+ }
+
+ public void sortListByName() {
+ this.transactionList.sort(new NameComparator<>());
+ }
+
}
diff --git a/src/main/java/financialtransactions/TransactionManager.java b/src/main/java/financialtransactions/TransactionManager.java
index 2f1194c8a7..19c7e70eba 100644
--- a/src/main/java/financialtransactions/TransactionManager.java
+++ b/src/main/java/financialtransactions/TransactionManager.java
@@ -14,12 +14,15 @@ public TransactionManager() {
public boolean addTransaction(Transaction> transaction) {
transactionList.addTransaction(transaction);
+ transactionList.sortListByName();
if (transaction instanceof Inflow) {
Inflow inflow = (Inflow) transaction;
+ transactionList.setTransactionsType("Inflow");
return inflows.addTransaction(inflow);
}
if (transaction instanceof Outflow) {
Outflow outflow = (Outflow) transaction;
+ transactionList.setTransactionsType("Outflow");
return outflows.addTransaction(outflow);
}
System.out.println("Invalid transaction type.");
From 83163ef97518363fa9aa9d3a22bb8726a39b2913 Mon Sep 17 00:00:00 2001
From: ChongXern
Date: Sat, 30 Mar 2024 01:48:11 +0800
Subject: [PATCH 099/208] Remove unused collections import
---
src/main/java/financialtransactions/TransactionList.java | 1 -
1 file changed, 1 deletion(-)
diff --git a/src/main/java/financialtransactions/TransactionList.java b/src/main/java/financialtransactions/TransactionList.java
index aa457256bf..a971c7e766 100644
--- a/src/main/java/financialtransactions/TransactionList.java
+++ b/src/main/java/financialtransactions/TransactionList.java
@@ -1,7 +1,6 @@
package financialtransactions;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.Comparator;
public class TransactionList> {
From 2b0d299ece915076e09a1f5f9d4bf0de550b9292 Mon Sep 17 00:00:00 2001
From: ChongXern
Date: Sat, 30 Mar 2024 01:57:52 +0800
Subject: [PATCH 100/208] Add date comparator for transactions
---
.../java/financialtransactions/Transaction.java | 4 ++++
.../financialtransactions/TransactionList.java | 14 ++++++++++++--
.../financialtransactions/TransactionManager.java | 2 +-
src/main/java/template/BaseDate.java | 6 +++++-
4 files changed, 22 insertions(+), 4 deletions(-)
diff --git a/src/main/java/financialtransactions/Transaction.java b/src/main/java/financialtransactions/Transaction.java
index c4a9417bc9..644138e447 100644
--- a/src/main/java/financialtransactions/Transaction.java
+++ b/src/main/java/financialtransactions/Transaction.java
@@ -50,4 +50,8 @@ public String toString() {
public String toSave() {
return String.format("%s|%.2f|%s|%s\n", name, amount, date.toString(), category);
}
+
+ protected BaseDate getDate() {
+ return date;
+ }
}
diff --git a/src/main/java/financialtransactions/TransactionList.java b/src/main/java/financialtransactions/TransactionList.java
index a971c7e766..b4e857c458 100644
--- a/src/main/java/financialtransactions/TransactionList.java
+++ b/src/main/java/financialtransactions/TransactionList.java
@@ -89,8 +89,7 @@ public void setTransactionsType(String transactionsType) {
}
if (this.transactionsType == null) {
this.transactionsType = transactionsType;
- }
- else if (!this.transactionsType.equals(transactionsType)) {
+ } else if (!this.transactionsType.equals(transactionsType)) {
this.transactionsType = "Mixed";
}
}
@@ -102,8 +101,19 @@ public int compare(T o1, T o2) {
}
}
+ public class DateComparator> implements Comparator {
+ @Override
+ public int compare(T o1, T o2) {
+ return o2.getDate().getDateTime().compareTo(o1.getDate().getDateTime());
+ }
+ }
+
public void sortListByName() {
this.transactionList.sort(new NameComparator<>());
}
+ public void sortListByDate() {
+ this.transactionList.sort(new DateComparator<>());
+ }
+
}
diff --git a/src/main/java/financialtransactions/TransactionManager.java b/src/main/java/financialtransactions/TransactionManager.java
index 19c7e70eba..049ba5946d 100644
--- a/src/main/java/financialtransactions/TransactionManager.java
+++ b/src/main/java/financialtransactions/TransactionManager.java
@@ -14,7 +14,7 @@ public TransactionManager() {
public boolean addTransaction(Transaction> transaction) {
transactionList.addTransaction(transaction);
- transactionList.sortListByName();
+ // transactionList.sortListByName();
if (transaction instanceof Inflow) {
Inflow inflow = (Inflow) transaction;
transactionList.setTransactionsType("Inflow");
diff --git a/src/main/java/template/BaseDate.java b/src/main/java/template/BaseDate.java
index 8b48f0b794..010ccd98ab 100644
--- a/src/main/java/template/BaseDate.java
+++ b/src/main/java/template/BaseDate.java
@@ -27,7 +27,7 @@ public class BaseDate {
private static final ArrayList dateTimeFormats = dateTimeVary();
- LocalDateTime dateTime = null;
+ private LocalDateTime dateTime = null;
private final String defaultTime = " 0000";
public BaseDate(String args) {
@@ -76,4 +76,8 @@ public boolean isBefore(BaseDate otherDate) {
}
return false;
}
+
+ public LocalDateTime getDateTime() {
+ return dateTime;
+ }
}
From 25356a4b075222d7b0711db1563e2c9e6429b3a3 Mon Sep 17 00:00:00 2001
From: chowy
Date: Sat, 30 Mar 2024 17:15:26 +0800
Subject: [PATCH 101/208] Added feature to handle multiple users
---
src/main/java/financeproject/Main.java | 12 ++++----
src/main/java/storage/Storage.java | 41 +++++++++++++++++++++-----
src/main/java/user/Authentication.java | 14 +--------
src/main/java/user/BaseUser.java | 37 ++++++++++++++++++-----
src/test/data/passwords.txt | 1 +
src/test/java/user/BaseUserTest.java | 4 ++-
text-ui-test/EXPECTED.TXT | 2 +-
text-ui-test/data/data.txt | 3 --
text-ui-test/data/passwords.txt | 1 +
9 files changed, 76 insertions(+), 39 deletions(-)
create mode 100644 src/test/data/passwords.txt
delete mode 100644 text-ui-test/data/data.txt
create mode 100644 text-ui-test/data/passwords.txt
diff --git a/src/main/java/financeproject/Main.java b/src/main/java/financeproject/Main.java
index 806d254534..64edae8744 100644
--- a/src/main/java/financeproject/Main.java
+++ b/src/main/java/financeproject/Main.java
@@ -23,19 +23,19 @@ public static void main(String[] args) throws SecurityException, ExceededAttempt
Parser parser = new Parser(ui);
BaseCommand baseCommand = null;
String response = "";
-
- BaseUser tempUser = new BaseUser("Bob", ui);
- Authentication auth = tempUser.getAuthentication();
+
+ BaseUser user = new BaseUser(ui, storage);
+ Authentication auth = user.getAuthentication();
InactivityTimer inactivityTimer = new InactivityTimer();
boolean isAuthenticated = false;
while (!isAuthenticated && auth.getWrongAttempts() < 3) {
try {
- if (!auth.authenticate()) {
+ if (!auth.authenticate(user.getUsername())) {
ui.printMessage("Authentication error");
} else {
ui.printMessage("Password is correct. You are now logged in");
- manager = storage.loadFile();
+ manager = storage.loadFile(user.getUsername());
isAuthenticated = true;
}
} catch (ExceededAttemptsException e) {
@@ -71,7 +71,7 @@ public static void main(String[] args) throws SecurityException, ExceededAttempt
System.out.println("Uh-oh, something went wrong: " + e.getMessage());
}
- storage.saveFile(manager);
+ storage.saveFile(user.getUsername(), manager);
try {
inactivityTimer.checkTimeElapsed();
diff --git a/src/main/java/storage/Storage.java b/src/main/java/storage/Storage.java
index 6fbce01a93..65c69226fb 100644
--- a/src/main/java/storage/Storage.java
+++ b/src/main/java/storage/Storage.java
@@ -15,9 +15,36 @@ public class Storage {
public Storage(String filePath) {
this.filePath = filePath;
}
-
- public TransactionManager loadFile() {
- File f = new File(filePath + "/data.txt");
+
+ public void addNewUser(String username, String password) {
+ try {
+ FileWriter fw = new FileWriter(filePath + "/passwords.txt", true);
+ fw.write(username + "|" + password + "\n");
+ fw.close();
+ } catch (IOException e) {
+ System.out.println("Could not add user");
+ }
+ }
+
+ public String loadPassword(String username) {
+ File f = new File(filePath + "/passwords.txt");
+ try {
+ Scanner sc = new Scanner(f);
+ while (sc.hasNext()) {
+ String line = sc.nextLine();
+ if (line.startsWith(username)) {
+ return line.split("\\|")[1];
+ }
+ }
+ return null;
+ } catch (FileNotFoundException e) {
+ createFileDir();
+ return null;
+ }
+ }
+
+ public TransactionManager loadFile(String username) {
+ File f = new File(filePath + String.format("/%s.txt", username));
TransactionManager manager = new TransactionManager();
try {
Scanner sc = new Scanner(f);
@@ -44,14 +71,12 @@ public TransactionManager loadFile() {
private void createFileDir() {
File f = new File(filePath);
- if (!f.mkdir()) {
- System.out.println("create file failed");
- }
+ f.mkdir();
}
- public void saveFile(TransactionManager tm) {
+ public void saveFile(String username, TransactionManager tm) {
try {
- FileWriter fw = new FileWriter(filePath + "/data.txt");
+ FileWriter fw = new FileWriter(filePath + String.format("/%s.txt", username));
fw.write(tm.toSave());
fw.close();
} catch (IOException e) {
diff --git a/src/main/java/user/Authentication.java b/src/main/java/user/Authentication.java
index 0ee0c06dbe..3cc129fc6f 100644
--- a/src/main/java/user/Authentication.java
+++ b/src/main/java/user/Authentication.java
@@ -43,21 +43,9 @@ public int getWrongAttempts() {
return wrongAttempts;
}
- public boolean authenticate() throws ExceededAttemptsException {
- System.out.println("username: ");
- String inputUsername = this.ui.readInput();
+ public boolean authenticate(String inputUsername) throws ExceededAttemptsException {
System.out.println("password: ");
String inputPassword = this.ui.readInput();
- /*try {
- return this.checkPassword(inputUsername, inputPassword);
- } catch (ExceededAttemptsException e) {
- if (e.isCanTryAgain()) {
- System.out.println("Wrong password or username, please try again.");
- } else {
- System.out.println("Sorry, too many incorrect attempts.");
- }
- return false;
- }*/
return this.checkPassword(inputUsername, inputPassword);
}
}
diff --git a/src/main/java/user/BaseUser.java b/src/main/java/user/BaseUser.java
index 012c99cc82..6aaa636bbe 100644
--- a/src/main/java/user/BaseUser.java
+++ b/src/main/java/user/BaseUser.java
@@ -1,21 +1,44 @@
package user;
+import storage.Storage;
import userinterface.UI;
public class BaseUser {
- String name;
+ String username;
Authentication auth;
UI ui;
- public BaseUser(String name, UI ui) {
- this.name = name;
- String username = name.replace(" ", "_");
- this.auth = new Authentication("password", username, ui);
+ public BaseUser(UI ui, Storage storage) {
+ ui.printMessage("username:");
+ String pw = null;
+ do {
+ username = ui.readInput().replace(" ", "_");
+ pw = storage.loadPassword(username);
+ if (pw == null) {
+ ui.printMessage(String.format("User does not exist, do you want to create a new user with " +
+ "username %s? Yes or No", username));
+ if (ui.readInput().equals("Yes")) {
+ ui.printMessage("Please enter a new password:");
+ pw = ui.readInput();
+ storage.addNewUser(username, pw);
+ ui.printMessage("User successfully created, enter your password again to login");
+ } else {
+ ui.printMessage("Please enter another username:");
+ }
+ }
+ } while (pw == null);
+ this.auth = new Authentication(pw, username, ui);
+ this.ui = ui;
+ }
+
+ public BaseUser(String username, String pw, UI ui, Storage storage) {
+ this.username = username;
+ this.auth = new Authentication(pw, username, ui);
this.ui = ui;
}
- public String getName() {
- return name;
+ public String getUsername() {
+ return username;
}
public Authentication getAuthentication(){
diff --git a/src/test/data/passwords.txt b/src/test/data/passwords.txt
new file mode 100644
index 0000000000..b82d33347d
--- /dev/null
+++ b/src/test/data/passwords.txt
@@ -0,0 +1 @@
+Bob|password
diff --git a/src/test/java/user/BaseUserTest.java b/src/test/java/user/BaseUserTest.java
index c8f6ffc985..432010a215 100644
--- a/src/test/java/user/BaseUserTest.java
+++ b/src/test/java/user/BaseUserTest.java
@@ -3,6 +3,7 @@
import customexceptions.ExceededAttemptsException;
import org.junit.jupiter.api.Test;
+import storage.Storage;
import userinterface.UI;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -11,7 +12,8 @@ public class BaseUserTest {
@Test
public void sampleTest() throws ExceededAttemptsException {
UI ui = new UI();
- BaseUser user = new BaseUser("Bob", ui);
+ Storage storage = new Storage("./data");
+ BaseUser user = new BaseUser("Bob", "password", ui, storage);
Authentication auth = user.getAuthentication();
assertTrue(auth.checkPassword("Bob", "password"));
}
diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT
index 9cd3de5780..eaa015f1be 100644
--- a/text-ui-test/EXPECTED.TXT
+++ b/text-ui-test/EXPECTED.TXT
@@ -1,5 +1,5 @@
Welcome. Enter your username and password to login.
-username:
+username:
password:
Password is correct. You are now logged in
Ok. Added inflow
diff --git a/text-ui-test/data/data.txt b/text-ui-test/data/data.txt
deleted file mode 100644
index 1e8c2694d8..0000000000
--- a/text-ui-test/data/data.txt
+++ /dev/null
@@ -1,3 +0,0 @@
-Stocks|400.00|Oct 24 2024 12:00PM|INVESTMENT
-Refund|100.00|Jun 23 2023 05:00PM|REFUND
-Groceries|-150.00|Jun 23 2023 06:30PM|SHOPPING
diff --git a/text-ui-test/data/passwords.txt b/text-ui-test/data/passwords.txt
new file mode 100644
index 0000000000..b82d33347d
--- /dev/null
+++ b/text-ui-test/data/passwords.txt
@@ -0,0 +1 @@
+Bob|password
From fcea0fd091b2a0a6ded1d53836bfa548a9c16715 Mon Sep 17 00:00:00 2001
From: chenhowy <110732061+chenhowy@users.noreply.github.com>
Date: Sat, 30 Mar 2024 17:30:07 +0800
Subject: [PATCH 102/208] Update gradle.yml to remove text-ui-tests
---
.github/workflows/gradle.yml | 16 ----------------
1 file changed, 16 deletions(-)
diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml
index fd8c44d086..391c46b4fe 100644
--- a/.github/workflows/gradle.yml
+++ b/.github/workflows/gradle.yml
@@ -32,19 +32,3 @@ jobs:
- name: Build and check with Gradle
run: ./gradlew check
-
- - name: Perform IO redirection test (*NIX)
- if: runner.os == 'Linux'
- working-directory: ${{ github.workspace }}/text-ui-test
- run: ./runtest.sh
-
- - name: Perform IO redirection test (MacOS)
- if: always() && runner.os == 'macOS'
- working-directory: ${{ github.workspace }}/text-ui-test
- run: ./runtest.sh
-
- - name: Perform IO redirection test (Windows)
- if: always() && runner.os == 'Windows'
- working-directory: ${{ github.workspace }}/text-ui-test
- shell: cmd
- run: runtest.bat
\ No newline at end of file
From 48731613c9097267bc0169167c8d4f5115f0afc5 Mon Sep 17 00:00:00 2001
From: ChongXern
Date: Sat, 30 Mar 2024 19:29:43 +0800
Subject: [PATCH 103/208] Create BarChart class
---
src/main/java/financialtransactions/Outflow.java | 2 +-
src/main/java/storage/BarChart.java | 7 +++++++
2 files changed, 8 insertions(+), 1 deletion(-)
create mode 100644 src/main/java/storage/BarChart.java
diff --git a/src/main/java/financialtransactions/Outflow.java b/src/main/java/financialtransactions/Outflow.java
index dd952fada6..1584cc1ab9 100644
--- a/src/main/java/financialtransactions/Outflow.java
+++ b/src/main/java/financialtransactions/Outflow.java
@@ -2,7 +2,7 @@
public class Outflow extends Transaction {
public enum Category {
- RENT, DEBT, SHOPPING, TREAT, EDUCATION, TAX, OTHER
+ FOOD, RENT, DEBT, SHOPPING, TREAT, EDUCATION, TAX, OTHER
}
public Outflow(String name, double amount, String date) {
diff --git a/src/main/java/storage/BarChart.java b/src/main/java/storage/BarChart.java
new file mode 100644
index 0000000000..3aaf47361a
--- /dev/null
+++ b/src/main/java/storage/BarChart.java
@@ -0,0 +1,7 @@
+package storage;
+
+public class BarChart {
+ public BarChart() {
+
+ }
+}
From b7daccc84b0c7502c0a19c782ea2c41347d99ce6 Mon Sep 17 00:00:00 2001
From: dylansiew <88567790+dylansiew@users.noreply.github.com>
Date: Sat, 30 Mar 2024 23:17:45 +0800
Subject: [PATCH 104/208] implemeting oop concepts
---
data/Bob.txt | 0
data/passwords.txt | 1 +
.../ExceededAttemptsException.java | 8 +--
.../IncompletePromptException.java | 49 ++++------------
.../UserNotFoundExcption.java | 7 +++
src/main/java/financeproject/Main.java | 57 ++++++++-----------
src/main/java/storage/Storage.java | 14 +++--
src/main/java/user/Authentication.java | 36 ++++++------
src/main/java/user/BaseUser.java | 45 ++++++---------
.../java/command/AddInflowCommandTest.java | 19 +++++++
.../java/command/AddOutflowCommandTest.java | 19 +++++++
src/test/java/user/BaseUserTest.java | 9 +--
12 files changed, 128 insertions(+), 136 deletions(-)
create mode 100644 data/Bob.txt
create mode 100644 data/passwords.txt
create mode 100644 src/main/java/customexceptions/UserNotFoundExcption.java
create mode 100644 src/test/java/command/AddInflowCommandTest.java
create mode 100644 src/test/java/command/AddOutflowCommandTest.java
diff --git a/data/Bob.txt b/data/Bob.txt
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/data/passwords.txt b/data/passwords.txt
new file mode 100644
index 0000000000..b82d33347d
--- /dev/null
+++ b/data/passwords.txt
@@ -0,0 +1 @@
+Bob|password
diff --git a/src/main/java/customexceptions/ExceededAttemptsException.java b/src/main/java/customexceptions/ExceededAttemptsException.java
index 0e9c363ffb..0339fbe848 100644
--- a/src/main/java/customexceptions/ExceededAttemptsException.java
+++ b/src/main/java/customexceptions/ExceededAttemptsException.java
@@ -1,11 +1,7 @@
package customexceptions;
public class ExceededAttemptsException extends Exception {
- private boolean canTryAgain;
- public ExceededAttemptsException(boolean canTryAgain) {
- this.canTryAgain = canTryAgain;
- }
- public boolean isCanTryAgain() {
- return this.canTryAgain;
+ public ExceededAttemptsException() {
+ super("Attempts exceeded, exiting program");
}
}
diff --git a/src/main/java/customexceptions/IncompletePromptException.java b/src/main/java/customexceptions/IncompletePromptException.java
index 5445d653ff..ee1cdc0262 100644
--- a/src/main/java/customexceptions/IncompletePromptException.java
+++ b/src/main/java/customexceptions/IncompletePromptException.java
@@ -1,51 +1,24 @@
package customexceptions;
-import java.util.Arrays;
-
public class IncompletePromptException extends Exception {
public static final String[] INSTRUCTIONS = {
"add-inflow", "add-outflow", "delete-inflow", "delete-outflow", "quit"};
- private boolean isTypo = false;
- private boolean isIncomplete = false;
- private boolean isUnknown = false;
public IncompletePromptException(String line) {
- int spaceIndex = line.indexOf(" ");
- String firstWord = (spaceIndex == -1) ? line : line.substring(0, spaceIndex);
- if (Arrays.asList(INSTRUCTIONS).contains(firstWord)) {
- isTypo = false;
- isIncomplete = true;
- isUnknown = false;
- } else {
- checkTypo(firstWord);
- }
+ super(setMessage(line));
}
- public boolean getIsTypo() {
- return this.isTypo;
- }
- public boolean getIsIncomplete() {
- return this.isIncomplete;
- }
- public boolean getIsUnknown() {
- return this.isUnknown;
- }
-
- public void checkTypo(String word) {
- for (String instruction : INSTRUCTIONS) {
- if (instruction.contains(word)) {
- if (!isTypo) {
- isTypo = true;
- System.out.println("Did you mean: ");
- }
- System.out.print(instruction + " ");
+ private static String setMessage(String prompt){
+ String message = "Sorry, prompt input is unknown.";
+ for(String instr: IncompletePromptException.INSTRUCTIONS){
+ if(instr.equals(prompt)){
+ message = "Sorry, your prompt appears incomplete. Could you finish your sentence?";
+ break;
+ } else if (instr.contains(prompt)){
+ message = "Please prompt again with correct spelling.";
+ break;
}
}
- if (isTypo) {
- this.isIncomplete = true;
- System.out.println("?");
- } else {
- this.isUnknown = true;
- }
+ return message;
}
}
diff --git a/src/main/java/customexceptions/UserNotFoundExcption.java b/src/main/java/customexceptions/UserNotFoundExcption.java
new file mode 100644
index 0000000000..aa429c0111
--- /dev/null
+++ b/src/main/java/customexceptions/UserNotFoundExcption.java
@@ -0,0 +1,7 @@
+package customexceptions;
+
+public class UserNotFoundExcption extends Exception {
+ public UserNotFoundExcption() {
+ super("Username not found. Exiting program");
+ }
+}
diff --git a/src/main/java/financeproject/Main.java b/src/main/java/financeproject/Main.java
index 64edae8744..7ff7eb21d2 100644
--- a/src/main/java/financeproject/Main.java
+++ b/src/main/java/financeproject/Main.java
@@ -4,6 +4,7 @@
import customexceptions.ExceededAttemptsException;
import customexceptions.InactivityTimeoutException;
import customexceptions.IncompletePromptException;
+import customexceptions.UserNotFoundExcption;
import financialtransactions.TransactionManager;
import parser.Parser;
import storage.Storage;
@@ -23,52 +24,40 @@ public static void main(String[] args) throws SecurityException, ExceededAttempt
Parser parser = new Parser(ui);
BaseCommand baseCommand = null;
String response = "";
-
- BaseUser user = new BaseUser(ui, storage);
- Authentication auth = user.getAuthentication();
- InactivityTimer inactivityTimer = new InactivityTimer();
- boolean isAuthenticated = false;
- while (!isAuthenticated && auth.getWrongAttempts() < 3) {
- try {
- if (!auth.authenticate(user.getUsername())) {
- ui.printMessage("Authentication error");
- } else {
- ui.printMessage("Password is correct. You are now logged in");
- manager = storage.loadFile(user.getUsername());
- isAuthenticated = true;
- }
- } catch (ExceededAttemptsException e) {
- if (e.isCanTryAgain()) {
- ui.printMessage("Incorrect username or password. Please try again.");
- } else {
- ui.printMessage("Too many incorrect attempts. Authentication failed.");
- }
- }
+ // Authenticating user
+ BaseUser user = null;
+ InactivityTimer inactivityTimer = new InactivityTimer();
+ try {
+ ui.printMessage("Username: ");
+ response = ui.readInput();
+ user = storage.loadUser(response);
+ Authentication.authenticateUser(user, ui);
+ } catch (UserNotFoundExcption e) {
+ ui.printMessage(e.getMessage());
+ return;
+ } catch (ExceededAttemptsException e) {
+ ui.printMessage(e.getMessage());
+ return;
}
-
- if (!isAuthenticated) {
- ui.closeScanner();
+ if (user != null) {
+ ui.printMessage("User has been authenticated. Starting program...");
+ } else {
return;
}
+ // Main program flow
do {
- String command = ui.readInput();
+ response = ui.readInput();
try {
- baseCommand = parser.parseCommand(command);
+ baseCommand = parser.parseCommand(response);
response = baseCommand.execute(manager);
ui.printMessage(response);
inactivityTimer.resetTimer();
} catch (IncompletePromptException e) {
- if (e.getIsTypo()) {
- System.out.println("Please prompt again with correct spelling.");
- } else if (e.getIsIncomplete()) {
- System.out.println("Sorry, your prompt appears incomplete. Could you finish your sentence?");
- } else if (e.getIsUnknown()) {
- System.out.println("Sorry, prompt inputted is unknown. ");
- }
+ ui.printMessage(e.getMessage());
} catch (Exception e) {
- System.out.println("Uh-oh, something went wrong: " + e.getMessage());
+ ui.printMessage("Uh-oh, something went wrong: " + e.getMessage());
}
storage.saveFile(user.getUsername(), manager);
diff --git a/src/main/java/storage/Storage.java b/src/main/java/storage/Storage.java
index 65c69226fb..4b863083c6 100644
--- a/src/main/java/storage/Storage.java
+++ b/src/main/java/storage/Storage.java
@@ -3,6 +3,7 @@
import financialtransactions.Inflow;
import financialtransactions.Outflow;
import financialtransactions.TransactionManager;
+import user.BaseUser;
import java.io.File;
import java.io.FileNotFoundException;
@@ -10,8 +11,11 @@
import java.io.IOException;
import java.util.Scanner;
+import customexceptions.UserNotFoundExcption;
+
public class Storage {
private final String filePath;
+ private Scanner sc;
public Storage(String filePath) {
this.filePath = filePath;
}
@@ -26,17 +30,19 @@ public void addNewUser(String username, String password) {
}
}
- public String loadPassword(String username) {
+ public BaseUser loadUser(String username) throws UserNotFoundExcption{
File f = new File(filePath + "/passwords.txt");
try {
- Scanner sc = new Scanner(f);
+ this.sc = new Scanner(f);
while (sc.hasNext()) {
String line = sc.nextLine();
if (line.startsWith(username)) {
- return line.split("\\|")[1];
+ String password = line.split("\\|")[1];
+ BaseUser newUser = new BaseUser(username, password);
+ return newUser;
}
}
- return null;
+ throw new UserNotFoundExcption();
} catch (FileNotFoundException e) {
createFileDir();
return null;
diff --git a/src/main/java/user/Authentication.java b/src/main/java/user/Authentication.java
index 3cc129fc6f..8322a9cc2d 100644
--- a/src/main/java/user/Authentication.java
+++ b/src/main/java/user/Authentication.java
@@ -4,29 +4,24 @@
import userinterface.UI;
public class Authentication {
+ private static int attemptsLimit = 3;
String username;
UI ui;
private String password;
- private int wrongAttempts;
-
- public Authentication(String password, String username, UI ui) {
+ public Authentication(String username, String password) {
this.password = password;
this.username = username;
- this.ui = ui;
- this.wrongAttempts = 0;
}
public String getUsername() {
return this.username;
}
- public boolean checkPassword(String username, String password) throws ExceededAttemptsException {
+ public boolean checkPassword(String username, String password) {
+ System.out.println(password + " and " + this.password);
+ System.out.println(username + " and " + this.username);
boolean isMatch = this.password.equals(password) && this.username.equals(username);
- if (!isMatch) {
- wrongAttempts++;
- throw new ExceededAttemptsException(wrongAttempts < 3);
- }
return isMatch;
}
@@ -39,13 +34,18 @@ public boolean changePassword(String username, String oldPassword, String newPas
return true;
}
- public int getWrongAttempts() {
- return wrongAttempts;
- }
-
- public boolean authenticate(String inputUsername) throws ExceededAttemptsException {
- System.out.println("password: ");
- String inputPassword = this.ui.readInput();
- return this.checkPassword(inputUsername, inputPassword);
+ public static boolean authenticateUser(BaseUser user, UI ui) throws ExceededAttemptsException {
+ Authentication auth = user.getAuthentication();
+ String passwordInput;
+ for (int i = 0; i < Authentication.attemptsLimit; i++) {
+ ui.printMessage("Password: ");
+ passwordInput = ui.readInput();
+ if (auth.checkPassword(user.getUsername(), passwordInput)) {
+ return true;
+ } else {
+ ui.printMessage("Wrong password");
+ }
+ }
+ throw new ExceededAttemptsException();
}
}
diff --git a/src/main/java/user/BaseUser.java b/src/main/java/user/BaseUser.java
index 6aaa636bbe..25aa6e0620 100644
--- a/src/main/java/user/BaseUser.java
+++ b/src/main/java/user/BaseUser.java
@@ -1,46 +1,33 @@
package user;
-import storage.Storage;
-import userinterface.UI;
+import financialtransactions.TransactionManager;
public class BaseUser {
String username;
Authentication auth;
- UI ui;
+ TransactionManager manager = null;
- public BaseUser(UI ui, Storage storage) {
- ui.printMessage("username:");
- String pw = null;
- do {
- username = ui.readInput().replace(" ", "_");
- pw = storage.loadPassword(username);
- if (pw == null) {
- ui.printMessage(String.format("User does not exist, do you want to create a new user with " +
- "username %s? Yes or No", username));
- if (ui.readInput().equals("Yes")) {
- ui.printMessage("Please enter a new password:");
- pw = ui.readInput();
- storage.addNewUser(username, pw);
- ui.printMessage("User successfully created, enter your password again to login");
- } else {
- ui.printMessage("Please enter another username:");
- }
- }
- } while (pw == null);
- this.auth = new Authentication(pw, username, ui);
- this.ui = ui;
- }
-
- public BaseUser(String username, String pw, UI ui, Storage storage) {
+ public BaseUser(String username, String password) {
this.username = username;
- this.auth = new Authentication(pw, username, ui);
- this.ui = ui;
+ this.auth = new Authentication(username, password);
}
public String getUsername() {
return username;
}
+ public boolean setTransactionManager(TransactionManager manager){
+ if(this.manager == null){
+ this.manager = manager;
+ return true;
+ }
+ return false;
+ }
+
+ public TransactionManager getTransactionManager(){
+ return this.manager;
+ }
+
public Authentication getAuthentication(){
return this.auth;
}
diff --git a/src/test/java/command/AddInflowCommandTest.java b/src/test/java/command/AddInflowCommandTest.java
new file mode 100644
index 0000000000..a487eeee13
--- /dev/null
+++ b/src/test/java/command/AddInflowCommandTest.java
@@ -0,0 +1,19 @@
+package command;
+
+import org.junit.jupiter.api.Test;
+
+import financialtransactions.TransactionManager;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class AddInflowCommandTest {
+ @Test
+ public void testAddInflow() {
+ String arg = "add-inflow n/Salary a/400.00 d/23/05/2022 t/1900 c/income";
+ String[] splitCommand = arg.split(" ");
+ AddInflowCommand command = new AddInflowCommand(splitCommand);
+
+ TransactionManager manager = new TransactionManager();
+ assertEquals(command.execute(manager), "Ok. Added inflow");
+ }
+}
diff --git a/src/test/java/command/AddOutflowCommandTest.java b/src/test/java/command/AddOutflowCommandTest.java
new file mode 100644
index 0000000000..05299ae792
--- /dev/null
+++ b/src/test/java/command/AddOutflowCommandTest.java
@@ -0,0 +1,19 @@
+package command;
+
+import org.junit.jupiter.api.Test;
+
+import financialtransactions.TransactionManager;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class AddOutflowCommandTest{
+ @Test
+ public void testAddOutflowTest(){
+ String arg = "add-outflow n/Rent a/1500.00 d/23/06/2023 t/1800 c/rent";
+ String[] splitCommand = arg.split(" ");
+ AddOutflowCommand command = new AddOutflowCommand(splitCommand);
+
+ TransactionManager manager = new TransactionManager();
+ assertEquals(command.execute(manager), "Ok. Added outflow");
+ }
+}
diff --git a/src/test/java/user/BaseUserTest.java b/src/test/java/user/BaseUserTest.java
index 432010a215..032288d176 100644
--- a/src/test/java/user/BaseUserTest.java
+++ b/src/test/java/user/BaseUserTest.java
@@ -1,19 +1,14 @@
package user;
-import customexceptions.ExceededAttemptsException;
import org.junit.jupiter.api.Test;
-import storage.Storage;
-import userinterface.UI;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class BaseUserTest {
@Test
- public void sampleTest() throws ExceededAttemptsException {
- UI ui = new UI();
- Storage storage = new Storage("./data");
- BaseUser user = new BaseUser("Bob", "password", ui, storage);
+ public void baseUserTest() {
+ BaseUser user = new BaseUser("Bob", "password");
Authentication auth = user.getAuthentication();
assertTrue(auth.checkPassword("Bob", "password"));
}
From 1675cd40e142afcc2dea62a9efa6da6878aa2b70 Mon Sep 17 00:00:00 2001
From: chowy
Date: Sun, 31 Mar 2024 04:00:43 +0800
Subject: [PATCH 105/208] Added feature to set reminders for future payments.
Added a quick report for when user logs in.
---
src/main/java/command/AddReminderCommand.java | 37 ++++++++++++
.../java/command/DeleteReminderCommand.java | 21 +++++++
.../java/command/EditReminderCommand.java | 42 ++++++++++++++
src/main/java/command/HelpCommand.java | 16 ++++--
src/main/java/command/SetBudgetCommand.java | 21 +++++++
src/main/java/financeproject/Main.java | 5 +-
.../java/financialtransactions/Inflow.java | 5 ++
.../java/financialtransactions/Outflow.java | 5 ++
.../java/financialtransactions/Reminder.java | 20 +++++++
.../financialtransactions/Transaction.java | 6 +-
.../TransactionList.java | 12 +++-
.../TransactionManager.java | 57 ++++++++++++++++++-
src/main/java/parser/Parser.java | 25 ++++++++
src/main/java/storage/Storage.java | 12 +++-
.../TransactionManagerTest.java | 14 ++++-
15 files changed, 278 insertions(+), 20 deletions(-)
create mode 100644 src/main/java/command/AddReminderCommand.java
create mode 100644 src/main/java/command/DeleteReminderCommand.java
create mode 100644 src/main/java/command/EditReminderCommand.java
create mode 100644 src/main/java/command/SetBudgetCommand.java
create mode 100644 src/main/java/financialtransactions/Reminder.java
diff --git a/src/main/java/command/AddReminderCommand.java b/src/main/java/command/AddReminderCommand.java
new file mode 100644
index 0000000000..9e0a0164d8
--- /dev/null
+++ b/src/main/java/command/AddReminderCommand.java
@@ -0,0 +1,37 @@
+package command;
+
+import financialtransactions.Reminder;
+import financialtransactions.TransactionManager;
+
+public class AddReminderCommand extends BaseCommand {
+ public AddReminderCommand(String[] commandParts) {
+ super(false, commandParts);
+ }
+
+ public String execute(TransactionManager manager) {
+ String reminderName = null;
+ double reminderAmount = 0.0;
+ String reminderDate = null;
+ String reminderTime = null;
+ String reminderCategory = null;
+
+ for (String part : commandParts) {
+ if (part.startsWith("n/")) {
+ reminderName = part.substring(2);
+ } else if (part.startsWith("a/")) {
+ reminderAmount = Double.parseDouble(part.substring(2));
+ } else if (part.startsWith("d/")) {
+ reminderDate = part.substring(2);
+ } else if (part.startsWith("t/")) {
+ reminderTime = part.substring(2);
+ } else if (part.startsWith("c/")) {
+ reminderCategory = part.substring(2);
+ }
+ }
+ String reminderDateTime = reminderDate + " " + reminderTime;
+ Reminder reminder = new Reminder(reminderName, reminderAmount, reminderDateTime);
+ reminder.setCategory(Reminder.Category.valueOf(reminderCategory.toUpperCase()));
+ manager.addTransaction(reminder);
+ return "Ok. Added reminder";
+ }
+}
diff --git a/src/main/java/command/DeleteReminderCommand.java b/src/main/java/command/DeleteReminderCommand.java
new file mode 100644
index 0000000000..3502281443
--- /dev/null
+++ b/src/main/java/command/DeleteReminderCommand.java
@@ -0,0 +1,21 @@
+package command;
+
+import financialtransactions.TransactionManager;
+
+public class DeleteReminderCommand extends BaseCommand {
+ public DeleteReminderCommand(String[] commandParts) {
+ super(false, commandParts);
+ }
+
+ public String execute(TransactionManager manager) throws Exception {
+ String reminderIndex = null;
+ for (String part : commandParts) {
+ if (part.startsWith("i/")) {
+ reminderIndex = part.substring(2);
+ }
+ }
+ assert reminderIndex != null : "reminderIndex should not be null";
+ manager.removeReminder(Integer.parseInt(reminderIndex));
+ return "Ok. Reminder deleted";
+ }
+}
diff --git a/src/main/java/command/EditReminderCommand.java b/src/main/java/command/EditReminderCommand.java
new file mode 100644
index 0000000000..b35bb2516a
--- /dev/null
+++ b/src/main/java/command/EditReminderCommand.java
@@ -0,0 +1,42 @@
+package command;
+
+import financialtransactions.Reminder;
+import financialtransactions.TransactionManager;
+
+public class EditReminderCommand extends BaseCommand {
+ public EditReminderCommand(String[] commandParts) {
+ super(false, commandParts);
+ }
+
+ public String execute(TransactionManager manager) throws Exception {
+ int reminderIndex = -1;
+ String reminderName = null;
+ double reminderAmount = 0.0;
+ String reminderDate = null;
+ String reminderTime = null;
+ String reminderCategory = null;
+
+ for (String part : commandParts) {
+ if (part.startsWith("i/")) {
+ reminderIndex = Integer.parseInt(part.substring(2));
+ } else if (part.startsWith("n/")) {
+ reminderName = part.substring(2);
+ } else if (part.startsWith("a/")) {
+ reminderAmount = Double.parseDouble(part.substring(2));
+ } else if (part.startsWith("d/")) {
+ reminderDate = part.substring(2);
+ } else if (part.startsWith("t/")) {
+ reminderTime = part.substring(2);
+ } else if (part.startsWith("c/")) {
+ reminderCategory = part.substring(2);
+ }
+ }
+
+ String reminderDateTime = reminderDate + " " + reminderTime;
+ Reminder updatedReminder = new Reminder(reminderName, reminderAmount, reminderDateTime);
+ assert reminderCategory != null : "reminderCategory should not be null";
+ updatedReminder.setCategory(Reminder.Category.valueOf(reminderCategory.toUpperCase()));
+ manager.editOutflow(reminderIndex, updatedReminder);
+ return "Ok. Edited reminder";
+ }
+}
diff --git a/src/main/java/command/HelpCommand.java b/src/main/java/command/HelpCommand.java
index a0d3ed134f..09deaf1750 100644
--- a/src/main/java/command/HelpCommand.java
+++ b/src/main/java/command/HelpCommand.java
@@ -13,12 +13,16 @@ public String execute(TransactionManager manager) throws Exception {
baseString += "Here are the available commands: \n";
baseString += "1) add-inflow n/NAME a/AMOUNT d/DATE t/TIME c/CATEGORY\n";
baseString += "2) add-outflow n/NAME a/AMOUNT d/DATE t/TIME c/CATEGORY\n";
- baseString += "3) delete-inflow i/INDEX\n";
- baseString += "4) delete-outflow i/INDEX\n";
- baseString += "5) edit-inflow i/INDEX n/NAME a/AMOUNT d/DATE t/TIME c/CATEGORY\n";
- baseString += "6) edit-outflow i/INDEX n/NAME a/AMOUNT d/DATE t/TIME c/CATEGORY\n";
- baseString += "7) view-history n/NUM \n";
- baseString += "8) quit \n";
+ baseString += "3) add-reminder n/NAME a/AMOUNT d/DATE t/TIME c/CATEGORY\n";
+ baseString += "4) delete-inflow i/INDEX\n";
+ baseString += "5) delete-outflow i/INDEX\n";
+ baseString += "6) delete-reminder i/INDEX\n";
+ baseString += "7) edit-inflow i/INDEX n/NAME a/AMOUNT d/DATE t/TIME c/CATEGORY\n";
+ baseString += "8) edit-outflow i/INDEX n/NAME a/AMOUNT d/DATE t/TIME c/CATEGORY\n";
+ baseString += "9) delete-reminder i/INDEX n/NAME a/AMOUNT d/DATE t/TIME c/CATEGORY\n";
+ baseString += "10) set-budget a/AMOUNT\n";
+ baseString += "11) view-history n/NUM \n";
+ baseString += "12) quit \n";
baseString += "_____________";
return baseString;
}
diff --git a/src/main/java/command/SetBudgetCommand.java b/src/main/java/command/SetBudgetCommand.java
new file mode 100644
index 0000000000..686290a3bd
--- /dev/null
+++ b/src/main/java/command/SetBudgetCommand.java
@@ -0,0 +1,21 @@
+package command;
+
+import financialtransactions.TransactionManager;
+
+public class SetBudgetCommand extends BaseCommand{
+ public SetBudgetCommand(String[] commandParts) {
+ super(false, commandParts);
+ }
+
+ public String execute(TransactionManager manager) throws Exception{
+ String budgetString = null;
+ for (String part : commandParts) {
+ if (part.startsWith("a/")) {
+ budgetString = part.substring(2);
+ }
+ }
+ double budget = Double.parseDouble(budgetString);
+ manager.setBudget(budget);
+ return "Ok. Budget set.";
+ }
+}
diff --git a/src/main/java/financeproject/Main.java b/src/main/java/financeproject/Main.java
index 7ff7eb21d2..04eac2f472 100644
--- a/src/main/java/financeproject/Main.java
+++ b/src/main/java/financeproject/Main.java
@@ -16,8 +16,7 @@
public class Main {
public static void main(String[] args) throws SecurityException, ExceededAttemptsException {
Storage storage = new Storage("./data");
- TransactionManager manager = new TransactionManager();
-
+
UI ui = new UI();
ui.printMessage("Welcome. Enter your username and password to login.");
@@ -45,6 +44,8 @@ public static void main(String[] args) throws SecurityException, ExceededAttempt
} else {
return;
}
+ TransactionManager manager = storage.loadFile(user.getUsername());
+ ui.printMessage(manager.generateQuickReport());
// Main program flow
do {
diff --git a/src/main/java/financialtransactions/Inflow.java b/src/main/java/financialtransactions/Inflow.java
index 28480e8527..cdf0c52794 100644
--- a/src/main/java/financialtransactions/Inflow.java
+++ b/src/main/java/financialtransactions/Inflow.java
@@ -10,4 +10,9 @@ public Inflow(String name, double amount, String date) {
public void setCategory(Category category) {
super.category = category;
}
+
+ @Override
+ public String toSave() {
+ return super.toSave() + "|I\n";
+ }
}
diff --git a/src/main/java/financialtransactions/Outflow.java b/src/main/java/financialtransactions/Outflow.java
index 1584cc1ab9..173ab400c7 100644
--- a/src/main/java/financialtransactions/Outflow.java
+++ b/src/main/java/financialtransactions/Outflow.java
@@ -12,4 +12,9 @@ public Outflow(String name, double amount, String date) {
public void setCategory(Category category) {
this.category = category;
}
+
+ @Override
+ public String toSave() {
+ return super.toSave() + "|O\n";
+ }
}
diff --git a/src/main/java/financialtransactions/Reminder.java b/src/main/java/financialtransactions/Reminder.java
new file mode 100644
index 0000000000..b74c17e841
--- /dev/null
+++ b/src/main/java/financialtransactions/Reminder.java
@@ -0,0 +1,20 @@
+package financialtransactions;
+
+public class Reminder extends Transaction {
+ public enum Category {
+ INSTALLMENT, CREDITCARD, UTILITIES
+ }
+
+ public Reminder(String name, double amount, String date) {
+ super(name, -1.00 * amount, date);
+ }
+
+ public void setCategory(Category category) {
+ this.category = category;
+ }
+
+ @Override
+ public String toSave() {
+ return super.toSave() + "|R\n";
+ }
+}
diff --git a/src/main/java/financialtransactions/Transaction.java b/src/main/java/financialtransactions/Transaction.java
index 644138e447..b37327af31 100644
--- a/src/main/java/financialtransactions/Transaction.java
+++ b/src/main/java/financialtransactions/Transaction.java
@@ -46,12 +46,12 @@ public T getCategory() {
public String toString() {
return String.format("Name: %s, Amount: %.2f, Date: %s", name, amount, date.toString());
}
-
+
public String toSave() {
- return String.format("%s|%.2f|%s|%s\n", name, amount, date.toString(), category);
+ return String.format("%s|%.2f|%s|%s", name, amount, date.toString(), category);
}
- protected BaseDate getDate() {
+ public BaseDate getDate() {
return date;
}
}
diff --git a/src/main/java/financialtransactions/TransactionList.java b/src/main/java/financialtransactions/TransactionList.java
index b4e857c458..72e668ba12 100644
--- a/src/main/java/financialtransactions/TransactionList.java
+++ b/src/main/java/financialtransactions/TransactionList.java
@@ -1,5 +1,6 @@
package financialtransactions;
+import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Comparator;
@@ -115,5 +116,14 @@ public void sortListByName() {
public void sortListByDate() {
this.transactionList.sort(new DateComparator<>());
}
-
+
+ public double totalSpentInPastMonth() {
+ double amount = 0;
+ for (T transaction : transactionList) {
+ if (transaction.getDate().getDateTime().getMonth() == LocalDateTime.now().getMonth()) {
+ amount += transaction.getAmount();
+ }
+ }
+ return amount;
+ }
}
diff --git a/src/main/java/financialtransactions/TransactionManager.java b/src/main/java/financialtransactions/TransactionManager.java
index 049ba5946d..cb805bb5f9 100644
--- a/src/main/java/financialtransactions/TransactionManager.java
+++ b/src/main/java/financialtransactions/TransactionManager.java
@@ -5,13 +5,21 @@ public class TransactionManager {
private TransactionList> transactionList;
private TransactionList inflows;
private TransactionList outflows;
+ private TransactionList reminders;
+
+ private double budget = 0.00;
public TransactionManager() {
this.transactionList = new TransactionList<>();
this.inflows = new TransactionList<>();
this.outflows = new TransactionList<>();
+ this.reminders = new TransactionList<>();
}
-
+
+ public void setBudget(double budget) {
+ this.budget = budget;
+ }
+
public boolean addTransaction(Transaction> transaction) {
transactionList.addTransaction(transaction);
// transactionList.sortListByName();
@@ -25,6 +33,11 @@ public boolean addTransaction(Transaction> transaction) {
transactionList.setTransactionsType("Outflow");
return outflows.addTransaction(outflow);
}
+ if (transaction instanceof Reminder) {
+ Reminder reminder = (Reminder) transaction;
+ transactionList.setTransactionsType("Reminder");
+ return reminders.addTransaction(reminder);
+ }
System.out.println("Invalid transaction type.");
return false;
}
@@ -38,6 +51,9 @@ public boolean removeTransaction(int index) throws Exception{
if (transactionRemoved instanceof Outflow) {
return outflows.removeTransactionIndex(index);
}
+ if (transactionRemoved instanceof Reminder) {
+ return reminders.removeTransactionIndex(index);
+ }
return false;
}
@@ -55,6 +71,13 @@ public boolean removeOutflow(int index) throws Exception {
return outflows.removeTransactionIndex(numOfOutflows - index);
}
+ public boolean removeReminder(int index) throws Exception {
+ int numOfReminders = reminders.getTransactionListSize();
+ Transaction> transactionRemoved = reminders.getNthTransaction(numOfReminders - index);
+ transactionList.removeTransactionIndex(transactionList.getIndexOfParticularTransaction(transactionRemoved));
+ return reminders.removeTransactionIndex(numOfReminders - index);
+ }
+
public boolean editInflow(int index, Transaction> updatedTransaction) throws Exception {
int numOfInflows = inflows.getTransactionListSize();
Transaction> transactionEdited = inflows.getNthTransaction(numOfInflows - index);
@@ -71,6 +94,14 @@ public boolean editOutflow(int index, Transaction> updatedTransaction) throws
return outflows.editTransactionIndex(numOfOutflows - index, (Outflow) updatedTransaction);
}
+ public boolean editReminder(int index, Transaction> updatedTransaction) throws Exception {
+ int numOfReminders = reminders.getTransactionListSize();
+ Transaction> transactionEdited = reminders.getNthTransaction(numOfReminders - index);
+ transactionList.editTransactionIndex(transactionList.getIndexOfParticularTransaction(transactionEdited),
+ updatedTransaction);
+ return reminders.editTransactionIndex(numOfReminders - index, (Reminder) updatedTransaction);
+ }
+
public double getTotalBalance() {
double inflowBalance = inflows.getBalance();
double outflowBalance = outflows.getBalance();
@@ -106,10 +137,32 @@ public String showLastNTransactions(int n) throws Exception{
index++;
}
}
+
+ index = 1;
+ returnedText += "\nReminders:\nTransactions:\n";
+ for (int i = listSize - 1; i > listSize - n - 1; i--) {
+ Transaction> transaction = transactionList.getNthTransaction(i);
+ if (transaction instanceof Reminder) {
+ returnedText += String.format("%d) %s\n", index, transactionList.getNthTransaction(i).toString());
+ index++;
+ }
+ }
+
return returnedText;
}
public String toSave() {
- return inflows.toSave() + outflows.toSave();
+ return String.format("%.2f\n", budget) + inflows.toSave() + outflows.toSave() + reminders.toSave();
+ }
+
+ public String generateQuickReport() {
+ String baseString = "";
+ baseString += String.format("You have spent " +
+ "%.2f in the current month.\n", outflows.totalSpentInPastMonth());
+ baseString += String.format("With a budget of " +
+ "%.2f, you have %.2f left to spend.\n", budget, budget - outflows.totalSpentInPastMonth());
+ baseString += String.format("You have " +
+ "%d upcoming payments that require your attention", reminders.getTransactionListSize());
+ return baseString;
}
}
diff --git a/src/main/java/parser/Parser.java b/src/main/java/parser/Parser.java
index a42e08e048..25c5e86506 100644
--- a/src/main/java/parser/Parser.java
+++ b/src/main/java/parser/Parser.java
@@ -3,6 +3,7 @@
import customexceptions.IncompletePromptException;
import command.AddInflowCommand;
import command.AddOutflowCommand;
+import command.AddReminderCommand;
import command.BaseCommand;
import command.DeleteOutflowCommand;
import command.ExitCommand;
@@ -11,6 +12,10 @@
import command.HelpCommand;
import command.DeleteInflowCommand;
import command.EditOutflowCommand;
+import command.DeleteReminderCommand;
+import command.EditReminderCommand;
+import command.SetBudgetCommand;
+
import userinterface.UI;
public class Parser {
@@ -37,6 +42,11 @@ public BaseCommand parseCommand(String command) throws IncompletePromptException
throw new IncompletePromptException(command);
}
return new AddOutflowCommand(commandParts);
+ case "add-reminder":
+ if (commandParts.length < 6) {
+ throw new IncompletePromptException(command);
+ }
+ return new AddReminderCommand(commandParts);
case "delete-inflow":
if (commandParts.length < 2) {
throw new IncompletePromptException(command);
@@ -47,6 +57,11 @@ public BaseCommand parseCommand(String command) throws IncompletePromptException
throw new IncompletePromptException(command);
}
return new DeleteOutflowCommand(commandParts);
+ case "delete-reminder":
+ if (commandParts.length < 2) {
+ throw new IncompletePromptException(command);
+ }
+ return new DeleteReminderCommand(commandParts);
case "edit-inflow":
if (commandParts.length < 7) {
throw new IncompletePromptException(command);
@@ -57,6 +72,16 @@ public BaseCommand parseCommand(String command) throws IncompletePromptException
throw new IncompletePromptException(command);
}
return new EditOutflowCommand(commandParts);
+ case "edit-reminder":
+ if (commandParts.length < 7) {
+ throw new IncompletePromptException(command);
+ }
+ return new EditReminderCommand(commandParts);
+ case "set-budget":
+ if (commandParts.length < 2) {
+ throw new IncompletePromptException(command);
+ }
+ return new SetBudgetCommand(commandParts);
case "view-history":
if (commandParts.length < 2) {
throw new IncompletePromptException(command);
diff --git a/src/main/java/storage/Storage.java b/src/main/java/storage/Storage.java
index 4b863083c6..d9cc883ad7 100644
--- a/src/main/java/storage/Storage.java
+++ b/src/main/java/storage/Storage.java
@@ -2,6 +2,7 @@
import financialtransactions.Inflow;
import financialtransactions.Outflow;
+import financialtransactions.Reminder;
import financialtransactions.TransactionManager;
import user.BaseUser;
@@ -54,18 +55,23 @@ public TransactionManager loadFile(String username) {
TransactionManager manager = new TransactionManager();
try {
Scanner sc = new Scanner(f);
+ manager.setBudget(Double.parseDouble(sc.nextLine()));
while (sc.hasNext()) {
String[] transactionInfo = sc.nextLine().split("\\|");
- assert transactionInfo.length == 4 : "Transaction info should have 4 arguments";
+ assert transactionInfo.length == 5 : "Transaction info should have 5 arguments";
double amount = Double.parseDouble(transactionInfo[1]);
- if (!transactionInfo[1].startsWith("-")) {
+ if (transactionInfo[4].equals("I")) {
Inflow inflow = new Inflow(transactionInfo[0], amount, transactionInfo[2]);
inflow.setCategory(Inflow.Category.valueOf(transactionInfo[3]));
manager.addTransaction(inflow);
- } else {
+ } else if (transactionInfo[4].equals("O")){
Outflow outflow = new Outflow(transactionInfo[0], -amount, transactionInfo[2]);
outflow.setCategory(Outflow.Category.valueOf(transactionInfo[3]));
manager.addTransaction(outflow);
+ } else {
+ Reminder reminder = new Reminder(transactionInfo[0], -amount, transactionInfo[2]);
+ reminder.setCategory(Reminder.Category.valueOf(transactionInfo[3]));
+ manager.addTransaction(reminder);
}
}
sc.close();
diff --git a/src/test/java/financialtransactions/TransactionManagerTest.java b/src/test/java/financialtransactions/TransactionManagerTest.java
index 4e423eaf28..536d6f3630 100644
--- a/src/test/java/financialtransactions/TransactionManagerTest.java
+++ b/src/test/java/financialtransactions/TransactionManagerTest.java
@@ -16,8 +16,16 @@ public void toSaveTest() {
Outflow shopping = new Outflow("Shopping", 200, "23/05/2022 2000");
shopping.setCategory(Outflow.Category.SHOPPING);
managerTest.addTransaction(shopping);
-
- assertEquals("Salary payment|400.00|May 23 2022 07:00PM|INCOME\n" +
- "Shopping|-200.00|May 23 2022 08:00PM|SHOPPING\n", managerTest.toSave());
+
+ Reminder bill = new Reminder("Water bills", 64.30, "25/06/2025 1500");
+ bill.setCategory(Reminder.Category.UTILITIES);
+ managerTest.addTransaction(bill);
+
+ managerTest.setBudget(1500);
+
+ assertEquals("1500.00\n" +
+ "Salary payment|400.00|May 23 2022 07:00PM|INCOME|I\n" +
+ "Shopping|-200.00|May 23 2022 08:00PM|SHOPPING|O\n" +
+ "Water bills|-64.30|Jun 25 2025 03:00PM|UTILITIES|R\n", managerTest.toSave());
}
}
From 005cea211090af068ddcb7e76e04d2ce5de34516 Mon Sep 17 00:00:00 2001
From: dylansiew <88567790+dylansiew@users.noreply.github.com>
Date: Mon, 1 Apr 2024 18:46:50 +0800
Subject: [PATCH 106/208] typo handling
---
src/main/java/customexceptions/IncompletePromptException.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/java/customexceptions/IncompletePromptException.java b/src/main/java/customexceptions/IncompletePromptException.java
index ee1cdc0262..784104e604 100644
--- a/src/main/java/customexceptions/IncompletePromptException.java
+++ b/src/main/java/customexceptions/IncompletePromptException.java
@@ -15,7 +15,7 @@ private static String setMessage(String prompt){
message = "Sorry, your prompt appears incomplete. Could you finish your sentence?";
break;
} else if (instr.contains(prompt)){
- message = "Please prompt again with correct spelling.";
+ message = "Please prompt again with correct spelling. Did you mean to type " + instr;
break;
}
}
From 973af975ebbad7e6b26a96cead97f90f40837bbf Mon Sep 17 00:00:00 2001
From: ChongXern
Date: Mon, 1 Apr 2024 23:34:15 +0800
Subject: [PATCH 107/208] Modify bar chart class
---
.../TransactionManager.java | 8 ++-
src/main/java/storage/BarChart.java | 53 ++++++++++++++++++-
2 files changed, 58 insertions(+), 3 deletions(-)
diff --git a/src/main/java/financialtransactions/TransactionManager.java b/src/main/java/financialtransactions/TransactionManager.java
index 049ba5946d..13ff196f01 100644
--- a/src/main/java/financialtransactions/TransactionManager.java
+++ b/src/main/java/financialtransactions/TransactionManager.java
@@ -1,6 +1,8 @@
package financialtransactions;
+import storage.BarChart;
+
public class TransactionManager {
private TransactionList> transactionList;
private TransactionList inflows;
@@ -82,7 +84,7 @@ public String toString() {
return "Inflows:\n" + inflows.toString() + "\nOutflows:\n" + outflows.toString();
}
- public String showLastNTransactions(int n) throws Exception{
+ public String showLastNTransactions(int n, boolean isIncludeBarChart) throws Exception {
int listSize = transactionList.getTransactionListSize();
if (n > listSize) {
throw new Exception("Invalid index");
@@ -106,6 +108,10 @@ public String showLastNTransactions(int n) throws Exception{
index++;
}
}
+ if (isIncludeBarChart) {
+ BarChart> barChart = new BarChart<>(transactionList);
+ barChart.printBarChart();
+ }
return returnedText;
}
diff --git a/src/main/java/storage/BarChart.java b/src/main/java/storage/BarChart.java
index 3aaf47361a..f67ec993a3 100644
--- a/src/main/java/storage/BarChart.java
+++ b/src/main/java/storage/BarChart.java
@@ -1,7 +1,56 @@
package storage;
-public class BarChart {
- public BarChart() {
+import financialtransactions.Transaction;
+import financialtransactions.TransactionList;
+import java.util.HashMap;
+import java.util.Map;
+public class BarChart> {
+ private TransactionList transactionList;
+ private int totalTransactionsCount;
+ private HashMap categoryFrequencies;
+ private static final int TOTAL_BAR_SIZE = 50;
+ private static final int LEGEND_SIZE = 10;
+
+ public BarChart(TransactionList transactionList) {
+ this.transactionList = transactionList;
+ this.totalTransactionsCount = transactionList.getTransactionListSize();
+ this.categoryFrequencies = new HashMap<>();
+ //this.categoryPercentages = new HashMap<>();
+ }
+
+ public void computeTransactionFrequencies() throws Exception {
+ for (int i = 0; i < totalTransactionsCount; i++) {
+ String category = transactionList.getNthTransaction(i).getCategory().toString();
+ if (categoryFrequencies.containsKey(category)) {
+ int categoryCount = categoryFrequencies.get(category);
+ categoryFrequencies.put(category, categoryCount + 1);
+ } else {
+ categoryFrequencies.put(category, 1);
+ }
+ }
+ }
+
+ public void printBarChart() throws Exception {
+ computeTransactionFrequencies();
+ for (Map.Entry entry : categoryFrequencies.entrySet()) {
+ String category = entry.getKey();
+ Integer frequency = entry.getValue();
+ if (frequency == 0) {
+ continue;
+ }
+ double percentage = (double)frequency / totalTransactionsCount;
+ int barSize = (int)(percentage * TOTAL_BAR_SIZE);
+ System.out.print(category);
+ for (int i = 0; i < LEGEND_SIZE - category.length(); i++) {
+ System.out.print(" ");
+ }
+ System.out.print(": ");
+ for (int i = 0; i < barSize; i++) {
+ System.out.print("|");
+ }
+ percentage = Math.round(percentage * 10000.0) / 100.0;
+ System.out.println(" " + percentage + "%");
+ }
}
}
From 08f4f9de560d386e161884c917e021d4f89bb52e Mon Sep 17 00:00:00 2001
From: ChongXern
Date: Mon, 1 Apr 2024 23:44:29 +0800
Subject: [PATCH 108/208] Adjust params for show last n transactions without
bar chart
---
src/main/java/command/ViewHistoryCommand.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/java/command/ViewHistoryCommand.java b/src/main/java/command/ViewHistoryCommand.java
index 645bb73527..8c672fb0f4 100644
--- a/src/main/java/command/ViewHistoryCommand.java
+++ b/src/main/java/command/ViewHistoryCommand.java
@@ -20,6 +20,6 @@ public String execute(TransactionManager manager) throws Exception{
if (numTransactionsString != null) {
numTransactions = Integer.parseInt(numTransactionsString);
}
- return manager.showLastNTransactions(numTransactions);
+ return manager.showLastNTransactions(numTransactions, false);
}
}
From 6b7f2459fb1317e879b73e3a4b8c3450bfd8fbbd Mon Sep 17 00:00:00 2001
From: ChongXern
Date: Mon, 1 Apr 2024 23:47:13 +0800
Subject: [PATCH 109/208] Reorder static variables in the right position in bar
chart class
---
src/main/java/storage/BarChart.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/main/java/storage/BarChart.java b/src/main/java/storage/BarChart.java
index f67ec993a3..c7ad1b2fe9 100644
--- a/src/main/java/storage/BarChart.java
+++ b/src/main/java/storage/BarChart.java
@@ -6,11 +6,11 @@
import java.util.Map;
public class BarChart> {
+ private static final int TOTAL_BAR_SIZE = 50;
+ private static final int LEGEND_SIZE = 10;
private TransactionList transactionList;
private int totalTransactionsCount;
private HashMap categoryFrequencies;
- private static final int TOTAL_BAR_SIZE = 50;
- private static final int LEGEND_SIZE = 10;
public BarChart(TransactionList transactionList) {
this.transactionList = transactionList;
From ace737fd3a4f181171dcbac6de4cfd0a66b93381 Mon Sep 17 00:00:00 2001
From: Chong Xern <104547209+ChongXern@users.noreply.github.com>
Date: Tue, 2 Apr 2024 11:16:18 +0800
Subject: [PATCH 110/208] Add all in view history command to view everything
---
src/main/java/command/ViewHistoryCommand.java | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/src/main/java/command/ViewHistoryCommand.java b/src/main/java/command/ViewHistoryCommand.java
index 645bb73527..18bceddc72 100644
--- a/src/main/java/command/ViewHistoryCommand.java
+++ b/src/main/java/command/ViewHistoryCommand.java
@@ -10,15 +10,13 @@ public ViewHistoryCommand(String[] commandParts) {
public String execute(TransactionManager manager) throws Exception{
//@@author Kishen271828
- String numTransactionsString = null;
- for (String part : commandParts) {
- if (part.startsWith("n/")) {
- numTransactionsString = part.substring(2);
- }
- }
+ //String numTransactionsString = null;
int numTransactions = 0;
- if (numTransactionsString != null) {
+ if (commandParts[1].startsWith("n/")) {
+ String numTransactionsString = commandParts[1].substring(2);
numTransactions = Integer.parseInt(numTransactionsString);
+ } else if (commandParts[1].equals("all")) {
+ numTransactions = manager.getTransactionListSize();
}
return manager.showLastNTransactions(numTransactions);
}
From 298786fa8f99b552f3b209f26d15a47cce07e695 Mon Sep 17 00:00:00 2001
From: Chong Xern <104547209+ChongXern@users.noreply.github.com>
Date: Wed, 3 Apr 2024 00:43:15 +0800
Subject: [PATCH 111/208] Implement undo functionality
---
data/passwords.txt | 2 +-
src/main/java/command/AddInflowCommand.java | 9 +-
src/main/java/command/AddOutflowCommand.java | 11 ++-
src/main/java/command/AddReminderCommand.java | 9 +-
src/main/java/command/BaseCommand.java | 16 +++-
.../java/command/DeleteInflowCommand.java | 14 +--
.../java/command/DeleteOutflowCommand.java | 14 +--
.../java/command/DeleteReminderCommand.java | 4 +-
src/main/java/command/UndoCommand.java | 89 ++++++++++++++++++
.../IncompletePromptException.java | 4 +-
.../UserNotFoundException.java | 7 ++
.../UserNotFoundExcption.java | 7 --
src/main/java/financeproject/Main.java | 16 ++--
.../java/financeproject/data/passwords.txt | 1 +
.../financialtransactions/Transaction.java | 5 +-
.../TransactionList.java | 20 ++--
.../TransactionManager.java | 91 +++++++++++++------
src/main/java/parser/Parser.java | 72 ++++++++++-----
src/main/java/storage/Storage.java | 7 +-
src/main/java/user/InactivityTimer.java | 8 +-
20 files changed, 301 insertions(+), 105 deletions(-)
create mode 100644 src/main/java/command/UndoCommand.java
create mode 100644 src/main/java/customexceptions/UserNotFoundException.java
delete mode 100644 src/main/java/customexceptions/UserNotFoundExcption.java
create mode 100644 src/main/java/financeproject/data/passwords.txt
diff --git a/data/passwords.txt b/data/passwords.txt
index b82d33347d..962ea2afd5 100644
--- a/data/passwords.txt
+++ b/data/passwords.txt
@@ -1 +1 @@
-Bob|password
+Bob|password
\ No newline at end of file
diff --git a/src/main/java/command/AddInflowCommand.java b/src/main/java/command/AddInflowCommand.java
index 9d1b76654d..322cf47fb7 100644
--- a/src/main/java/command/AddInflowCommand.java
+++ b/src/main/java/command/AddInflowCommand.java
@@ -7,10 +7,10 @@ public class AddInflowCommand extends BaseCommand {
public AddInflowCommand(String[] commandParts) {
super(false, commandParts);
+ createInflow();
}
- public String execute(TransactionManager manager) {
- //@@author Kishen271828
+ private void createInflow() {
String inflowName = null;
double inflowAmount = 0;
String inflowDate = null;
@@ -31,9 +31,12 @@ public String execute(TransactionManager manager) {
}
}
String inflowDateTime = inflowDate + " " + inflowTime;
- Inflow inflow = new Inflow(inflowName, inflowAmount, inflowDateTime);
+ inflow = new Inflow(inflowName, inflowAmount, inflowDateTime);
assert inflowCategory != null;
inflow.setCategory(Inflow.Category.valueOf(inflowCategory.toUpperCase()));
+ }
+ public String execute(TransactionManager manager) {
+ //@@author Kishen271828
manager.addTransaction(inflow);
return "Ok. Added inflow";
}
diff --git a/src/main/java/command/AddOutflowCommand.java b/src/main/java/command/AddOutflowCommand.java
index 4c64b3f860..2cc71a588d 100644
--- a/src/main/java/command/AddOutflowCommand.java
+++ b/src/main/java/command/AddOutflowCommand.java
@@ -7,10 +7,10 @@ public class AddOutflowCommand extends BaseCommand {
public AddOutflowCommand(String[] commandParts) {
super(false, commandParts);
+ createOutflow();
}
- public String execute(TransactionManager manager) {
- //@@author Kishen271828
+ private void createOutflow() {
String outflowName = null;
double outflowAmount = 0.0;
String outflowDate = null;
@@ -32,8 +32,13 @@ public String execute(TransactionManager manager) {
}
String outflowDateTime = outflowDate + " " + outflowTime;
- Outflow outflow = new Outflow(outflowName, outflowAmount, outflowDateTime);
+ outflow = new Outflow(outflowName, outflowAmount, outflowDateTime);
+ assert outflowCategory != null;
outflow.setCategory(Outflow.Category.valueOf(outflowCategory.toUpperCase()));
+ }
+
+ public String execute(TransactionManager manager) {
+ //@@author Kishen271828
manager.addTransaction(outflow);
return "Ok. Added outflow";
}
diff --git a/src/main/java/command/AddReminderCommand.java b/src/main/java/command/AddReminderCommand.java
index 9e0a0164d8..8879c5934c 100644
--- a/src/main/java/command/AddReminderCommand.java
+++ b/src/main/java/command/AddReminderCommand.java
@@ -6,9 +6,10 @@
public class AddReminderCommand extends BaseCommand {
public AddReminderCommand(String[] commandParts) {
super(false, commandParts);
+ createReminder();
}
- public String execute(TransactionManager manager) {
+ private void createReminder() {
String reminderName = null;
double reminderAmount = 0.0;
String reminderDate = null;
@@ -29,8 +30,12 @@ public String execute(TransactionManager manager) {
}
}
String reminderDateTime = reminderDate + " " + reminderTime;
- Reminder reminder = new Reminder(reminderName, reminderAmount, reminderDateTime);
+ reminder = new Reminder(reminderName, reminderAmount, reminderDateTime);
+ assert reminderCategory != null;
reminder.setCategory(Reminder.Category.valueOf(reminderCategory.toUpperCase()));
+ }
+
+ public String execute(TransactionManager manager) {
manager.addTransaction(reminder);
return "Ok. Added reminder";
}
diff --git a/src/main/java/command/BaseCommand.java b/src/main/java/command/BaseCommand.java
index 4d725ba882..8bbbe84c6d 100644
--- a/src/main/java/command/BaseCommand.java
+++ b/src/main/java/command/BaseCommand.java
@@ -1,11 +1,16 @@
package command;
+import financialtransactions.Inflow;
+import financialtransactions.Outflow;
+import financialtransactions.Reminder;
import financialtransactions.TransactionManager;
public abstract class BaseCommand {
public boolean isExit;
String[] commandParts;
-
+ protected Inflow inflow;
+ protected Outflow outflow;
+ protected Reminder reminder;
public BaseCommand(Boolean isExit, String[] commandParts){
this.isExit = isExit;
this.commandParts = commandParts;
@@ -18,4 +23,13 @@ public boolean isExit() {
public void setIsExit(boolean isExit) {
this.isExit = isExit;
}
+ public Inflow getInflow() {
+ return inflow;
+ }
+ public Outflow getOutflow() {
+ return outflow;
+ }
+ public Reminder getReminder() {
+ return reminder;
+ }
}
diff --git a/src/main/java/command/DeleteInflowCommand.java b/src/main/java/command/DeleteInflowCommand.java
index 942f58804c..4215528cfc 100644
--- a/src/main/java/command/DeleteInflowCommand.java
+++ b/src/main/java/command/DeleteInflowCommand.java
@@ -3,19 +3,19 @@
import financialtransactions.TransactionManager;
public class DeleteInflowCommand extends BaseCommand {
+ private String inflowIndex = null;
public DeleteInflowCommand(String[] commandParts) {
super(false, commandParts);
}
public String execute(TransactionManager manager) throws Exception {
- String inflowIndex = null;
- for (String part : commandParts) {
- if (part.startsWith("i/")) {
- inflowIndex = part.substring(2);
- }
+ if (commandParts[1].startsWith("i/")) {
+ inflowIndex = commandParts[1].substring(2);
}
assert inflowIndex != null : "inflowIndex should not be null";
- manager.removeInflow(Integer.parseInt(inflowIndex));
- return "Ok. Inflow deleted";
+ int inflowIndexParsed = Integer.parseInt(inflowIndex);
+ inflow = manager.removeInflow(inflowIndexParsed);
+ //inflow = manager.getNthInflowFromList(inflowIndexParsed);
+ return "Ok. Inflow " + inflow.getName() + " | " + inflow.getCategory().toString() + " deleted";
}
}
diff --git a/src/main/java/command/DeleteOutflowCommand.java b/src/main/java/command/DeleteOutflowCommand.java
index 615c8e015e..b83dca3efc 100644
--- a/src/main/java/command/DeleteOutflowCommand.java
+++ b/src/main/java/command/DeleteOutflowCommand.java
@@ -1,5 +1,7 @@
package command;
+import financialtransactions.Outflow;
+import financialtransactions.Transaction;
import financialtransactions.TransactionManager;
public class DeleteOutflowCommand extends BaseCommand {
@@ -9,13 +11,13 @@ public DeleteOutflowCommand(String[] commandParts) {
public String execute(TransactionManager manager) throws Exception {
String outflowIndex = null;
- for (String part : commandParts) {
- if (part.startsWith("i/")) {
- outflowIndex = part.substring(2);
- }
+ if (commandParts[1].startsWith("i/")) {
+ outflowIndex = commandParts[1].substring(2);
}
assert outflowIndex != null : "outflowIndex should not be null";
- manager.removeOutflow(Integer.parseInt(outflowIndex));
- return "Ok. Outflow deleted";
+ int outflowIndexParsed = Integer.parseInt(outflowIndex);
+ outflow = manager.removeOutflow(outflowIndexParsed);
+ //outflow = manager.getNthOutflowFromList(outflowIndexParsed);
+ return "Ok. Outflow " + outflow.getName() + " " + outflow.getCategory().toString() + " deleted";
}
}
diff --git a/src/main/java/command/DeleteReminderCommand.java b/src/main/java/command/DeleteReminderCommand.java
index 3502281443..085ba2413f 100644
--- a/src/main/java/command/DeleteReminderCommand.java
+++ b/src/main/java/command/DeleteReminderCommand.java
@@ -15,7 +15,7 @@ public String execute(TransactionManager manager) throws Exception {
}
}
assert reminderIndex != null : "reminderIndex should not be null";
- manager.removeReminder(Integer.parseInt(reminderIndex));
- return "Ok. Reminder deleted";
+ reminder = manager.removeReminder(Integer.parseInt(reminderIndex));
+ return "Ok. Inflow " + reminder.getName() + " | " + reminder.getCategory().toString() + " deleted";
}
}
diff --git a/src/main/java/command/UndoCommand.java b/src/main/java/command/UndoCommand.java
new file mode 100644
index 0000000000..119a3ab67a
--- /dev/null
+++ b/src/main/java/command/UndoCommand.java
@@ -0,0 +1,89 @@
+package command;
+
+import financialtransactions.Inflow;
+import financialtransactions.Outflow;
+import financialtransactions.Reminder;
+import financialtransactions.TransactionManager;
+import user.InactivityTimer;
+
+public class UndoCommand extends BaseCommand {
+ private Inflow inflow;
+ private Outflow outflow;
+ private Reminder reminder;
+ private String action;
+ private boolean canUndo = false;
+ private InactivityTimer timer;
+
+ public UndoCommand(String[] commandParts) {
+ super(false, commandParts);
+ this.timer = new InactivityTimer();
+ action = commandParts[0];
+ }
+
+ public void setInflow(Inflow inflow) {
+ this.inflow = inflow;
+ this.outflow = null;
+ this.reminder = null;
+ }
+ public void setOutflow(Outflow outflow) {
+ this.inflow = null;
+ this.outflow = outflow;
+ this.reminder = null;
+ }
+ public void setReminder(Reminder reminder) {
+ this.inflow = null;
+ this.outflow = null;
+ this.reminder = reminder;
+ }
+
+ public String execute(TransactionManager manager) throws Exception {
+ if (!timer.canUndo()) {
+ System.out.println("Sorry, no longer able to undo the last action as 10 seconds have passed.");
+ }
+ if (commandParts == null) {
+ System.out.println("Sorry, there is no action to undo.");
+ }
+ switch (action) {
+ case "delete-inflow":
+ canUndo = true;
+ int inflowIndex = Integer.parseInt(commandParts[1].substring(2));
+ Inflow inflowToRemove = manager.getNthInflowFromList(inflowIndex);
+ manager.addTransaction(inflowToRemove);
+ break;
+ case "delete-outflow":
+ canUndo = true;
+ int outflowIndex = Integer.parseInt(commandParts[1].substring(2));
+ Outflow outflowToRemove = manager.getNthOutflowFromList(outflowIndex);
+ manager.addTransaction(outflowToRemove);
+ break;
+ case "delete-reminder":
+ canUndo = true;
+ int reminderIndex = Integer.parseInt(commandParts[1].substring(2));
+ Reminder reminderToRemove = manager.getNthReminderFromList(reminderIndex);
+ manager.addTransaction(reminderToRemove);
+ break;
+ case "add-inflow":
+ //commandToUndo = new DeleteInflowCommand(commandParts);
+ canUndo = true;
+ manager.removeTransaction(inflow);
+ //manager.addTransaction(commandBeforeUndo.inflow);
+ break;
+ case "add-outflow":
+ //commandToUndo = new DeleteOutflowCommand(commandParts);
+ canUndo = true;
+ manager.removeTransaction(outflow);
+ //manager.addTransaction(commandBeforeUndo.outflow);
+ break;
+ case "add-reminder":
+ //commandToUndo = new DeleteReminderCommand(commandParts);
+ canUndo = true;
+ manager.removeTransaction(reminder);
+ //manager.addTransaction(commandBeforeUndo.reminder);
+ break;
+ }
+ if (canUndo) {
+ return "Ok. " + action + " has been undone.";
+ }
+ return "Sorry, unable to undo action.";
+ }
+}
diff --git a/src/main/java/customexceptions/IncompletePromptException.java b/src/main/java/customexceptions/IncompletePromptException.java
index ee1cdc0262..321a8ff89d 100644
--- a/src/main/java/customexceptions/IncompletePromptException.java
+++ b/src/main/java/customexceptions/IncompletePromptException.java
@@ -2,7 +2,7 @@
public class IncompletePromptException extends Exception {
public static final String[] INSTRUCTIONS = {
- "add-inflow", "add-outflow", "delete-inflow", "delete-outflow", "quit"};
+ "add-inflow", "add-outflow", "delete-inflow", "delete-outflow", "undo", "quit"};
public IncompletePromptException(String line) {
super(setMessage(line));
@@ -11,7 +11,7 @@ public IncompletePromptException(String line) {
private static String setMessage(String prompt){
String message = "Sorry, prompt input is unknown.";
for(String instr: IncompletePromptException.INSTRUCTIONS){
- if(instr.equals(prompt)){
+ if (instr.equals(prompt)){
message = "Sorry, your prompt appears incomplete. Could you finish your sentence?";
break;
} else if (instr.contains(prompt)){
diff --git a/src/main/java/customexceptions/UserNotFoundException.java b/src/main/java/customexceptions/UserNotFoundException.java
new file mode 100644
index 0000000000..722ac3478f
--- /dev/null
+++ b/src/main/java/customexceptions/UserNotFoundException.java
@@ -0,0 +1,7 @@
+package customexceptions;
+
+public class UserNotFoundException extends Exception {
+ public UserNotFoundException() {
+ super("Username not found. Exiting program");
+ }
+}
diff --git a/src/main/java/customexceptions/UserNotFoundExcption.java b/src/main/java/customexceptions/UserNotFoundExcption.java
deleted file mode 100644
index aa429c0111..0000000000
--- a/src/main/java/customexceptions/UserNotFoundExcption.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package customexceptions;
-
-public class UserNotFoundExcption extends Exception {
- public UserNotFoundExcption() {
- super("Username not found. Exiting program");
- }
-}
diff --git a/src/main/java/financeproject/Main.java b/src/main/java/financeproject/Main.java
index 04eac2f472..5a4869740c 100644
--- a/src/main/java/financeproject/Main.java
+++ b/src/main/java/financeproject/Main.java
@@ -4,7 +4,7 @@
import customexceptions.ExceededAttemptsException;
import customexceptions.InactivityTimeoutException;
import customexceptions.IncompletePromptException;
-import customexceptions.UserNotFoundExcption;
+import customexceptions.UserNotFoundException;
import financialtransactions.TransactionManager;
import parser.Parser;
import storage.Storage;
@@ -14,8 +14,9 @@
import userinterface.UI;
public class Main {
- public static void main(String[] args) throws SecurityException, ExceededAttemptsException {
- Storage storage = new Storage("./data");
+ public static void main(String[] args) throws SecurityException {
+ // Storage storage = new Storage("./data"); // Storage manager for jar file
+ Storage storage = new Storage("../../../data");
UI ui = new UI();
ui.printMessage("Welcome. Enter your username and password to login.");
@@ -32,10 +33,7 @@ public static void main(String[] args) throws SecurityException, ExceededAttempt
response = ui.readInput();
user = storage.loadUser(response);
Authentication.authenticateUser(user, ui);
- } catch (UserNotFoundExcption e) {
- ui.printMessage(e.getMessage());
- return;
- } catch (ExceededAttemptsException e) {
+ } catch (UserNotFoundException | ExceededAttemptsException e) {
ui.printMessage(e.getMessage());
return;
}
@@ -58,7 +56,11 @@ public static void main(String[] args) throws SecurityException, ExceededAttempt
} catch (IncompletePromptException e) {
ui.printMessage(e.getMessage());
} catch (Exception e) {
+ StackTraceElement[] stackTrace = e.getStackTrace();
ui.printMessage("Uh-oh, something went wrong: " + e.getMessage());
+ for (StackTraceElement element : stackTrace) {
+ System.out.println("Exception caught in " + element.getClassName() + " at line " + element.getLineNumber());
+ }
}
storage.saveFile(user.getUsername(), manager);
diff --git a/src/main/java/financeproject/data/passwords.txt b/src/main/java/financeproject/data/passwords.txt
new file mode 100644
index 0000000000..962ea2afd5
--- /dev/null
+++ b/src/main/java/financeproject/data/passwords.txt
@@ -0,0 +1 @@
+Bob|password
\ No newline at end of file
diff --git a/src/main/java/financialtransactions/Transaction.java b/src/main/java/financialtransactions/Transaction.java
index b37327af31..329ba66e03 100644
--- a/src/main/java/financialtransactions/Transaction.java
+++ b/src/main/java/financialtransactions/Transaction.java
@@ -14,6 +14,7 @@ public abstract class Transaction {
protected T category;
public Transaction(String name, double amount, String date) {
+ assert name != null : "NULL name detected";
if (name.length() > NAME_MAX_LEN) {
System.out.println("Sorry, the description inputted exceeds the maximum permeable length. " +
"Please try again.");
@@ -28,11 +29,11 @@ public Transaction(String name, double amount, String date) {
}
}
- protected String getName() {
+ public String getName() {
return name;
}
- public double getAmount() {
+ protected double getAmount() {
return amount;
}
diff --git a/src/main/java/financialtransactions/TransactionList.java b/src/main/java/financialtransactions/TransactionList.java
index 72e668ba12..dd9f3f6f97 100644
--- a/src/main/java/financialtransactions/TransactionList.java
+++ b/src/main/java/financialtransactions/TransactionList.java
@@ -16,8 +16,8 @@ public int getTransactionListSize() {
return this.transactionList.size();
}
- public T getNthTransaction(int n) throws Exception{
- if(n >= this.transactionList.size()){
+ public Transaction> getNthTransaction(int n) throws Exception {
+ if (n >= this.transactionList.size()) {
throw new Exception("Invalid index");
}
return this.transactionList.get(n);
@@ -27,8 +27,8 @@ public int getIndexOfParticularTransaction(T particularTransaction) {
return this.transactionList.indexOf(particularTransaction);
}
- public boolean addTransaction(T newTransaction){
- if (newTransaction != null){
+ public boolean addTransaction(T newTransaction) {
+ if (newTransaction != null) {
transactionList.add(newTransaction);
return true;
}
@@ -76,7 +76,7 @@ protected void printTransactionsSafeInfo() {
int index = 1;
for (T transaction : transactionList) {
System.out.print(index++);
- System.out.println(" " + transaction.getName() + " " + transaction.getCategory());
+ System.out.println(" " + transaction.getName() + " | " + transaction.getCategory() + " | " + transaction.getClass());
}
}
@@ -109,7 +109,15 @@ public int compare(T o1, T o2) {
}
}
- public void sortListByName() {
+ public class FlowComparator> implements Comparator {
+ @Override
+ public int compare(T o1, T o2) {
+ return o2.getClass().toString().compareTo(o1.getClass().toString());
+ }
+ }
+
+ public void sortList() {
+ this.transactionList.sort(new FlowComparator<>());
this.transactionList.sort(new NameComparator<>());
}
diff --git a/src/main/java/financialtransactions/TransactionManager.java b/src/main/java/financialtransactions/TransactionManager.java
index b347a24a34..83257d087c 100644
--- a/src/main/java/financialtransactions/TransactionManager.java
+++ b/src/main/java/financialtransactions/TransactionManager.java
@@ -22,62 +22,70 @@ public void setBudget(double budget) {
this.budget = budget;
}
- public boolean addTransaction(Transaction> transaction) {
+ public void addTransaction(Transaction> transaction) {
transactionList.addTransaction(transaction);
- // transactionList.sortListByName();
- if (transaction instanceof Inflow) {
- Inflow inflow = (Inflow) transaction;
+ // transactionList.sortList();
+ if (transaction instanceof Inflow inflow) {
transactionList.setTransactionsType("Inflow");
- return inflows.addTransaction(inflow);
+ inflows.addTransaction(inflow);
+ return;
}
- if (transaction instanceof Outflow) {
- Outflow outflow = (Outflow) transaction;
+ if (transaction instanceof Outflow outflow) {
transactionList.setTransactionsType("Outflow");
- return outflows.addTransaction(outflow);
+ outflows.addTransaction(outflow);
+ return;
}
- if (transaction instanceof Reminder) {
- Reminder reminder = (Reminder) transaction;
+ if (transaction instanceof Reminder reminder) {
transactionList.setTransactionsType("Reminder");
- return reminders.addTransaction(reminder);
+ reminders.addTransaction(reminder);
+ return;
}
System.out.println("Invalid transaction type.");
- return false;
}
- public boolean removeTransaction(int index) throws Exception{
+ public void removeTransaction(Transaction> transaction) {
+ int index = transactionList.getIndexOfParticularTransaction(transaction);
transactionList.removeTransactionIndex(index);
- Transaction> transactionRemoved = transactionList.getNthTransaction(index);
- if (transactionRemoved instanceof Inflow) {
- return inflows.removeTransactionIndex(index);
+ if (transaction instanceof Inflow inflow) {
+ int inflowIndex = inflows.getIndexOfParticularTransaction(inflow);
+ inflows.removeTransactionIndex(inflowIndex);
+ return;
}
- if (transactionRemoved instanceof Outflow) {
- return outflows.removeTransactionIndex(index);
+ if (transaction instanceof Outflow outflow) {
+ int outflowIndex = outflows.getIndexOfParticularTransaction(outflow);
+ outflows.removeTransactionIndex(outflowIndex);
+ return;
}
- if (transactionRemoved instanceof Reminder) {
- return reminders.removeTransactionIndex(index);
+ if (transaction instanceof Reminder reminder) {
+ int reminderIndex = reminders.getIndexOfParticularTransaction(reminder);
+ reminders.removeTransactionIndex(reminderIndex);
+ return;
}
- return false;
+ System.out.println("Invalid transaction type.");
}
- public boolean removeInflow(int index) throws Exception {
+ public Inflow removeInflow(int index) throws Exception {
int numOfInflows = inflows.getTransactionListSize();
- Transaction> transactionRemoved = inflows.getNthTransaction(numOfInflows - index);
+ Inflow transactionRemoved = (Inflow) inflows.getNthTransaction(numOfInflows - index);
transactionList.removeTransactionIndex(transactionList.getIndexOfParticularTransaction(transactionRemoved));
- return inflows.removeTransactionIndex(numOfInflows - index);
+ inflows.removeTransactionIndex(numOfInflows - index);
+ return transactionRemoved;
}
- public boolean removeOutflow(int index) throws Exception {
+ public Outflow removeOutflow(int index) throws Exception {
int numOfOutflows = outflows.getTransactionListSize();
- Transaction> transactionRemoved = outflows.getNthTransaction(numOfOutflows - index);
+ Outflow transactionRemoved = (Outflow) outflows.getNthTransaction(numOfOutflows - index);
transactionList.removeTransactionIndex(transactionList.getIndexOfParticularTransaction(transactionRemoved));
- return outflows.removeTransactionIndex(numOfOutflows - index);
+ outflows.removeTransactionIndex(numOfOutflows - index);
+ return transactionRemoved;
}
- public boolean removeReminder(int index) throws Exception {
+ public Reminder removeReminder(int index) throws Exception {
int numOfReminders = reminders.getTransactionListSize();
- Transaction> transactionRemoved = reminders.getNthTransaction(numOfReminders - index);
+ Reminder transactionRemoved = (Reminder) reminders.getNthTransaction(numOfReminders - index);
transactionList.removeTransactionIndex(transactionList.getIndexOfParticularTransaction(transactionRemoved));
- return reminders.removeTransactionIndex(numOfReminders - index);
+ reminders.removeTransactionIndex(numOfReminders - index);
+ return transactionRemoved;
}
public boolean editInflow(int index, Transaction> updatedTransaction) throws Exception {
@@ -172,4 +180,27 @@ public String generateQuickReport() {
"%d upcoming payments that require your attention", reminders.getTransactionListSize());
return baseString;
}
+
+ public int getTransactionListSize() {
+ return transactionList.getTransactionListSize();
+ }
+
+ public int findTransactionIndex(Transaction> transaction) {
+ return transactionList.getIndexOfParticularTransaction(transaction);
+ }
+
+ public Inflow getNthInflowFromList(int n) throws Exception {
+ return (Inflow) inflows.getNthTransaction(n - 1);
+ }
+
+ public Outflow getNthOutflowFromList(int n) throws Exception {
+ return (Outflow) outflows.getNthTransaction(n - 1);
+ }
+
+ public Reminder getNthReminderFromList(int n) throws Exception {
+ return (Reminder) reminders.getNthTransaction(n -1);
+ }
+ public void printTransactionListSafeInfo() {
+ transactionList.printTransactionsSafeInfo();
+ }
}
diff --git a/src/main/java/parser/Parser.java b/src/main/java/parser/Parser.java
index 25c5e86506..e3cf160032 100644
--- a/src/main/java/parser/Parser.java
+++ b/src/main/java/parser/Parser.java
@@ -1,32 +1,28 @@
package parser;
+import command.*;
import customexceptions.IncompletePromptException;
-import command.AddInflowCommand;
-import command.AddOutflowCommand;
-import command.AddReminderCommand;
-import command.BaseCommand;
-import command.DeleteOutflowCommand;
-import command.ExitCommand;
-import command.ViewHistoryCommand;
-import command.EditInflowCommand;
-import command.HelpCommand;
-import command.DeleteInflowCommand;
-import command.EditOutflowCommand;
-import command.DeleteReminderCommand;
-import command.EditReminderCommand;
-import command.SetBudgetCommand;
-
+import financialtransactions.Inflow;
+import financialtransactions.Outflow;
+import financialtransactions.Reminder;
import userinterface.UI;
public class Parser {
UI ui;
+ // For undo functionality
+ String[] lastCommandParts = null;
+ BaseCommand lastCommand;
+ Inflow lastInflow;
+ Outflow lastOutflow;
+ Reminder lastReminder;
+
public Parser(UI ui) {
this.ui = ui;
}
- public BaseCommand parseCommand(String command) throws IncompletePromptException, Exception {
+ public BaseCommand parseCommand(String command) throws Exception {
String[] commandParts = command.split("\\s+");
String action = commandParts[0];
switch (action) {
@@ -36,32 +32,53 @@ public BaseCommand parseCommand(String command) throws IncompletePromptException
if (commandParts.length < 6) {
throw new IncompletePromptException(command);
}
- return new AddInflowCommand(commandParts);
+ lastCommandParts = commandParts;
+ lastCommand = new AddInflowCommand(commandParts);
+ lastInflow = lastCommand.getInflow();
+ return lastCommand;
case "add-outflow":
if (commandParts.length < 6) {
throw new IncompletePromptException(command);
}
- return new AddOutflowCommand(commandParts);
+ lastCommandParts = commandParts;
+ lastCommand = new AddOutflowCommand(commandParts);
+ lastOutflow = lastCommand.getOutflow();
+ return lastCommand;
case "add-reminder":
if (commandParts.length < 6) {
throw new IncompletePromptException(command);
}
- return new AddReminderCommand(commandParts);
+ lastCommandParts = commandParts;
+ lastCommand = new AddReminderCommand(commandParts);
+ lastReminder = lastCommand.getReminder();
+ return lastCommand;
case "delete-inflow":
if (commandParts.length < 2) {
throw new IncompletePromptException(command);
}
- return new DeleteInflowCommand(commandParts);
+ lastCommandParts = commandParts;
+ lastCommand = new DeleteInflowCommand(commandParts);
+ lastInflow = lastCommand.getInflow();
+ if (lastInflow == null) {
+ System.out.println("Last inflow is null");
+ }
+ return lastCommand;
case "delete-outflow":
if (commandParts.length < 2) {
throw new IncompletePromptException(command);
}
- return new DeleteOutflowCommand(commandParts);
+ lastCommandParts = commandParts;
+ lastCommand = new DeleteOutflowCommand(commandParts);
+ lastOutflow = lastCommand.getOutflow();
+ return lastCommand;
case "delete-reminder":
if (commandParts.length < 2) {
throw new IncompletePromptException(command);
}
- return new DeleteReminderCommand(commandParts);
+ lastCommandParts = commandParts;
+ lastCommand = new DeleteReminderCommand(commandParts);
+ lastReminder = lastCommand.getReminder();
+ return lastCommand;
case "edit-inflow":
if (commandParts.length < 7) {
throw new IncompletePromptException(command);
@@ -87,6 +104,17 @@ public BaseCommand parseCommand(String command) throws IncompletePromptException
throw new IncompletePromptException(command);
}
return new ViewHistoryCommand(commandParts);
+ case "undo":
+ UndoCommand undoCommand = new UndoCommand(lastCommandParts);
+ if (lastCommandParts[0].contains("inflow")) {
+ undoCommand.setInflow(lastInflow);
+ } else if (lastCommandParts[0].contains("outflow")) {
+ undoCommand.setOutflow(lastOutflow);
+ } else if (lastCommandParts[0].contains("reminder")) {
+ undoCommand.setReminder(lastReminder);
+ }
+ lastCommandParts = null;
+ return undoCommand;
case "quit":
return new ExitCommand(commandParts);
default:
diff --git a/src/main/java/storage/Storage.java b/src/main/java/storage/Storage.java
index d9cc883ad7..7ec9ceea07 100644
--- a/src/main/java/storage/Storage.java
+++ b/src/main/java/storage/Storage.java
@@ -12,7 +12,7 @@
import java.io.IOException;
import java.util.Scanner;
-import customexceptions.UserNotFoundExcption;
+import customexceptions.UserNotFoundException;
public class Storage {
private final String filePath;
@@ -31,7 +31,7 @@ public void addNewUser(String username, String password) {
}
}
- public BaseUser loadUser(String username) throws UserNotFoundExcption{
+ public BaseUser loadUser(String username) throws UserNotFoundException {
File f = new File(filePath + "/passwords.txt");
try {
this.sc = new Scanner(f);
@@ -43,9 +43,10 @@ public BaseUser loadUser(String username) throws UserNotFoundExcption{
return newUser;
}
}
- throw new UserNotFoundExcption();
+ throw new UserNotFoundException();
} catch (FileNotFoundException e) {
createFileDir();
+ System.out.println("File is not found, please try again.");
return null;
}
}
diff --git a/src/main/java/user/InactivityTimer.java b/src/main/java/user/InactivityTimer.java
index 4d4ef1dc2e..9345986d00 100644
--- a/src/main/java/user/InactivityTimer.java
+++ b/src/main/java/user/InactivityTimer.java
@@ -5,6 +5,7 @@
public class InactivityTimer {
public static final int INACTIVITY_TIME = 180_000;
public static final int GRACE_TIME = 30_000;
+ public static final int PERMITTED_UNDO_TIME = 10_000;
private long startTime;
public InactivityTimer() {
@@ -24,5 +25,10 @@ public void checkTimeElapsed() throws InactivityTimeoutException {
} else if (timeDifference >= INACTIVITY_TIME - GRACE_TIME) {
throw new InactivityTimeoutException(false, true);
}
- }
+ }
+
+ public boolean canUndo() {
+ long timeDifference = System.currentTimeMillis() - startTime;
+ return timeDifference <= PERMITTED_UNDO_TIME;
+ }
}
From df7577129710c29ecc6c410b864efcc20a735e9e Mon Sep 17 00:00:00 2001
From: Chong Xern <104547209+ChongXern@users.noreply.github.com>
Date: Wed, 3 Apr 2024 00:43:21 +0800
Subject: [PATCH 112/208] Create CategoryNotFoundException.java
---
src/main/java/customexceptions/CategoryNotFoundException.java | 4 ++++
1 file changed, 4 insertions(+)
create mode 100644 src/main/java/customexceptions/CategoryNotFoundException.java
diff --git a/src/main/java/customexceptions/CategoryNotFoundException.java b/src/main/java/customexceptions/CategoryNotFoundException.java
new file mode 100644
index 0000000000..f7ada40ea5
--- /dev/null
+++ b/src/main/java/customexceptions/CategoryNotFoundException.java
@@ -0,0 +1,4 @@
+package customexceptions;
+
+public class CategoryNotFoundException {
+}
From 11f62514d53a98e10592fa0652157a964ce7c667 Mon Sep 17 00:00:00 2001
From: ChongXern
Date: Wed, 3 Apr 2024 00:54:30 +0800
Subject: [PATCH 113/208] Adjust instanceof in TransactionManager
---
.../TransactionManager.java | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/src/main/java/financialtransactions/TransactionManager.java b/src/main/java/financialtransactions/TransactionManager.java
index 83257d087c..426ffa0f7c 100644
--- a/src/main/java/financialtransactions/TransactionManager.java
+++ b/src/main/java/financialtransactions/TransactionManager.java
@@ -25,17 +25,20 @@ public void setBudget(double budget) {
public void addTransaction(Transaction> transaction) {
transactionList.addTransaction(transaction);
// transactionList.sortList();
- if (transaction instanceof Inflow inflow) {
+ if (transaction instanceof Inflow) {
+ Inflow inflow = (Inflow) transaction;
transactionList.setTransactionsType("Inflow");
inflows.addTransaction(inflow);
return;
}
- if (transaction instanceof Outflow outflow) {
+ if (transaction instanceof Outflow) {
+ Outflow outflow = (Outflow) transaction;
transactionList.setTransactionsType("Outflow");
outflows.addTransaction(outflow);
return;
}
- if (transaction instanceof Reminder reminder) {
+ if (transaction instanceof Reminder) {
+ Reminder reminder = (Reminder) transaction;
transactionList.setTransactionsType("Reminder");
reminders.addTransaction(reminder);
return;
@@ -46,17 +49,20 @@ public void addTransaction(Transaction> transaction) {
public void removeTransaction(Transaction> transaction) {
int index = transactionList.getIndexOfParticularTransaction(transaction);
transactionList.removeTransactionIndex(index);
- if (transaction instanceof Inflow inflow) {
+ if (transaction instanceof Inflow) {
+ Inflow inflow = (Inflow) transaction;
int inflowIndex = inflows.getIndexOfParticularTransaction(inflow);
inflows.removeTransactionIndex(inflowIndex);
return;
}
- if (transaction instanceof Outflow outflow) {
+ if (transaction instanceof Outflow) {
+ Outflow outflow = (Outflow) transaction;
int outflowIndex = outflows.getIndexOfParticularTransaction(outflow);
outflows.removeTransactionIndex(outflowIndex);
return;
}
- if (transaction instanceof Reminder reminder) {
+ if (transaction instanceof Reminder) {
+ Reminder reminder = (Reminder) transaction;
int reminderIndex = reminders.getIndexOfParticularTransaction(reminder);
reminders.removeTransactionIndex(reminderIndex);
return;
From f13e3a593ad99457e30e80437885c0da9cb0a0e8 Mon Sep 17 00:00:00 2001
From: ChongXern
Date: Wed, 3 Apr 2024 01:05:43 +0800
Subject: [PATCH 114/208] Fix checkstyle errors
---
src/main/java/command/BaseCommand.java | 4 ++--
src/main/java/command/DeleteOutflowCommand.java | 2 --
src/main/java/command/UndoCommand.java | 2 ++
src/main/java/financeproject/Main.java | 4 ----
.../financialtransactions/TransactionList.java | 3 ++-
src/main/java/parser/Parser.java | 16 +++++++++++++++-
6 files changed, 21 insertions(+), 10 deletions(-)
diff --git a/src/main/java/command/BaseCommand.java b/src/main/java/command/BaseCommand.java
index 8bbbe84c6d..656b43c9d6 100644
--- a/src/main/java/command/BaseCommand.java
+++ b/src/main/java/command/BaseCommand.java
@@ -6,11 +6,11 @@
import financialtransactions.TransactionManager;
public abstract class BaseCommand {
- public boolean isExit;
- String[] commandParts;
protected Inflow inflow;
protected Outflow outflow;
protected Reminder reminder;
+ public boolean isExit;
+ String[] commandParts;
public BaseCommand(Boolean isExit, String[] commandParts){
this.isExit = isExit;
this.commandParts = commandParts;
diff --git a/src/main/java/command/DeleteOutflowCommand.java b/src/main/java/command/DeleteOutflowCommand.java
index b83dca3efc..cc79f7eaf6 100644
--- a/src/main/java/command/DeleteOutflowCommand.java
+++ b/src/main/java/command/DeleteOutflowCommand.java
@@ -1,7 +1,5 @@
package command;
-import financialtransactions.Outflow;
-import financialtransactions.Transaction;
import financialtransactions.TransactionManager;
public class DeleteOutflowCommand extends BaseCommand {
diff --git a/src/main/java/command/UndoCommand.java b/src/main/java/command/UndoCommand.java
index 119a3ab67a..13a2904cd5 100644
--- a/src/main/java/command/UndoCommand.java
+++ b/src/main/java/command/UndoCommand.java
@@ -80,6 +80,8 @@ public String execute(TransactionManager manager) throws Exception {
manager.removeTransaction(reminder);
//manager.addTransaction(commandBeforeUndo.reminder);
break;
+ default:
+ return "Sorry, unable to undo action.";
}
if (canUndo) {
return "Ok. " + action + " has been undone.";
diff --git a/src/main/java/financeproject/Main.java b/src/main/java/financeproject/Main.java
index 5a4869740c..1534086c36 100644
--- a/src/main/java/financeproject/Main.java
+++ b/src/main/java/financeproject/Main.java
@@ -56,11 +56,7 @@ public static void main(String[] args) throws SecurityException {
} catch (IncompletePromptException e) {
ui.printMessage(e.getMessage());
} catch (Exception e) {
- StackTraceElement[] stackTrace = e.getStackTrace();
ui.printMessage("Uh-oh, something went wrong: " + e.getMessage());
- for (StackTraceElement element : stackTrace) {
- System.out.println("Exception caught in " + element.getClassName() + " at line " + element.getLineNumber());
- }
}
storage.saveFile(user.getUsername(), manager);
diff --git a/src/main/java/financialtransactions/TransactionList.java b/src/main/java/financialtransactions/TransactionList.java
index dd9f3f6f97..88a351c7e9 100644
--- a/src/main/java/financialtransactions/TransactionList.java
+++ b/src/main/java/financialtransactions/TransactionList.java
@@ -76,7 +76,8 @@ protected void printTransactionsSafeInfo() {
int index = 1;
for (T transaction : transactionList) {
System.out.print(index++);
- System.out.println(" " + transaction.getName() + " | " + transaction.getCategory() + " | " + transaction.getClass());
+ System.out.println(" " + transaction.getName() + " | " + transaction.getCategory() +
+ " | " + transaction.getClass());
}
}
diff --git a/src/main/java/parser/Parser.java b/src/main/java/parser/Parser.java
index e3cf160032..9224900185 100644
--- a/src/main/java/parser/Parser.java
+++ b/src/main/java/parser/Parser.java
@@ -1,6 +1,20 @@
package parser;
-import command.*;
+import command.AddInflowCommand;
+import command.AddOutflowCommand;
+import command.AddReminderCommand;
+import command.DeleteInflowCommand;
+import command.DeleteOutflowCommand;
+import command.DeleteReminderCommand;
+import command.SetBudgetCommand;
+import command.EditInflowCommand;
+import command.EditOutflowCommand;
+import command.EditReminderCommand;
+import command.UndoCommand;
+import command.ExitCommand;
+import command.ViewHistoryCommand;
+import command.BaseCommand;
+import command.HelpCommand;
import customexceptions.IncompletePromptException;
import financialtransactions.Inflow;
import financialtransactions.Outflow;
From 19cc0fbc1e58e22dfc43c4e769e9105df5dd49c3 Mon Sep 17 00:00:00 2001
From: ChongXern
Date: Wed, 3 Apr 2024 01:10:47 +0800
Subject: [PATCH 115/208] Fix checkstyle errors
---
src/main/java/command/BaseCommand.java | 2 +-
src/main/java/financialtransactions/TransactionList.java | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/main/java/command/BaseCommand.java b/src/main/java/command/BaseCommand.java
index 656b43c9d6..78e17b360f 100644
--- a/src/main/java/command/BaseCommand.java
+++ b/src/main/java/command/BaseCommand.java
@@ -9,8 +9,8 @@ public abstract class BaseCommand {
protected Inflow inflow;
protected Outflow outflow;
protected Reminder reminder;
- public boolean isExit;
String[] commandParts;
+ public boolean isExit;
public BaseCommand(Boolean isExit, String[] commandParts){
this.isExit = isExit;
this.commandParts = commandParts;
diff --git a/src/main/java/financialtransactions/TransactionList.java b/src/main/java/financialtransactions/TransactionList.java
index 88a351c7e9..543492c8ce 100644
--- a/src/main/java/financialtransactions/TransactionList.java
+++ b/src/main/java/financialtransactions/TransactionList.java
@@ -76,8 +76,8 @@ protected void printTransactionsSafeInfo() {
int index = 1;
for (T transaction : transactionList) {
System.out.print(index++);
- System.out.println(" " + transaction.getName() + " | " + transaction.getCategory() +
- " | " + transaction.getClass());
+ System.out.print(" " + transaction.getName() + " | " + transaction.getCategory());
+ System.out.println(" | " + transaction.getClass());
}
}
From 26131d9912000b8cf36c21faea4a762c15ab272c Mon Sep 17 00:00:00 2001
From: ChongXern
Date: Wed, 3 Apr 2024 01:15:04 +0800
Subject: [PATCH 116/208] Fix checkstyle error
---
src/main/java/command/BaseCommand.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/java/command/BaseCommand.java b/src/main/java/command/BaseCommand.java
index 78e17b360f..38d6c55b6e 100644
--- a/src/main/java/command/BaseCommand.java
+++ b/src/main/java/command/BaseCommand.java
@@ -6,11 +6,11 @@
import financialtransactions.TransactionManager;
public abstract class BaseCommand {
+ public boolean isExit;
protected Inflow inflow;
protected Outflow outflow;
protected Reminder reminder;
String[] commandParts;
- public boolean isExit;
public BaseCommand(Boolean isExit, String[] commandParts){
this.isExit = isExit;
this.commandParts = commandParts;
From 016614a87640e7610300e155b579e0711622115d Mon Sep 17 00:00:00 2001
From: chowy
Date: Wed, 3 Apr 2024 21:09:06 +0800
Subject: [PATCH 117/208] Added a feature to generate report for a past month,
updated getQuickReport to show reminders that have not passed.
---
.../java/command/GenerateReportCommand.java | 64 +++++++++++++++++++
src/main/java/command/HelpCommand.java | 3 +-
src/main/java/financeproject/Main.java | 3 +-
.../TransactionList.java | 29 ++++++++-
.../TransactionManager.java | 40 ++++++++++--
src/main/java/parser/Parser.java | 6 ++
src/main/java/storage/Storage.java | 1 +
7 files changed, 136 insertions(+), 10 deletions(-)
create mode 100644 src/main/java/command/GenerateReportCommand.java
diff --git a/src/main/java/command/GenerateReportCommand.java b/src/main/java/command/GenerateReportCommand.java
new file mode 100644
index 0000000000..e10660093a
--- /dev/null
+++ b/src/main/java/command/GenerateReportCommand.java
@@ -0,0 +1,64 @@
+package command;
+
+import financialtransactions.TransactionManager;
+
+public class GenerateReportCommand extends BaseCommand {
+
+ public GenerateReportCommand(String[] commandParts) {
+ super(false,commandParts);
+ }
+
+ public String execute(TransactionManager manager) throws Exception{
+ String monthString = "";
+ int month = 0;
+ int year = 0;
+ if (commandParts[1].startsWith("m/")) {
+ monthString = commandParts[1].substring(2);
+ }
+ switch (monthString) {
+ case "JAN":
+ month = 1;
+ break;
+ case "FEB":
+ month = 2;
+ break;
+ case "MAR":
+ month = 3;
+ break;
+ case "APR":
+ month = 4;
+ break;
+ case "MAY":
+ month = 5;
+ break;
+ case "JUN":
+ month = 6;
+ break;
+ case "JUL":
+ month = 7;
+ break;
+ case "AUG":
+ month = 8;
+ break;
+ case "SEP":
+ month = 9;
+ break;
+ case "OCT":
+ month = 10;
+ break;
+ case "NOV":
+ month = 11;
+ break;
+ case "DEC":
+ month = 12;
+ break;
+ default:
+ return "Month must be in the form of MMM";
+ }
+ if (commandParts[2].startsWith("y/")) {
+ year = Integer.parseInt(commandParts[2].substring(2));
+ }
+ return manager.generateFullReport(monthString, month, year);
+ }
+
+}
diff --git a/src/main/java/command/HelpCommand.java b/src/main/java/command/HelpCommand.java
index 09deaf1750..a4fa803030 100644
--- a/src/main/java/command/HelpCommand.java
+++ b/src/main/java/command/HelpCommand.java
@@ -22,7 +22,8 @@ public String execute(TransactionManager manager) throws Exception {
baseString += "9) delete-reminder i/INDEX n/NAME a/AMOUNT d/DATE t/TIME c/CATEGORY\n";
baseString += "10) set-budget a/AMOUNT\n";
baseString += "11) view-history n/NUM \n";
- baseString += "12) quit \n";
+ baseString += "12) generate-report m/MONTH y/YEAR\n";
+ baseString += "13) quit \n";
baseString += "_____________";
return baseString;
}
diff --git a/src/main/java/financeproject/Main.java b/src/main/java/financeproject/Main.java
index 1534086c36..0b39251165 100644
--- a/src/main/java/financeproject/Main.java
+++ b/src/main/java/financeproject/Main.java
@@ -15,8 +15,7 @@
public class Main {
public static void main(String[] args) throws SecurityException {
- // Storage storage = new Storage("./data"); // Storage manager for jar file
- Storage storage = new Storage("../../../data");
+ Storage storage = new Storage("./data"); // Storage manager for jar file
UI ui = new UI();
ui.printMessage("Welcome. Enter your username and password to login.");
diff --git a/src/main/java/financialtransactions/TransactionList.java b/src/main/java/financialtransactions/TransactionList.java
index 543492c8ce..d9300b1b43 100644
--- a/src/main/java/financialtransactions/TransactionList.java
+++ b/src/main/java/financialtransactions/TransactionList.java
@@ -64,6 +64,7 @@ public String toString(){
return baseString.toString();
}
+ //@@author chenhowy
public String toSave() {
StringBuilder baseString = new StringBuilder();
for (T transaction : transactionList) {
@@ -71,7 +72,7 @@ public String toSave() {
}
return baseString.toString();
}
-
+ //@@author
protected void printTransactionsSafeInfo() {
int index = 1;
for (T transaction : transactionList) {
@@ -125,14 +126,36 @@ public void sortList() {
public void sortListByDate() {
this.transactionList.sort(new DateComparator<>());
}
-
+ //@@author chenhowy
public double totalSpentInPastMonth() {
double amount = 0;
for (T transaction : transactionList) {
- if (transaction.getDate().getDateTime().getMonth() == LocalDateTime.now().getMonth()) {
+ if ((transaction.getDate().getDateTime().getMonth() == LocalDateTime.now().getMonth()) &&
+ transaction.getDate().getDateTime().isBefore(LocalDateTime.now())) {
+ amount += transaction.getAmount();
+ }
+ }
+ return amount;
+ }
+
+ public double getTotalSpentInMonth(int month, int year) {
+ double amount = 0;
+ for (T transaction : transactionList) {
+ if (transaction.getDate().getDateTime().getMonthValue() == month &&
+ transaction.getDate().getDateTime().getYear() == year) {
amount += transaction.getAmount();
}
}
return amount;
}
+ public int getTransactionsAfterToday() {
+ int numberOfTransactions = 0;
+ LocalDateTime today = LocalDateTime.now();
+ for (T transaction : transactionList) {
+ if (transaction.getDate().getDateTime().isAfter(today)) {
+ numberOfTransactions++;
+ }
+ }
+ return numberOfTransactions;
+ }
}
diff --git a/src/main/java/financialtransactions/TransactionManager.java b/src/main/java/financialtransactions/TransactionManager.java
index 426ffa0f7c..c1fd7833ad 100644
--- a/src/main/java/financialtransactions/TransactionManager.java
+++ b/src/main/java/financialtransactions/TransactionManager.java
@@ -3,6 +3,8 @@
import storage.BarChart;
+import java.time.LocalDateTime;
+
public class TransactionManager {
private TransactionList> transactionList;
private TransactionList inflows;
@@ -173,20 +175,50 @@ public String showLastNTransactions(int n, boolean isIncludeBarChart) throws Exc
}
public String toSave() {
- return String.format("%.2f\n", budget) + inflows.toSave() + outflows.toSave() + reminders.toSave();
+ return String.format("%.2f\n", budget) + transactionList.toSave();
}
+ //@@author chenhowy
public String generateQuickReport() {
String baseString = "";
baseString += String.format("You have spent " +
"%.2f in the current month.\n", outflows.totalSpentInPastMonth());
baseString += String.format("With a budget of " +
- "%.2f, you have %.2f left to spend.\n", budget, budget - outflows.totalSpentInPastMonth());
+ "%.2f, you have %.2f left to spend.\n", budget, budget - outflows.totalSpentInPastMonth() -
+ reminders.totalSpentInPastMonth());
baseString += String.format("You have " +
- "%d upcoming payments that require your attention", reminders.getTransactionListSize());
+ "%d upcoming payments that require your attention", reminders.getTransactionsAfterToday());
return baseString;
}
-
+
+ public String generateFullReport(String monthString, int month, int year) {
+ if (!isBefore(month, year)) {
+ return "Please enter a month that is before the current month";
+ }
+ String baseString = "";
+ baseString += String.format("In the month of %s %s, " +
+ "you had an income of $%.2f.\n", monthString, year, inflows.getTotalSpentInMonth(month, year));
+ baseString += String.format("You spent $%.2f.\n", outflows.getTotalSpentInMonth(month, year) +
+ reminders.getTotalSpentInMonth(month, year));
+ baseString += String.format("You managed to save $%.2f!",
+ inflows.getTotalSpentInMonth(month, year) - outflows.getTotalSpentInMonth(month, year) -
+ reminders.getTotalSpentInMonth(month, year));
+ return baseString;
+ }
+
+ public boolean isBefore(int month, int year) {
+ LocalDateTime today = LocalDateTime.now();
+ int todayMonth = today.getMonthValue();
+ int todayYear = today.getYear();
+ if (year < todayYear) {
+ return true;
+ } else if (year == todayYear && month < todayMonth) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+ //@@author
public int getTransactionListSize() {
return transactionList.getTransactionListSize();
}
diff --git a/src/main/java/parser/Parser.java b/src/main/java/parser/Parser.java
index 9224900185..c3a6f27fbe 100644
--- a/src/main/java/parser/Parser.java
+++ b/src/main/java/parser/Parser.java
@@ -15,6 +15,7 @@
import command.ViewHistoryCommand;
import command.BaseCommand;
import command.HelpCommand;
+import command.GenerateReportCommand;
import customexceptions.IncompletePromptException;
import financialtransactions.Inflow;
import financialtransactions.Outflow;
@@ -118,6 +119,11 @@ public BaseCommand parseCommand(String command) throws Exception {
throw new IncompletePromptException(command);
}
return new ViewHistoryCommand(commandParts);
+ case "generate-report":
+ if (commandParts.length < 3) {
+ throw new IncompletePromptException(command);
+ }
+ return new GenerateReportCommand(commandParts);
case "undo":
UndoCommand undoCommand = new UndoCommand(lastCommandParts);
if (lastCommandParts[0].contains("inflow")) {
diff --git a/src/main/java/storage/Storage.java b/src/main/java/storage/Storage.java
index 7ec9ceea07..f71e4b1d22 100644
--- a/src/main/java/storage/Storage.java
+++ b/src/main/java/storage/Storage.java
@@ -1,3 +1,4 @@
+//@@author chenhowy
package storage;
import financialtransactions.Inflow;
From 61d93017f986daf2539ff596cae7ac27307026f5 Mon Sep 17 00:00:00 2001
From: ChongXern
Date: Thu, 4 Apr 2024 10:48:23 +0800
Subject: [PATCH 118/208] Implement category not found exception
---
src/main/java/command/AddInflowCommand.java | 9 ++++++--
src/main/java/command/AddOutflowCommand.java | 9 ++++++--
src/main/java/command/AddReminderCommand.java | 9 ++++++--
src/main/java/command/UndoCommand.java | 6 -----
.../CategoryNotFoundException.java | 8 ++++++-
src/main/java/financeproject/Main.java | 4 ++--
src/main/java/financeproject/data/Bob.txt | 4 ++++
.../java/financialtransactions/Inflow.java | 15 +++++++++++-
.../java/financialtransactions/Outflow.java | 13 ++++++++++-
.../java/financialtransactions/Reminder.java | 14 ++++++++++-
.../financialtransactions/Transaction.java | 5 +++-
.../TransactionManager.java | 3 ---
src/main/java/storage/Storage.java | 3 +++
.../financialtransactions/InflowTest.java | 7 +++++-
.../financialtransactions/OutflowTest.java | 7 +++++-
.../TransactionManagerTest.java | 23 +++++++++++++++----
16 files changed, 110 insertions(+), 29 deletions(-)
create mode 100644 src/main/java/financeproject/data/Bob.txt
diff --git a/src/main/java/command/AddInflowCommand.java b/src/main/java/command/AddInflowCommand.java
index 322cf47fb7..a6a8f977a8 100644
--- a/src/main/java/command/AddInflowCommand.java
+++ b/src/main/java/command/AddInflowCommand.java
@@ -1,5 +1,6 @@
package command;
+import customexceptions.CategoryNotFoundException;
import financialtransactions.Inflow;
import financialtransactions.TransactionManager;
@@ -7,10 +8,14 @@ public class AddInflowCommand extends BaseCommand {
public AddInflowCommand(String[] commandParts) {
super(false, commandParts);
- createInflow();
+ try {
+ createInflow();
+ } catch (CategoryNotFoundException e) {
+ System.out.println(e.getMessage());
+ }
}
- private void createInflow() {
+ private void createInflow() throws CategoryNotFoundException {
String inflowName = null;
double inflowAmount = 0;
String inflowDate = null;
diff --git a/src/main/java/command/AddOutflowCommand.java b/src/main/java/command/AddOutflowCommand.java
index 2cc71a588d..d8c639bc5d 100644
--- a/src/main/java/command/AddOutflowCommand.java
+++ b/src/main/java/command/AddOutflowCommand.java
@@ -1,5 +1,6 @@
package command;
+import customexceptions.CategoryNotFoundException;
import financialtransactions.Outflow;
import financialtransactions.TransactionManager;
@@ -7,10 +8,14 @@ public class AddOutflowCommand extends BaseCommand {
public AddOutflowCommand(String[] commandParts) {
super(false, commandParts);
- createOutflow();
+ try {
+ createOutflow();
+ } catch (CategoryNotFoundException e) {
+ System.out.println(e.getMessage());
+ }
}
- private void createOutflow() {
+ private void createOutflow() throws CategoryNotFoundException {
String outflowName = null;
double outflowAmount = 0.0;
String outflowDate = null;
diff --git a/src/main/java/command/AddReminderCommand.java b/src/main/java/command/AddReminderCommand.java
index 8879c5934c..7daa2d596b 100644
--- a/src/main/java/command/AddReminderCommand.java
+++ b/src/main/java/command/AddReminderCommand.java
@@ -1,15 +1,20 @@
package command;
+import customexceptions.CategoryNotFoundException;
import financialtransactions.Reminder;
import financialtransactions.TransactionManager;
public class AddReminderCommand extends BaseCommand {
public AddReminderCommand(String[] commandParts) {
super(false, commandParts);
- createReminder();
+ try {
+ createReminder();
+ } catch (CategoryNotFoundException e) {
+ System.out.println(e.getMessage());
+ }
}
- private void createReminder() {
+ private void createReminder() throws CategoryNotFoundException {
String reminderName = null;
double reminderAmount = 0.0;
String reminderDate = null;
diff --git a/src/main/java/command/UndoCommand.java b/src/main/java/command/UndoCommand.java
index 13a2904cd5..7b54f9a48e 100644
--- a/src/main/java/command/UndoCommand.java
+++ b/src/main/java/command/UndoCommand.java
@@ -63,22 +63,16 @@ public String execute(TransactionManager manager) throws Exception {
manager.addTransaction(reminderToRemove);
break;
case "add-inflow":
- //commandToUndo = new DeleteInflowCommand(commandParts);
canUndo = true;
manager.removeTransaction(inflow);
- //manager.addTransaction(commandBeforeUndo.inflow);
break;
case "add-outflow":
- //commandToUndo = new DeleteOutflowCommand(commandParts);
canUndo = true;
manager.removeTransaction(outflow);
- //manager.addTransaction(commandBeforeUndo.outflow);
break;
case "add-reminder":
- //commandToUndo = new DeleteReminderCommand(commandParts);
canUndo = true;
manager.removeTransaction(reminder);
- //manager.addTransaction(commandBeforeUndo.reminder);
break;
default:
return "Sorry, unable to undo action.";
diff --git a/src/main/java/customexceptions/CategoryNotFoundException.java b/src/main/java/customexceptions/CategoryNotFoundException.java
index f7ada40ea5..5278a57226 100644
--- a/src/main/java/customexceptions/CategoryNotFoundException.java
+++ b/src/main/java/customexceptions/CategoryNotFoundException.java
@@ -1,4 +1,10 @@
package customexceptions;
-public class CategoryNotFoundException {
+import java.util.Arrays;
+import java.util.EnumSet;
+
+public class CategoryNotFoundException extends Exception {
+ public CategoryNotFoundException(Enum>[] categories) {
+ super("Category not found. Available categories are: " + Arrays.toString(categories));
+ }
}
diff --git a/src/main/java/financeproject/Main.java b/src/main/java/financeproject/Main.java
index 1534086c36..f1e576c627 100644
--- a/src/main/java/financeproject/Main.java
+++ b/src/main/java/financeproject/Main.java
@@ -15,8 +15,8 @@
public class Main {
public static void main(String[] args) throws SecurityException {
- // Storage storage = new Storage("./data"); // Storage manager for jar file
- Storage storage = new Storage("../../../data");
+ Storage storage = new Storage("./data"); // Storage manager for jar file
+ //Storage storage = new Storage("../../../data");
UI ui = new UI();
ui.printMessage("Welcome. Enter your username and password to login.");
diff --git a/src/main/java/financeproject/data/Bob.txt b/src/main/java/financeproject/data/Bob.txt
new file mode 100644
index 0000000000..2dd38f8d2f
--- /dev/null
+++ b/src/main/java/financeproject/data/Bob.txt
@@ -0,0 +1,4 @@
+0.00
+Stocks|400.00|Oct 24 2024 12:00PM|INVESTMENT|I
+Refund|100.00|Jun 23 2023 05:00PM|REFUND|I
+Groceries|-150.00|Jun 23 2023 06:30PM|SHOPPING|O
diff --git a/src/main/java/financialtransactions/Inflow.java b/src/main/java/financialtransactions/Inflow.java
index cdf0c52794..ec1e953f73 100644
--- a/src/main/java/financialtransactions/Inflow.java
+++ b/src/main/java/financialtransactions/Inflow.java
@@ -1,15 +1,28 @@
package financialtransactions;
+import customexceptions.CategoryNotFoundException;
+
+import java.util.EnumSet;
+
public class Inflow extends Transaction {
public enum Category {
INCOME, INVESTMENT, GIFT, LOAN, REFUND, OTHER
}
+
public Inflow(String name, double amount, String date) {
super(name, amount, date);
}
- public void setCategory(Category category) {
+ public void setCategory(Category category) throws CategoryNotFoundException {
+ if (!isValidCategory(category)) {
+ throw new CategoryNotFoundException(Category.values());
+ }
super.category = category;
}
+
+ public boolean isValidCategory(Category category) {
+ EnumSet categories = EnumSet.allOf(Category.class);
+ return categories.contains(category);
+ }
@Override
public String toSave() {
diff --git a/src/main/java/financialtransactions/Outflow.java b/src/main/java/financialtransactions/Outflow.java
index 173ab400c7..a21b6c9769 100644
--- a/src/main/java/financialtransactions/Outflow.java
+++ b/src/main/java/financialtransactions/Outflow.java
@@ -1,5 +1,9 @@
package financialtransactions;
+import customexceptions.CategoryNotFoundException;
+
+import java.util.EnumSet;
+
public class Outflow extends Transaction {
public enum Category {
FOOD, RENT, DEBT, SHOPPING, TREAT, EDUCATION, TAX, OTHER
@@ -9,9 +13,16 @@ public Outflow(String name, double amount, String date) {
super(name, -1.00 * amount, date);
}
- public void setCategory(Category category) {
+ public void setCategory(Category category) throws CategoryNotFoundException {
+ if (!isValidCategory(category)) {
+ throw new CategoryNotFoundException(Category.values());
+ }
this.category = category;
}
+ public boolean isValidCategory(Category category) {
+ EnumSet categories = EnumSet.allOf(Category.class);
+ return categories.contains(category);
+ }
@Override
public String toSave() {
diff --git a/src/main/java/financialtransactions/Reminder.java b/src/main/java/financialtransactions/Reminder.java
index b74c17e841..c281cb7a1c 100644
--- a/src/main/java/financialtransactions/Reminder.java
+++ b/src/main/java/financialtransactions/Reminder.java
@@ -1,5 +1,9 @@
package financialtransactions;
+import customexceptions.CategoryNotFoundException;
+
+import java.util.EnumSet;
+
public class Reminder extends Transaction {
public enum Category {
INSTALLMENT, CREDITCARD, UTILITIES
@@ -9,10 +13,18 @@ public Reminder(String name, double amount, String date) {
super(name, -1.00 * amount, date);
}
- public void setCategory(Category category) {
+ public void setCategory(Category category) throws CategoryNotFoundException {
+ if (!isValidCategory(category)) {
+ throw new CategoryNotFoundException(Category.values());
+ }
this.category = category;
}
+ public boolean isValidCategory(Category category) {
+ EnumSet categories = EnumSet.allOf(Category.class);
+ return categories.contains(category);
+ }
+
@Override
public String toSave() {
return super.toSave() + "|R\n";
diff --git a/src/main/java/financialtransactions/Transaction.java b/src/main/java/financialtransactions/Transaction.java
index 329ba66e03..13e94a6b62 100644
--- a/src/main/java/financialtransactions/Transaction.java
+++ b/src/main/java/financialtransactions/Transaction.java
@@ -1,9 +1,11 @@
package financialtransactions;
+import customexceptions.CategoryNotFoundException;
import template.BaseDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
+import java.util.EnumSet;
public abstract class Transaction {
@@ -41,7 +43,8 @@ public T getCategory() {
return category;
}
- protected abstract void setCategory(T category);
+ protected abstract void setCategory(T category) throws CategoryNotFoundException;
+ protected abstract boolean isValidCategory(T category);
@Override
public String toString() {
diff --git a/src/main/java/financialtransactions/TransactionManager.java b/src/main/java/financialtransactions/TransactionManager.java
index 426ffa0f7c..8976c67096 100644
--- a/src/main/java/financialtransactions/TransactionManager.java
+++ b/src/main/java/financialtransactions/TransactionManager.java
@@ -206,7 +206,4 @@ public Outflow getNthOutflowFromList(int n) throws Exception {
public Reminder getNthReminderFromList(int n) throws Exception {
return (Reminder) reminders.getNthTransaction(n -1);
}
- public void printTransactionListSafeInfo() {
- transactionList.printTransactionsSafeInfo();
- }
}
diff --git a/src/main/java/storage/Storage.java b/src/main/java/storage/Storage.java
index 7ec9ceea07..b65aa05f49 100644
--- a/src/main/java/storage/Storage.java
+++ b/src/main/java/storage/Storage.java
@@ -1,5 +1,6 @@
package storage;
+import customexceptions.CategoryNotFoundException;
import financialtransactions.Inflow;
import financialtransactions.Outflow;
import financialtransactions.Reminder;
@@ -78,6 +79,8 @@ public TransactionManager loadFile(String username) {
sc.close();
} catch (FileNotFoundException e) {
createFileDir();
+ } catch (CategoryNotFoundException e) {
+ System.out.println(e.getMessage());
}
return manager;
}
diff --git a/src/test/java/financialtransactions/InflowTest.java b/src/test/java/financialtransactions/InflowTest.java
index 6e49730a09..2a62d23322 100644
--- a/src/test/java/financialtransactions/InflowTest.java
+++ b/src/test/java/financialtransactions/InflowTest.java
@@ -1,5 +1,6 @@
package financialtransactions;
+import customexceptions.CategoryNotFoundException;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -8,7 +9,11 @@ public class InflowTest {
@Test
public void testSetCategory() {
Inflow inflow = new Inflow("February salary", 20.00, "2024-03-02");
- inflow.setCategory(Inflow.Category.INCOME);
+ try {
+ inflow.setCategory(Inflow.Category.INCOME);
+ } catch (CategoryNotFoundException e) {
+ System.out.println(e.getMessage());
+ }
assertEquals(Inflow.Category.INCOME, inflow.getCategory());
}
}
diff --git a/src/test/java/financialtransactions/OutflowTest.java b/src/test/java/financialtransactions/OutflowTest.java
index 7a50116c85..3013efb8c3 100644
--- a/src/test/java/financialtransactions/OutflowTest.java
+++ b/src/test/java/financialtransactions/OutflowTest.java
@@ -1,5 +1,6 @@
package financialtransactions;
+import customexceptions.CategoryNotFoundException;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -8,7 +9,11 @@ public class OutflowTest {
@Test
public void testSetCategory() {
Outflow outflow = new Outflow("2024 Sem 2 School Fees", 999999.99, "2024-02-01");
- outflow.setCategory(Outflow.Category.EDUCATION);
+ try {
+ outflow.setCategory(Outflow.Category.EDUCATION);
+ } catch (CategoryNotFoundException e) {
+ System.out.println(e.getMessage());
+ }
assertEquals(Outflow.Category.EDUCATION, outflow.getCategory());
assertEquals(-999999.99, outflow.getAmount());
diff --git a/src/test/java/financialtransactions/TransactionManagerTest.java b/src/test/java/financialtransactions/TransactionManagerTest.java
index 536d6f3630..6d01e7405e 100644
--- a/src/test/java/financialtransactions/TransactionManagerTest.java
+++ b/src/test/java/financialtransactions/TransactionManagerTest.java
@@ -1,5 +1,6 @@
package financialtransactions;
+import customexceptions.CategoryNotFoundException;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -10,17 +11,29 @@ public void toSaveTest() {
TransactionManager managerTest = new TransactionManager();
Inflow income = new Inflow("Salary payment", 400.00, "23/05/2022 1900");
- income.setCategory(Inflow.Category.INCOME);
+ try {
+ income.setCategory(Inflow.Category.INCOME);
+ } catch (CategoryNotFoundException e) {
+ System.out.println(e.getMessage());
+ }
managerTest.addTransaction(income);
Outflow shopping = new Outflow("Shopping", 200, "23/05/2022 2000");
- shopping.setCategory(Outflow.Category.SHOPPING);
+ try {
+ shopping.setCategory(Outflow.Category.SHOPPING);
+ } catch (CategoryNotFoundException e) {
+ System.out.println(e.getMessage());
+ }
managerTest.addTransaction(shopping);
-
+
Reminder bill = new Reminder("Water bills", 64.30, "25/06/2025 1500");
- bill.setCategory(Reminder.Category.UTILITIES);
+ try {
+ bill.setCategory(Reminder.Category.UTILITIES);
+ } catch (CategoryNotFoundException e) {
+ System.out.println(e.getMessage());
+ }
managerTest.addTransaction(bill);
-
+
managerTest.setBudget(1500);
assertEquals("1500.00\n" +
From b62e961d35c706d01a19289bffdadca7c1f0f788 Mon Sep 17 00:00:00 2001
From: ChongXern
Date: Thu, 4 Apr 2024 10:51:16 +0800
Subject: [PATCH 119/208] Resolve merge conflict
---
src/main/java/financeproject/Main.java | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/src/main/java/financeproject/Main.java b/src/main/java/financeproject/Main.java
index f1e576c627..0b39251165 100644
--- a/src/main/java/financeproject/Main.java
+++ b/src/main/java/financeproject/Main.java
@@ -15,8 +15,7 @@
public class Main {
public static void main(String[] args) throws SecurityException {
- Storage storage = new Storage("./data"); // Storage manager for jar file
- //Storage storage = new Storage("../../../data");
+ Storage storage = new Storage("./data"); // Storage manager for jar file
UI ui = new UI();
ui.printMessage("Welcome. Enter your username and password to login.");
From 0dcf748be3dcbdf6e3f1942b235a197d92c7f044 Mon Sep 17 00:00:00 2001
From: ChongXern
Date: Thu, 4 Apr 2024 10:53:40 +0800
Subject: [PATCH 120/208] Fix checkstyle errors for exception
---
src/main/java/customexceptions/CategoryNotFoundException.java | 1 -
src/main/java/financialtransactions/Transaction.java | 2 --
2 files changed, 3 deletions(-)
diff --git a/src/main/java/customexceptions/CategoryNotFoundException.java b/src/main/java/customexceptions/CategoryNotFoundException.java
index 5278a57226..39f4df5072 100644
--- a/src/main/java/customexceptions/CategoryNotFoundException.java
+++ b/src/main/java/customexceptions/CategoryNotFoundException.java
@@ -1,7 +1,6 @@
package customexceptions;
import java.util.Arrays;
-import java.util.EnumSet;
public class CategoryNotFoundException extends Exception {
public CategoryNotFoundException(Enum>[] categories) {
diff --git a/src/main/java/financialtransactions/Transaction.java b/src/main/java/financialtransactions/Transaction.java
index 13e94a6b62..cd81958e80 100644
--- a/src/main/java/financialtransactions/Transaction.java
+++ b/src/main/java/financialtransactions/Transaction.java
@@ -5,8 +5,6 @@
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
-import java.util.EnumSet;
-
public abstract class Transaction {
private static final int NAME_MAX_LEN = 30;
From d346be32138a396645c809a16a57c00c9b7a9937 Mon Sep 17 00:00:00 2001
From: ChongXern
Date: Thu, 4 Apr 2024 11:02:14 +0800
Subject: [PATCH 121/208] Add throw category not found exception to outflow
method
---
src/main/java/financialtransactions/Inflow.java | 1 +
src/main/java/parser/Parser.java | 3 ---
src/test/java/financialtransactions/OutflowTest.java | 9 ++-------
3 files changed, 3 insertions(+), 10 deletions(-)
diff --git a/src/main/java/financialtransactions/Inflow.java b/src/main/java/financialtransactions/Inflow.java
index ec1e953f73..687836302b 100644
--- a/src/main/java/financialtransactions/Inflow.java
+++ b/src/main/java/financialtransactions/Inflow.java
@@ -12,6 +12,7 @@ public enum Category {
public Inflow(String name, double amount, String date) {
super(name, amount, date);
}
+
public void setCategory(Category category) throws CategoryNotFoundException {
if (!isValidCategory(category)) {
throw new CategoryNotFoundException(Category.values());
diff --git a/src/main/java/parser/Parser.java b/src/main/java/parser/Parser.java
index 9224900185..a2e813d1f0 100644
--- a/src/main/java/parser/Parser.java
+++ b/src/main/java/parser/Parser.java
@@ -73,9 +73,6 @@ public BaseCommand parseCommand(String command) throws Exception {
lastCommandParts = commandParts;
lastCommand = new DeleteInflowCommand(commandParts);
lastInflow = lastCommand.getInflow();
- if (lastInflow == null) {
- System.out.println("Last inflow is null");
- }
return lastCommand;
case "delete-outflow":
if (commandParts.length < 2) {
diff --git a/src/test/java/financialtransactions/OutflowTest.java b/src/test/java/financialtransactions/OutflowTest.java
index 3013efb8c3..01a3bf6590 100644
--- a/src/test/java/financialtransactions/OutflowTest.java
+++ b/src/test/java/financialtransactions/OutflowTest.java
@@ -7,15 +7,10 @@
public class OutflowTest {
@Test
- public void testSetCategory() {
+ public void testSetCategory() throws CategoryNotFoundException {
Outflow outflow = new Outflow("2024 Sem 2 School Fees", 999999.99, "2024-02-01");
- try {
- outflow.setCategory(Outflow.Category.EDUCATION);
- } catch (CategoryNotFoundException e) {
- System.out.println(e.getMessage());
- }
+ outflow.setCategory(Outflow.Category.EDUCATION);
assertEquals(Outflow.Category.EDUCATION, outflow.getCategory());
assertEquals(-999999.99, outflow.getAmount());
-
}
}
From 1e793232f7389e1f8bccaf1dafda4df3bb6c90a0 Mon Sep 17 00:00:00 2001
From: ChongXern
Date: Thu, 4 Apr 2024 11:12:14 +0800
Subject: [PATCH 122/208] Create Junit for new outflow method for is valid
category
---
src/test/java/financialtransactions/OutflowTest.java | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/src/test/java/financialtransactions/OutflowTest.java b/src/test/java/financialtransactions/OutflowTest.java
index 01a3bf6590..bb708dbe9d 100644
--- a/src/test/java/financialtransactions/OutflowTest.java
+++ b/src/test/java/financialtransactions/OutflowTest.java
@@ -1,16 +1,12 @@
package financialtransactions;
-import customexceptions.CategoryNotFoundException;
import org.junit.jupiter.api.Test;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class OutflowTest {
@Test
- public void testSetCategory() throws CategoryNotFoundException {
- Outflow outflow = new Outflow("2024 Sem 2 School Fees", 999999.99, "2024-02-01");
- outflow.setCategory(Outflow.Category.EDUCATION);
- assertEquals(Outflow.Category.EDUCATION, outflow.getCategory());
- assertEquals(-999999.99, outflow.getAmount());
+ public void testIsValidCategory(){
+ Outflow outflow = new Outflow("2024 Sem 2 School Fees", 999999.99, "2024-04-01");
+ assertTrue(outflow.isValidCategory(Outflow.Category.EDUCATION));
}
}
From 8de07f77ac0271888b872653a93a36d4910c7ae9 Mon Sep 17 00:00:00 2001
From: ChongXern
Date: Thu, 4 Apr 2024 11:16:04 +0800
Subject: [PATCH 123/208] Modify seedu Junit outflow test
---
src/test/java/seedu/OutflowTest.java | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/src/test/java/seedu/OutflowTest.java b/src/test/java/seedu/OutflowTest.java
index 641cd78d5c..aaa29729ef 100644
--- a/src/test/java/seedu/OutflowTest.java
+++ b/src/test/java/seedu/OutflowTest.java
@@ -1,5 +1,6 @@
package seedu;
+import customexceptions.CategoryNotFoundException;
import financialtransactions.Outflow;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -8,7 +9,11 @@ public class OutflowTest {
@Test
public void testSetCategory() {
Outflow outflow = new Outflow("2024 Sem 2 School Fees", 999999.99, "2024-02-01");
- outflow.setCategory(Outflow.Category.EDUCATION);
+ try {
+ outflow.setCategory(Outflow.Category.EDUCATION);
+ } catch (CategoryNotFoundException e) {
+ System.out.println(e.getMessage());
+ }
assertEquals(Outflow.Category.EDUCATION, outflow.getCategory());
}
}
From dde789f1bc90f46d712d4a6efc24a61abea9e064 Mon Sep 17 00:00:00 2001
From: ChongXern
Date: Thu, 4 Apr 2024 11:28:57 +0800
Subject: [PATCH 124/208] Enable optional bar chart for view-history
---
src/main/java/command/ViewHistoryCommand.java | 5 ++++-
src/main/java/financeproject/data/Bob.txt | 2 ++
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/src/main/java/command/ViewHistoryCommand.java b/src/main/java/command/ViewHistoryCommand.java
index 6acb52c4dc..880e341907 100644
--- a/src/main/java/command/ViewHistoryCommand.java
+++ b/src/main/java/command/ViewHistoryCommand.java
@@ -17,7 +17,10 @@ public String execute(TransactionManager manager) throws Exception{
numTransactions = Integer.parseInt(numTransactionsString);
} else if (commandParts[1].equals("all")) {
numTransactions = manager.getTransactionListSize();
+ } else {
+ return "Sorry, please use the correct syntax for view-history.";
}
- return manager.showLastNTransactions(numTransactions, false);
+ boolean isIncludeBarChart = commandParts.length == 3 && commandParts[2].equals("w/chart");
+ return manager.showLastNTransactions(numTransactions, isIncludeBarChart);
}
}
diff --git a/src/main/java/financeproject/data/Bob.txt b/src/main/java/financeproject/data/Bob.txt
index 2dd38f8d2f..1cc11e2cd4 100644
--- a/src/main/java/financeproject/data/Bob.txt
+++ b/src/main/java/financeproject/data/Bob.txt
@@ -1,4 +1,6 @@
0.00
Stocks|400.00|Oct 24 2024 12:00PM|INVESTMENT|I
Refund|100.00|Jun 23 2023 05:00PM|REFUND|I
+Salary|400.00|May 23 2022 07:00PM|INCOME|I
Groceries|-150.00|Jun 23 2023 06:30PM|SHOPPING|O
+Rent|-1500.00|Jun 23 2023 06:00PM|RENT|O
From b5214b426d59b93360791769f04bef2de836c037 Mon Sep 17 00:00:00 2001
From: dylansiew <88567790+dylansiew@users.noreply.github.com>
Date: Thu, 4 Apr 2024 15:31:21 +0800
Subject: [PATCH 125/208] closing scanner
---
data/Bob.txt | 1 +
src/main/java/storage/Storage.java | 30 ++++++++++++++----------------
2 files changed, 15 insertions(+), 16 deletions(-)
diff --git a/data/Bob.txt b/data/Bob.txt
index e69de29bb2..fb1088c65a 100644
--- a/data/Bob.txt
+++ b/data/Bob.txt
@@ -0,0 +1 @@
+0.00
diff --git a/src/main/java/storage/Storage.java b/src/main/java/storage/Storage.java
index d9cc883ad7..d55c11b3ab 100644
--- a/src/main/java/storage/Storage.java
+++ b/src/main/java/storage/Storage.java
@@ -21,17 +21,7 @@ public Storage(String filePath) {
this.filePath = filePath;
}
- public void addNewUser(String username, String password) {
- try {
- FileWriter fw = new FileWriter(filePath + "/passwords.txt", true);
- fw.write(username + "|" + password + "\n");
- fw.close();
- } catch (IOException e) {
- System.out.println("Could not add user");
- }
- }
-
- public BaseUser loadUser(String username) throws UserNotFoundExcption{
+ public BaseUser loadUser(String username) throws Exception{
File f = new File(filePath + "/passwords.txt");
try {
this.sc = new Scanner(f);
@@ -40,12 +30,17 @@ public BaseUser loadUser(String username) throws UserNotFoundExcption{
if (line.startsWith(username)) {
String password = line.split("\\|")[1];
BaseUser newUser = new BaseUser(username, password);
+ this.sc.close();
return newUser;
}
}
+ this.sc.close();
throw new UserNotFoundExcption();
} catch (FileNotFoundException e) {
- createFileDir();
+ if (!createFileDir()){
+ throw new Exception("Failed to create directory");
+ }
+ this.sc.close();
return null;
}
}
@@ -54,9 +49,9 @@ public TransactionManager loadFile(String username) {
File f = new File(filePath + String.format("/%s.txt", username));
TransactionManager manager = new TransactionManager();
try {
- Scanner sc = new Scanner(f);
+ this.sc = new Scanner(f);
manager.setBudget(Double.parseDouble(sc.nextLine()));
- while (sc.hasNext()) {
+ while (this.sc.hasNext()) {
String[] transactionInfo = sc.nextLine().split("\\|");
assert transactionInfo.length == 5 : "Transaction info should have 5 arguments";
double amount = Double.parseDouble(transactionInfo[1]);
@@ -77,13 +72,16 @@ public TransactionManager loadFile(String username) {
sc.close();
} catch (FileNotFoundException e) {
createFileDir();
+ sc.close();
+ } catch (Exception e){
+ System.out.println(e.getMessage());
}
return manager;
}
- private void createFileDir() {
+ private boolean createFileDir() {
File f = new File(filePath);
- f.mkdir();
+ return f.mkdir();
}
public void saveFile(String username, TransactionManager tm) {
From 1531954707f8314fd30063204c4821bba91be0e2 Mon Sep 17 00:00:00 2001
From: dylansiew <88567790+dylansiew@users.noreply.github.com>
Date: Thu, 4 Apr 2024 15:32:51 +0800
Subject: [PATCH 126/208] closing scanner
---
src/main/java/financeproject/Main.java | 19 +++++--------------
1 file changed, 5 insertions(+), 14 deletions(-)
diff --git a/src/main/java/financeproject/Main.java b/src/main/java/financeproject/Main.java
index 04eac2f472..8b164785fa 100644
--- a/src/main/java/financeproject/Main.java
+++ b/src/main/java/financeproject/Main.java
@@ -1,10 +1,8 @@
package financeproject;
import command.BaseCommand;
-import customexceptions.ExceededAttemptsException;
import customexceptions.InactivityTimeoutException;
import customexceptions.IncompletePromptException;
-import customexceptions.UserNotFoundExcption;
import financialtransactions.TransactionManager;
import parser.Parser;
import storage.Storage;
@@ -14,7 +12,7 @@
import userinterface.UI;
public class Main {
- public static void main(String[] args) throws SecurityException, ExceededAttemptsException {
+ public static void main(String[] args) throws SecurityException {
Storage storage = new Storage("./data");
UI ui = new UI();
@@ -22,28 +20,21 @@ public static void main(String[] args) throws SecurityException, ExceededAttempt
Parser parser = new Parser(ui);
BaseCommand baseCommand = null;
- String response = "";
+ String response;
// Authenticating user
- BaseUser user = null;
+ BaseUser user;
InactivityTimer inactivityTimer = new InactivityTimer();
try {
ui.printMessage("Username: ");
response = ui.readInput();
user = storage.loadUser(response);
Authentication.authenticateUser(user, ui);
- } catch (UserNotFoundExcption e) {
+ } catch (Exception e){
ui.printMessage(e.getMessage());
return;
- } catch (ExceededAttemptsException e) {
- ui.printMessage(e.getMessage());
- return;
- }
- if (user != null) {
- ui.printMessage("User has been authenticated. Starting program...");
- } else {
- return;
}
+ ui.printMessage("User has been authenticated. Starting program...");
TransactionManager manager = storage.loadFile(user.getUsername());
ui.printMessage(manager.generateQuickReport());
From 48623d6008820704eaa71c70737db9fd4eda9cb6 Mon Sep 17 00:00:00 2001
From: Kishen271828
Date: Thu, 4 Apr 2024 16:23:18 +0800
Subject: [PATCH 127/208] Main working
---
data/Bob.txt | 4 ++++
src/main/java/financeproject/Main.java | 7 ++++---
src/main/java/financeproject/data/data.txt | 5 -----
src/main/java/financialtransactions/TransactionList.java | 1 +
4 files changed, 9 insertions(+), 8 deletions(-)
delete mode 100644 src/main/java/financeproject/data/data.txt
diff --git a/data/Bob.txt b/data/Bob.txt
index e69de29bb2..b1081d210c 100644
--- a/data/Bob.txt
+++ b/data/Bob.txt
@@ -0,0 +1,4 @@
+0.00
+Stocks|400.00|Oct 24 2024 12:00PM|INVESTMENT|I
+Groceries|-150.00|Jun 23 2023 06:30PM|SHOPPING|O
+Refund|100.00|Jun 23 2023 05:00PM|REFUND|I
diff --git a/src/main/java/financeproject/Main.java b/src/main/java/financeproject/Main.java
index 0b39251165..1e50d697a2 100644
--- a/src/main/java/financeproject/Main.java
+++ b/src/main/java/financeproject/Main.java
@@ -16,7 +16,7 @@
public class Main {
public static void main(String[] args) throws SecurityException {
Storage storage = new Storage("./data"); // Storage manager for jar file
-
+
UI ui = new UI();
ui.printMessage("Welcome. Enter your username and password to login.");
@@ -25,7 +25,7 @@ public static void main(String[] args) throws SecurityException {
String response = "";
// Authenticating user
- BaseUser user = null;
+ BaseUser user;
InactivityTimer inactivityTimer = new InactivityTimer();
try {
ui.printMessage("Username: ");
@@ -42,6 +42,7 @@ public static void main(String[] args) throws SecurityException {
return;
}
TransactionManager manager = storage.loadFile(user.getUsername());
+ //TransactionManager manager = new TransactionManager();
ui.printMessage(manager.generateQuickReport());
// Main program flow
@@ -84,4 +85,4 @@ public static void main(String[] args) throws SecurityException {
} while (baseCommand == null || !baseCommand.isExit());
ui.closeScanner();
}
-}
+}
\ No newline at end of file
diff --git a/src/main/java/financeproject/data/data.txt b/src/main/java/financeproject/data/data.txt
deleted file mode 100644
index 7460e56187..0000000000
--- a/src/main/java/financeproject/data/data.txt
+++ /dev/null
@@ -1,5 +0,0 @@
-Salary|400.00|May 23 2022 07:00PM|INCOME
-Salara|400.00|May 23 2022 07:00PM|INCOME
-Salarz|400.00|May 23 2022 07:00PM|INCOME
-Rent|-1500.00|Jun 23 2023 06:00PM|RENT
-Rent|-1500.00|Jun 23 2023 06:00PM|RENT
diff --git a/src/main/java/financialtransactions/TransactionList.java b/src/main/java/financialtransactions/TransactionList.java
index d9300b1b43..8003e4ca35 100644
--- a/src/main/java/financialtransactions/TransactionList.java
+++ b/src/main/java/financialtransactions/TransactionList.java
@@ -126,6 +126,7 @@ public void sortList() {
public void sortListByDate() {
this.transactionList.sort(new DateComparator<>());
}
+
//@@author chenhowy
public double totalSpentInPastMonth() {
double amount = 0;
From 694dde8d812bebf85ec57419f5a5d6b813e9ca6f Mon Sep 17 00:00:00 2001
From: dylansiew <88567790+dylansiew@users.noreply.github.com>
Date: Thu, 4 Apr 2024 16:27:46 +0800
Subject: [PATCH 128/208] handling errors when loading file and setting mock
user for demo purposes
---
data/Bob.txt | 5 +++++
src/main/java/financeproject/Main.java | 23 ++++++++++-------------
src/main/java/storage/Storage.java | 14 ++++++++++----
src/main/java/user/Authentication.java | 12 ++----------
4 files changed, 27 insertions(+), 27 deletions(-)
diff --git a/data/Bob.txt b/data/Bob.txt
index e69de29bb2..3e7788c289 100644
--- a/data/Bob.txt
+++ b/data/Bob.txt
@@ -0,0 +1,5 @@
+0.00
+Salary|400.00|May 23 2022 07:00PM|INCOME|I
+Rent|-1500.00|Jun 23 2023 06:00PM|RENT|O
+Stocks|400.00|Oct 24 2024 12:00PM|INVESTMENT|I
+Refund|100.00|Jun 23 2023 05:00PM|REFUND|I
diff --git a/src/main/java/financeproject/Main.java b/src/main/java/financeproject/Main.java
index 0b39251165..4783f11a98 100644
--- a/src/main/java/financeproject/Main.java
+++ b/src/main/java/financeproject/Main.java
@@ -4,7 +4,6 @@
import customexceptions.ExceededAttemptsException;
import customexceptions.InactivityTimeoutException;
import customexceptions.IncompletePromptException;
-import customexceptions.UserNotFoundException;
import financialtransactions.TransactionManager;
import parser.Parser;
import storage.Storage;
@@ -22,25 +21,23 @@ public static void main(String[] args) throws SecurityException {
Parser parser = new Parser(ui);
BaseCommand baseCommand = null;
- String response = "";
+ String response;
// Authenticating user
- BaseUser user = null;
+ BaseUser user;
InactivityTimer inactivityTimer = new InactivityTimer();
try {
ui.printMessage("Username: ");
response = ui.readInput();
- user = storage.loadUser(response);
- Authentication.authenticateUser(user, ui);
- } catch (UserNotFoundException | ExceededAttemptsException e) {
+// user = storage.loadUser(response);
+ user = storage.loadMockUser();
+ if (Authentication.authenticateUser(user, ui)){
+ ui.printMessage("User has been authenticated. Starting program...");
+ }
+ } catch (ExceededAttemptsException e) {
ui.printMessage(e.getMessage());
return;
}
- if (user != null) {
- ui.printMessage("User has been authenticated. Starting program...");
- } else {
- return;
- }
TransactionManager manager = storage.loadFile(user.getUsername());
ui.printMessage(manager.generateQuickReport());
@@ -71,11 +68,11 @@ public static void main(String[] args) throws SecurityException {
String wantToContinue = ui.readInput();
if (wantToContinue.equalsIgnoreCase("y") ||
wantToContinue.equalsIgnoreCase("yes")) {
- System.out.println("Session continued.");
+ ui.printMessage("Session continued.");
inactivityTimer.resetTimer();
} else if (wantToContinue.equalsIgnoreCase("n") ||
wantToContinue.equalsIgnoreCase("no")) {
- System.out.println("Session ended. ");
+ ui.printMessage("Session ended. ");
assert baseCommand != null;
baseCommand.setIsExit(true);
}
diff --git a/src/main/java/storage/Storage.java b/src/main/java/storage/Storage.java
index 818e18cffe..4d2cb994b8 100644
--- a/src/main/java/storage/Storage.java
+++ b/src/main/java/storage/Storage.java
@@ -32,7 +32,10 @@ public void addNewUser(String username, String password) {
System.out.println("Could not add user");
}
}
-
+
+ public BaseUser loadMockUser(){
+ return new BaseUser("Bob", "password");
+ }
public BaseUser loadUser(String username) throws UserNotFoundException {
File f = new File(filePath + "/passwords.txt");
try {
@@ -41,8 +44,7 @@ public BaseUser loadUser(String username) throws UserNotFoundException {
String line = sc.nextLine();
if (line.startsWith(username)) {
String password = line.split("\\|")[1];
- BaseUser newUser = new BaseUser(username, password);
- return newUser;
+ return new BaseUser(username, password);
}
}
throw new UserNotFoundException();
@@ -58,7 +60,11 @@ public TransactionManager loadFile(String username) {
TransactionManager manager = new TransactionManager();
try {
Scanner sc = new Scanner(f);
- manager.setBudget(Double.parseDouble(sc.nextLine()));
+ double budget = 0.00;
+ if(sc.hasNext()){
+ budget = Double.parseDouble(sc.nextLine());
+ }
+ manager.setBudget(budget);
while (sc.hasNext()) {
String[] transactionInfo = sc.nextLine().split("\\|");
assert transactionInfo.length == 5 : "Transaction info should have 5 arguments";
diff --git a/src/main/java/user/Authentication.java b/src/main/java/user/Authentication.java
index 8322a9cc2d..bf9c64d31a 100644
--- a/src/main/java/user/Authentication.java
+++ b/src/main/java/user/Authentication.java
@@ -4,9 +4,8 @@
import userinterface.UI;
public class Authentication {
- private static int attemptsLimit = 3;
+ private static final int attemptsLimit = 3;
String username;
- UI ui;
private String password;
public Authentication(String username, String password) {
@@ -14,15 +13,8 @@ public Authentication(String username, String password) {
this.username = username;
}
- public String getUsername() {
- return this.username;
- }
-
public boolean checkPassword(String username, String password) {
- System.out.println(password + " and " + this.password);
- System.out.println(username + " and " + this.username);
- boolean isMatch = this.password.equals(password) && this.username.equals(username);
- return isMatch;
+ return this.password.equals(password) && this.username.equals(username);
}
public boolean changePassword(String username, String oldPassword, String newPassword)
From f604d4bf3a731a4bba1bf57ff06b8c4e1facac4f Mon Sep 17 00:00:00 2001
From: Kishen271828
Date: Thu, 4 Apr 2024 18:13:37 +0800
Subject: [PATCH 129/208] Implement sorting of transactions by time
---
.../financialtransactions/Transaction.java | 5 ++++
.../TransactionComparator.java | 11 ++++++++
.../TransactionList.java | 9 +++++++
.../TransactionManager.java | 26 ++++++++++++++-----
src/main/java/template/BaseDate.java | 5 ++++
5 files changed, 50 insertions(+), 6 deletions(-)
create mode 100644 src/main/java/financialtransactions/TransactionComparator.java
diff --git a/src/main/java/financialtransactions/Transaction.java b/src/main/java/financialtransactions/Transaction.java
index cd81958e80..e31a93e2e4 100644
--- a/src/main/java/financialtransactions/Transaction.java
+++ b/src/main/java/financialtransactions/Transaction.java
@@ -56,4 +56,9 @@ public String toSave() {
public BaseDate getDate() {
return date;
}
+
+ public int compareTo(Transaction> otherTransaction) {
+ return this.date.compareTo(otherTransaction.getDate());
+ }
+
}
diff --git a/src/main/java/financialtransactions/TransactionComparator.java b/src/main/java/financialtransactions/TransactionComparator.java
new file mode 100644
index 0000000000..1ec3e8eb79
--- /dev/null
+++ b/src/main/java/financialtransactions/TransactionComparator.java
@@ -0,0 +1,11 @@
+package financialtransactions;
+
+import java.util.Comparator;
+
+public class TransactionComparator implements Comparator> {
+ @Override
+ public int compare(Transaction> t1, Transaction> t2) {
+ // Compare the dates of the transactions
+ return t1.getDate().compareTo(t2.getDate());
+ }
+}
diff --git a/src/main/java/financialtransactions/TransactionList.java b/src/main/java/financialtransactions/TransactionList.java
index 8003e4ca35..2ac092d4b7 100644
--- a/src/main/java/financialtransactions/TransactionList.java
+++ b/src/main/java/financialtransactions/TransactionList.java
@@ -2,7 +2,9 @@
import java.time.LocalDateTime;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.Comparator;
+import java.util.List;
public class TransactionList> {
private ArrayList transactionList;
@@ -73,6 +75,7 @@ public String toSave() {
return baseString.toString();
}
//@@author
+
protected void printTransactionsSafeInfo() {
int index = 1;
for (T transaction : transactionList) {
@@ -97,6 +100,11 @@ public void setTransactionsType(String transactionsType) {
}
}
+ public void sortTransactions() {
+ transactionList.sort(new TransactionComparator());
+ }
+
+
public class NameComparator> implements Comparator {
@Override
public int compare(T o1, T o2) {
@@ -149,6 +157,7 @@ public double getTotalSpentInMonth(int month, int year) {
}
return amount;
}
+
public int getTransactionsAfterToday() {
int numberOfTransactions = 0;
LocalDateTime today = LocalDateTime.now();
diff --git a/src/main/java/financialtransactions/TransactionManager.java b/src/main/java/financialtransactions/TransactionManager.java
index 05bf6fef85..b369befb12 100644
--- a/src/main/java/financialtransactions/TransactionManager.java
+++ b/src/main/java/financialtransactions/TransactionManager.java
@@ -26,7 +26,7 @@ public void setBudget(double budget) {
public void addTransaction(Transaction> transaction) {
transactionList.addTransaction(transaction);
- // transactionList.sortList();
+ transactionList.sortTransactions();
if (transaction instanceof Inflow) {
Inflow inflow = (Inflow) transaction;
transactionList.setTransactionsType("Inflow");
@@ -76,7 +76,10 @@ public Inflow removeInflow(int index) throws Exception {
int numOfInflows = inflows.getTransactionListSize();
Inflow transactionRemoved = (Inflow) inflows.getNthTransaction(numOfInflows - index);
transactionList.removeTransactionIndex(transactionList.getIndexOfParticularTransaction(transactionRemoved));
+ transactionList.sortTransactions();
+
inflows.removeTransactionIndex(numOfInflows - index);
+ inflows.sortTransactions();
return transactionRemoved;
}
@@ -84,7 +87,10 @@ public Outflow removeOutflow(int index) throws Exception {
int numOfOutflows = outflows.getTransactionListSize();
Outflow transactionRemoved = (Outflow) outflows.getNthTransaction(numOfOutflows - index);
transactionList.removeTransactionIndex(transactionList.getIndexOfParticularTransaction(transactionRemoved));
+ transactionList.sortTransactions();
+
outflows.removeTransactionIndex(numOfOutflows - index);
+ outflows.sortTransactions();
return transactionRemoved;
}
@@ -96,20 +102,28 @@ public Reminder removeReminder(int index) throws Exception {
return transactionRemoved;
}
- public boolean editInflow(int index, Transaction> updatedTransaction) throws Exception {
+ public Inflow editInflow(int index, Transaction> updatedTransaction) throws Exception {
int numOfInflows = inflows.getTransactionListSize();
- Transaction> transactionEdited = inflows.getNthTransaction(numOfInflows - index);
+ Inflow transactionEdited = (Inflow) inflows.getNthTransaction(numOfInflows - index);
transactionList.editTransactionIndex(transactionList.getIndexOfParticularTransaction(transactionEdited),
updatedTransaction);
- return inflows.editTransactionIndex(numOfInflows - index, (Inflow) updatedTransaction);
+ transactionList.sortTransactions();
+
+ inflows.editTransactionIndex(numOfInflows - index, (Inflow) updatedTransaction);
+ inflows.sortTransactions();
+ return (Inflow) transactionEdited;
}
- public boolean editOutflow(int index, Transaction> updatedTransaction) throws Exception {
+ public Outflow editOutflow(int index, Transaction> updatedTransaction) throws Exception {
int numOfOutflows = outflows.getTransactionListSize();
Transaction> transactionEdited = outflows.getNthTransaction(numOfOutflows - index);
transactionList.editTransactionIndex(transactionList.getIndexOfParticularTransaction(transactionEdited),
updatedTransaction);
- return outflows.editTransactionIndex(numOfOutflows - index, (Outflow) updatedTransaction);
+ transactionList.sortTransactions();
+
+ outflows.editTransactionIndex(numOfOutflows - index, (Outflow) updatedTransaction);
+ outflows.sortTransactions();
+ return (Outflow) transactionEdited;
}
public boolean editReminder(int index, Transaction> updatedTransaction) throws Exception {
diff --git a/src/main/java/template/BaseDate.java b/src/main/java/template/BaseDate.java
index 010ccd98ab..f090f25a19 100644
--- a/src/main/java/template/BaseDate.java
+++ b/src/main/java/template/BaseDate.java
@@ -80,4 +80,9 @@ public boolean isBefore(BaseDate otherDate) {
public LocalDateTime getDateTime() {
return dateTime;
}
+
+ public int compareTo(BaseDate otherDate) {
+ return this.dateTime.compareTo(otherDate.dateTime);
+ }
+
}
From c55a6c1d2e6b3a859e7c1c94a3258268af53f033 Mon Sep 17 00:00:00 2001
From: Kishen271828
Date: Thu, 4 Apr 2024 18:19:42 +0800
Subject: [PATCH 130/208] Remove unused imports
---
src/main/java/financialtransactions/TransactionList.java | 2 --
1 file changed, 2 deletions(-)
diff --git a/src/main/java/financialtransactions/TransactionList.java b/src/main/java/financialtransactions/TransactionList.java
index 2ac092d4b7..8334e8fe46 100644
--- a/src/main/java/financialtransactions/TransactionList.java
+++ b/src/main/java/financialtransactions/TransactionList.java
@@ -2,9 +2,7 @@
import java.time.LocalDateTime;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.Comparator;
-import java.util.List;
public class TransactionList> {
private ArrayList transactionList;
From a84503a18ec20657401e0a9605a66f0ac4a35e47 Mon Sep 17 00:00:00 2001
From: Kishen271828
Date: Thu, 4 Apr 2024 18:34:48 +0800
Subject: [PATCH 131/208] Fix gradle checkstyle issues
---
src/main/java/command/AddInflowCommand.java | 3 +++
src/main/java/command/AddOutflowCommand.java | 2 ++
src/main/java/financeproject/Main.java | 4 ++--
src/test/java/parser/ParserTest.java | 2 --
4 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/src/main/java/command/AddInflowCommand.java b/src/main/java/command/AddInflowCommand.java
index a6a8f977a8..8492a39aa0 100644
--- a/src/main/java/command/AddInflowCommand.java
+++ b/src/main/java/command/AddInflowCommand.java
@@ -16,6 +16,7 @@ public AddInflowCommand(String[] commandParts) {
}
private void createInflow() throws CategoryNotFoundException {
+ //@@author Kishen271828
String inflowName = null;
double inflowAmount = 0;
String inflowDate = null;
@@ -39,7 +40,9 @@ private void createInflow() throws CategoryNotFoundException {
inflow = new Inflow(inflowName, inflowAmount, inflowDateTime);
assert inflowCategory != null;
inflow.setCategory(Inflow.Category.valueOf(inflowCategory.toUpperCase()));
+ //@@author
}
+
public String execute(TransactionManager manager) {
//@@author Kishen271828
manager.addTransaction(inflow);
diff --git a/src/main/java/command/AddOutflowCommand.java b/src/main/java/command/AddOutflowCommand.java
index d8c639bc5d..f91085f577 100644
--- a/src/main/java/command/AddOutflowCommand.java
+++ b/src/main/java/command/AddOutflowCommand.java
@@ -16,6 +16,7 @@ public AddOutflowCommand(String[] commandParts) {
}
private void createOutflow() throws CategoryNotFoundException {
+ //@@author Kishen271828
String outflowName = null;
double outflowAmount = 0.0;
String outflowDate = null;
@@ -40,6 +41,7 @@ private void createOutflow() throws CategoryNotFoundException {
outflow = new Outflow(outflowName, outflowAmount, outflowDateTime);
assert outflowCategory != null;
outflow.setCategory(Outflow.Category.valueOf(outflowCategory.toUpperCase()));
+ //@@author
}
public String execute(TransactionManager manager) {
diff --git a/src/main/java/financeproject/Main.java b/src/main/java/financeproject/Main.java
index 1e50d697a2..6b58c06dca 100644
--- a/src/main/java/financeproject/Main.java
+++ b/src/main/java/financeproject/Main.java
@@ -41,8 +41,8 @@ public static void main(String[] args) throws SecurityException {
} else {
return;
}
+
TransactionManager manager = storage.loadFile(user.getUsername());
- //TransactionManager manager = new TransactionManager();
ui.printMessage(manager.generateQuickReport());
// Main program flow
@@ -85,4 +85,4 @@ public static void main(String[] args) throws SecurityException {
} while (baseCommand == null || !baseCommand.isExit());
ui.closeScanner();
}
-}
\ No newline at end of file
+}
diff --git a/src/test/java/parser/ParserTest.java b/src/test/java/parser/ParserTest.java
index fdd713a44a..946de21983 100644
--- a/src/test/java/parser/ParserTest.java
+++ b/src/test/java/parser/ParserTest.java
@@ -31,8 +31,6 @@ public void addOutflow_success() throws Exception {
@Test
public void sampleTest() throws Exception{
- UI ui = new UI();
- Parser parser = new Parser(ui);
String assert1 = "add-inflow n/Salary a/400.00 d/23/05/2022 t/1900 c/income";
String assert2 = "add-outflow n/Rent a/1500.00 d/23/06/2023 t/1800 c/rent\n";
assertInstanceOf(AddInflowCommand.class, parser.parseCommand(assert1));
From a1e9a0c3f056139dba0b3c0916bd4f34df900cb0 Mon Sep 17 00:00:00 2001
From: ChongXern
Date: Thu, 4 Apr 2024 19:58:22 +0800
Subject: [PATCH 132/208] Create IncorrectCommandSyntaxException
Implement exception for commands, throw and catch accordingly.
---
src/main/java/command/AddInflowCommand.java | 12 +++++++++---
src/main/java/command/AddOutflowCommand.java | 12 +++++++++---
src/main/java/command/AddReminderCommand.java | 14 ++++++++++----
src/main/java/command/DeleteInflowCommand.java | 5 ++++-
src/main/java/command/DeleteOutflowCommand.java | 3 +++
src/main/java/command/DeleteReminderCommand.java | 9 +++++----
src/main/java/command/EditInflowCommand.java | 8 +++++++-
src/main/java/command/EditOutflowCommand.java | 8 +++++++-
src/main/java/command/EditReminderCommand.java | 8 +++++++-
src/main/java/command/SetBudgetCommand.java | 11 ++++++-----
src/main/java/command/ViewHistoryCommand.java | 3 ++-
.../IncorrectCommandSyntaxException.java | 7 +++++++
src/main/java/financeproject/Main.java | 3 ++-
src/main/java/financeproject/data/Bob.txt | 4 +++-
14 files changed, 81 insertions(+), 26 deletions(-)
create mode 100644 src/main/java/customexceptions/IncorrectCommandSyntaxException.java
diff --git a/src/main/java/command/AddInflowCommand.java b/src/main/java/command/AddInflowCommand.java
index a6a8f977a8..c095f372d8 100644
--- a/src/main/java/command/AddInflowCommand.java
+++ b/src/main/java/command/AddInflowCommand.java
@@ -1,6 +1,7 @@
package command;
import customexceptions.CategoryNotFoundException;
+import customexceptions.IncorrectCommandSyntaxException;
import financialtransactions.Inflow;
import financialtransactions.TransactionManager;
@@ -10,19 +11,22 @@ public AddInflowCommand(String[] commandParts) {
super(false, commandParts);
try {
createInflow();
- } catch (CategoryNotFoundException e) {
+ } catch (CategoryNotFoundException | IncorrectCommandSyntaxException e) {
System.out.println(e.getMessage());
}
}
- private void createInflow() throws CategoryNotFoundException {
+ private void createInflow() throws CategoryNotFoundException, IncorrectCommandSyntaxException {
String inflowName = null;
double inflowAmount = 0;
String inflowDate = null;
String inflowTime = null;
String inflowCategory = null;
- for (String part : commandParts) {
+ /* Iterates through the parts of the original command string that checks and updates
+ relevant inflow information. */
+ for (int i = 1; i < commandParts.length; i++) {
+ String part = commandParts[i];
if (part.startsWith("n/")) {
inflowName = part.substring(2);
} else if (part.startsWith("a/")) {
@@ -33,6 +37,8 @@ private void createInflow() throws CategoryNotFoundException {
inflowTime = part.substring(2);
} else if (part.startsWith("c/")) {
inflowCategory = part.substring(2);
+ } else {
+ throw new IncorrectCommandSyntaxException(commandParts[0]);
}
}
String inflowDateTime = inflowDate + " " + inflowTime;
diff --git a/src/main/java/command/AddOutflowCommand.java b/src/main/java/command/AddOutflowCommand.java
index d8c639bc5d..27254fe04f 100644
--- a/src/main/java/command/AddOutflowCommand.java
+++ b/src/main/java/command/AddOutflowCommand.java
@@ -1,6 +1,7 @@
package command;
import customexceptions.CategoryNotFoundException;
+import customexceptions.IncorrectCommandSyntaxException;
import financialtransactions.Outflow;
import financialtransactions.TransactionManager;
@@ -10,19 +11,22 @@ public AddOutflowCommand(String[] commandParts) {
super(false, commandParts);
try {
createOutflow();
- } catch (CategoryNotFoundException e) {
+ } catch (CategoryNotFoundException | IncorrectCommandSyntaxException e) {
System.out.println(e.getMessage());
}
}
- private void createOutflow() throws CategoryNotFoundException {
+ private void createOutflow() throws CategoryNotFoundException, IncorrectCommandSyntaxException {
String outflowName = null;
double outflowAmount = 0.0;
String outflowDate = null;
String outflowTime = null;
String outflowCategory = null;
- for (String part : commandParts) {
+ /* Iterates through the parts of the original command string that checks and updates
+ relevant outflow information. */
+ for (int i = 1 ; i < commandParts.length; i++) {
+ String part = commandParts[i];
if (part.startsWith("n/")) {
outflowName = part.substring(2);
} else if (part.startsWith("a/")) {
@@ -33,6 +37,8 @@ private void createOutflow() throws CategoryNotFoundException {
outflowTime = part.substring(2);
} else if (part.startsWith("c/")) {
outflowCategory = part.substring(2);
+ } else {
+ throw new IncorrectCommandSyntaxException(commandParts[0]);
}
}
String outflowDateTime = outflowDate + " " + outflowTime;
diff --git a/src/main/java/command/AddReminderCommand.java b/src/main/java/command/AddReminderCommand.java
index 7daa2d596b..a411def310 100644
--- a/src/main/java/command/AddReminderCommand.java
+++ b/src/main/java/command/AddReminderCommand.java
@@ -1,6 +1,7 @@
package command;
import customexceptions.CategoryNotFoundException;
+import customexceptions.IncorrectCommandSyntaxException;
import financialtransactions.Reminder;
import financialtransactions.TransactionManager;
@@ -9,19 +10,22 @@ public AddReminderCommand(String[] commandParts) {
super(false, commandParts);
try {
createReminder();
- } catch (CategoryNotFoundException e) {
+ } catch (CategoryNotFoundException | IncorrectCommandSyntaxException e) {
System.out.println(e.getMessage());
}
}
-
- private void createReminder() throws CategoryNotFoundException {
+
+ private void createReminder() throws CategoryNotFoundException, IncorrectCommandSyntaxException {
String reminderName = null;
double reminderAmount = 0.0;
String reminderDate = null;
String reminderTime = null;
String reminderCategory = null;
- for (String part : commandParts) {
+ /* Iterates through the parts of the original command string that checks and updates
+ relevant reminder information. */
+ for (int i = 1; i < commandParts.length; i++) {
+ String part = commandParts[i];
if (part.startsWith("n/")) {
reminderName = part.substring(2);
} else if (part.startsWith("a/")) {
@@ -32,6 +36,8 @@ private void createReminder() throws CategoryNotFoundException {
reminderTime = part.substring(2);
} else if (part.startsWith("c/")) {
reminderCategory = part.substring(2);
+ } else {
+ throw new IncorrectCommandSyntaxException(commandParts[0]);
}
}
String reminderDateTime = reminderDate + " " + reminderTime;
diff --git a/src/main/java/command/DeleteInflowCommand.java b/src/main/java/command/DeleteInflowCommand.java
index 4215528cfc..acfbb25328 100644
--- a/src/main/java/command/DeleteInflowCommand.java
+++ b/src/main/java/command/DeleteInflowCommand.java
@@ -1,16 +1,19 @@
package command;
+import customexceptions.IncorrectCommandSyntaxException;
import financialtransactions.TransactionManager;
public class DeleteInflowCommand extends BaseCommand {
- private String inflowIndex = null;
public DeleteInflowCommand(String[] commandParts) {
super(false, commandParts);
}
public String execute(TransactionManager manager) throws Exception {
+ String inflowIndex = null;
if (commandParts[1].startsWith("i/")) {
inflowIndex = commandParts[1].substring(2);
+ } else {
+ throw new IncorrectCommandSyntaxException(commandParts[0]);
}
assert inflowIndex != null : "inflowIndex should not be null";
int inflowIndexParsed = Integer.parseInt(inflowIndex);
diff --git a/src/main/java/command/DeleteOutflowCommand.java b/src/main/java/command/DeleteOutflowCommand.java
index cc79f7eaf6..7b841ed98e 100644
--- a/src/main/java/command/DeleteOutflowCommand.java
+++ b/src/main/java/command/DeleteOutflowCommand.java
@@ -1,5 +1,6 @@
package command;
+import customexceptions.IncorrectCommandSyntaxException;
import financialtransactions.TransactionManager;
public class DeleteOutflowCommand extends BaseCommand {
@@ -11,6 +12,8 @@ public String execute(TransactionManager manager) throws Exception {
String outflowIndex = null;
if (commandParts[1].startsWith("i/")) {
outflowIndex = commandParts[1].substring(2);
+ } else {
+ throw new IncorrectCommandSyntaxException(commandParts[0]);
}
assert outflowIndex != null : "outflowIndex should not be null";
int outflowIndexParsed = Integer.parseInt(outflowIndex);
diff --git a/src/main/java/command/DeleteReminderCommand.java b/src/main/java/command/DeleteReminderCommand.java
index 085ba2413f..73acb5bd10 100644
--- a/src/main/java/command/DeleteReminderCommand.java
+++ b/src/main/java/command/DeleteReminderCommand.java
@@ -1,5 +1,6 @@
package command;
+import customexceptions.IncorrectCommandSyntaxException;
import financialtransactions.TransactionManager;
public class DeleteReminderCommand extends BaseCommand {
@@ -9,10 +10,10 @@ public DeleteReminderCommand(String[] commandParts) {
public String execute(TransactionManager manager) throws Exception {
String reminderIndex = null;
- for (String part : commandParts) {
- if (part.startsWith("i/")) {
- reminderIndex = part.substring(2);
- }
+ if (commandParts[1].startsWith("i/")) {
+ reminderIndex = commandParts[1].substring(2);
+ } else {
+ throw new IncorrectCommandSyntaxException(commandParts[0]);
}
assert reminderIndex != null : "reminderIndex should not be null";
reminder = manager.removeReminder(Integer.parseInt(reminderIndex));
diff --git a/src/main/java/command/EditInflowCommand.java b/src/main/java/command/EditInflowCommand.java
index 860c4a4f59..845c072b42 100644
--- a/src/main/java/command/EditInflowCommand.java
+++ b/src/main/java/command/EditInflowCommand.java
@@ -1,5 +1,6 @@
package command;
+import customexceptions.IncorrectCommandSyntaxException;
import financialtransactions.Inflow;
import financialtransactions.TransactionManager;
@@ -16,7 +17,10 @@ public String execute(TransactionManager manager) throws Exception {
String inflowTime = null;
String inflowCategory = null;
- for (String part : commandParts) {
+ /* Iterates through the parts of the original command string that checks and updates
+ relevant inflow information. */
+ for (int i = 1; i < commandParts.length; i++) {
+ String part = commandParts[i];
if (part.startsWith("i/")) {
inflowIndex = Integer.parseInt(part.substring(2));
} else if (part.startsWith("n/")) {
@@ -29,6 +33,8 @@ public String execute(TransactionManager manager) throws Exception {
inflowTime = part.substring(2);
} else if (part.startsWith("c/")) {
inflowCategory = part.substring(2);
+ } else {
+ throw new IncorrectCommandSyntaxException(commandParts[0]);
}
}
diff --git a/src/main/java/command/EditOutflowCommand.java b/src/main/java/command/EditOutflowCommand.java
index 542f45d076..2e39f9447b 100644
--- a/src/main/java/command/EditOutflowCommand.java
+++ b/src/main/java/command/EditOutflowCommand.java
@@ -1,5 +1,6 @@
package command;
+import customexceptions.IncorrectCommandSyntaxException;
import financialtransactions.Outflow;
import financialtransactions.TransactionManager;
@@ -16,7 +17,10 @@ public String execute(TransactionManager manager) throws Exception {
String outflowTime = null;
String outflowCategory = null;
- for (String part : commandParts) {
+ /* Iterates through the parts of the original command string that checks and updates
+ relevant outflow information. */
+ for (int i = 1; i < commandParts.length; i++) {
+ String part = commandParts[i];
if (part.startsWith("i/")) {
outflowIndex = Integer.parseInt(part.substring(2));
} else if (part.startsWith("n/")) {
@@ -29,6 +33,8 @@ public String execute(TransactionManager manager) throws Exception {
outflowTime = part.substring(2);
} else if (part.startsWith("c/")) {
outflowCategory = part.substring(2);
+ } else {
+ throw new IncorrectCommandSyntaxException(commandParts[0]);
}
}
diff --git a/src/main/java/command/EditReminderCommand.java b/src/main/java/command/EditReminderCommand.java
index b35bb2516a..4ae7d80520 100644
--- a/src/main/java/command/EditReminderCommand.java
+++ b/src/main/java/command/EditReminderCommand.java
@@ -1,5 +1,6 @@
package command;
+import customexceptions.IncorrectCommandSyntaxException;
import financialtransactions.Reminder;
import financialtransactions.TransactionManager;
@@ -16,7 +17,10 @@ public String execute(TransactionManager manager) throws Exception {
String reminderTime = null;
String reminderCategory = null;
- for (String part : commandParts) {
+ /* Iterates through the parts of the original command string that checks and updates
+ relevant reminder information. */
+ for (int i = 1; i < commandParts.length; i++) {
+ String part = commandParts[i];
if (part.startsWith("i/")) {
reminderIndex = Integer.parseInt(part.substring(2));
} else if (part.startsWith("n/")) {
@@ -29,6 +33,8 @@ public String execute(TransactionManager manager) throws Exception {
reminderTime = part.substring(2);
} else if (part.startsWith("c/")) {
reminderCategory = part.substring(2);
+ } else {
+ throw new IncorrectCommandSyntaxException(commandParts[0]);
}
}
diff --git a/src/main/java/command/SetBudgetCommand.java b/src/main/java/command/SetBudgetCommand.java
index 686290a3bd..fbf0daa956 100644
--- a/src/main/java/command/SetBudgetCommand.java
+++ b/src/main/java/command/SetBudgetCommand.java
@@ -1,5 +1,6 @@
package command;
+import customexceptions.IncorrectCommandSyntaxException;
import financialtransactions.TransactionManager;
public class SetBudgetCommand extends BaseCommand{
@@ -9,11 +10,11 @@ public SetBudgetCommand(String[] commandParts) {
public String execute(TransactionManager manager) throws Exception{
String budgetString = null;
- for (String part : commandParts) {
- if (part.startsWith("a/")) {
- budgetString = part.substring(2);
- }
- }
+ if (commandParts[1].startsWith("a/")) {
+ budgetString = commandParts[1].substring(2);
+ } else {
+ throw new IncorrectCommandSyntaxException(commandParts[0]);
+ }
double budget = Double.parseDouble(budgetString);
manager.setBudget(budget);
return "Ok. Budget set.";
diff --git a/src/main/java/command/ViewHistoryCommand.java b/src/main/java/command/ViewHistoryCommand.java
index 880e341907..bb90f7fdd6 100644
--- a/src/main/java/command/ViewHistoryCommand.java
+++ b/src/main/java/command/ViewHistoryCommand.java
@@ -1,5 +1,6 @@
package command;
+import customexceptions.IncorrectCommandSyntaxException;
import financialtransactions.TransactionManager;
public class ViewHistoryCommand extends BaseCommand {
@@ -18,7 +19,7 @@ public String execute(TransactionManager manager) throws Exception{
} else if (commandParts[1].equals("all")) {
numTransactions = manager.getTransactionListSize();
} else {
- return "Sorry, please use the correct syntax for view-history.";
+ throw new IncorrectCommandSyntaxException(commandParts[0]);
}
boolean isIncludeBarChart = commandParts.length == 3 && commandParts[2].equals("w/chart");
return manager.showLastNTransactions(numTransactions, isIncludeBarChart);
diff --git a/src/main/java/customexceptions/IncorrectCommandSyntaxException.java b/src/main/java/customexceptions/IncorrectCommandSyntaxException.java
new file mode 100644
index 0000000000..40a2c6215f
--- /dev/null
+++ b/src/main/java/customexceptions/IncorrectCommandSyntaxException.java
@@ -0,0 +1,7 @@
+package customexceptions;
+
+public class IncorrectCommandSyntaxException extends Exception {
+ public IncorrectCommandSyntaxException(String command) {
+ super("Sorry, please use the correct syntax for " + command);
+ }
+}
diff --git a/src/main/java/financeproject/Main.java b/src/main/java/financeproject/Main.java
index 0b39251165..8f6bf6a41e 100644
--- a/src/main/java/financeproject/Main.java
+++ b/src/main/java/financeproject/Main.java
@@ -5,6 +5,7 @@
import customexceptions.InactivityTimeoutException;
import customexceptions.IncompletePromptException;
import customexceptions.UserNotFoundException;
+import customexceptions.IncorrectCommandSyntaxException;
import financialtransactions.TransactionManager;
import parser.Parser;
import storage.Storage;
@@ -52,7 +53,7 @@ public static void main(String[] args) throws SecurityException {
response = baseCommand.execute(manager);
ui.printMessage(response);
inactivityTimer.resetTimer();
- } catch (IncompletePromptException e) {
+ } catch (IncompletePromptException | IncorrectCommandSyntaxException e) {
ui.printMessage(e.getMessage());
} catch (Exception e) {
ui.printMessage("Uh-oh, something went wrong: " + e.getMessage());
diff --git a/src/main/java/financeproject/data/Bob.txt b/src/main/java/financeproject/data/Bob.txt
index 1cc11e2cd4..420644bb63 100644
--- a/src/main/java/financeproject/data/Bob.txt
+++ b/src/main/java/financeproject/data/Bob.txt
@@ -1,6 +1,8 @@
-0.00
+100.00
Stocks|400.00|Oct 24 2024 12:00PM|INVESTMENT|I
Refund|100.00|Jun 23 2023 05:00PM|REFUND|I
Salary|400.00|May 23 2022 07:00PM|INCOME|I
+Salary|400.00|May 23 2022 07:00PM|INCOME|I
Groceries|-150.00|Jun 23 2023 06:30PM|SHOPPING|O
Rent|-1500.00|Jun 23 2023 06:00PM|RENT|O
+Rent|-1500.00|Jun 23 2023 06:00PM|RENT|O
From 6dc63a691fc789c72ad18bf82f3db0cda7b3bc88 Mon Sep 17 00:00:00 2001
From: ChongXern
Date: Thu, 4 Apr 2024 21:39:14 +0800
Subject: [PATCH 133/208] Create CategoryNotFoundException
Implemented in commands and transactions, as well as junit tests
---
src/main/java/command/AddInflowCommand.java | 15 +++++++++++----
src/main/java/command/AddOutflowCommand.java | 15 +++++++++++----
src/main/java/command/AddReminderCommand.java | 14 +++++++++++---
src/main/java/command/BaseCommand.java | 4 ++++
src/main/java/command/EditInflowCommand.java | 11 ++++++++++-
src/main/java/command/EditOutflowCommand.java | 11 ++++++++++-
src/main/java/command/EditReminderCommand.java | 11 ++++++++++-
.../CategoryNotFoundException.java | 8 +++++++-
src/main/java/financeproject/data/Bob.txt | 6 +++---
.../java/financialtransactions/Inflow.java | 18 ++++++++++++------
.../java/financialtransactions/Outflow.java | 14 +++++++++-----
.../java/financialtransactions/Reminder.java | 14 +++++++++-----
.../financialtransactions/Transaction.java | 4 ++--
src/main/java/storage/Storage.java | 6 +++---
.../java/financialtransactions/InflowTest.java | 2 +-
.../financialtransactions/OutflowTest.java | 2 +-
.../TransactionManagerTest.java | 6 +++---
src/test/java/seedu/OutflowTest.java | 2 +-
18 files changed, 118 insertions(+), 45 deletions(-)
diff --git a/src/main/java/command/AddInflowCommand.java b/src/main/java/command/AddInflowCommand.java
index 6177cd8c98..43d07ad549 100644
--- a/src/main/java/command/AddInflowCommand.java
+++ b/src/main/java/command/AddInflowCommand.java
@@ -11,12 +11,12 @@ public AddInflowCommand(String[] commandParts) {
super(false, commandParts);
try {
createInflow();
- } catch (CategoryNotFoundException | IncorrectCommandSyntaxException e) {
+ } catch (IncorrectCommandSyntaxException e) {
System.out.println(e.getMessage());
}
}
- private void createInflow() throws CategoryNotFoundException, IncorrectCommandSyntaxException {
+ private void createInflow() throws IncorrectCommandSyntaxException {
//@@author Kishen271828
String inflowName = null;
double inflowAmount = 0;
@@ -45,12 +45,19 @@ private void createInflow() throws CategoryNotFoundException, IncorrectCommandSy
String inflowDateTime = inflowDate + " " + inflowTime;
inflow = new Inflow(inflowName, inflowAmount, inflowDateTime);
assert inflowCategory != null;
- inflow.setCategory(Inflow.Category.valueOf(inflowCategory.toUpperCase()));
- //@@author
+ try {
+ inflow.setCategory(inflowCategory);
+ } catch (CategoryNotFoundException e) {
+ System.out.println(e.getMessage());
+ e.disableExecute(this);
+ }
}
public String execute(TransactionManager manager) {
//@@author Kishen271828
+ if (!canExecute) {
+ return "Sorry, inflow not added.";
+ }
manager.addTransaction(inflow);
return "Ok. Added inflow";
}
diff --git a/src/main/java/command/AddOutflowCommand.java b/src/main/java/command/AddOutflowCommand.java
index 9cac783cec..f2563f34af 100644
--- a/src/main/java/command/AddOutflowCommand.java
+++ b/src/main/java/command/AddOutflowCommand.java
@@ -11,12 +11,12 @@ public AddOutflowCommand(String[] commandParts) {
super(false, commandParts);
try {
createOutflow();
- } catch (CategoryNotFoundException | IncorrectCommandSyntaxException e) {
+ } catch (IncorrectCommandSyntaxException e) {
System.out.println(e.getMessage());
}
}
- private void createOutflow() throws CategoryNotFoundException, IncorrectCommandSyntaxException {
+ private void createOutflow() throws IncorrectCommandSyntaxException {
//@@author Kishen271828
String outflowName = null;
double outflowAmount = 0.0;
@@ -46,12 +46,19 @@ private void createOutflow() throws CategoryNotFoundException, IncorrectCommandS
outflow = new Outflow(outflowName, outflowAmount, outflowDateTime);
assert outflowCategory != null;
- outflow.setCategory(Outflow.Category.valueOf(outflowCategory.toUpperCase()));
- //@@author
+ try {
+ outflow.setCategory(outflowCategory);
+ } catch (CategoryNotFoundException e) {
+ System.out.println(e.getMessage());
+ e.disableExecute(this);
+ }
}
public String execute(TransactionManager manager) {
//@@author Kishen271828
+ if (!canExecute) {
+ return "Sorry, outflow not added.";
+ }
manager.addTransaction(outflow);
return "Ok. Added outflow";
}
diff --git a/src/main/java/command/AddReminderCommand.java b/src/main/java/command/AddReminderCommand.java
index a411def310..4ef8603622 100644
--- a/src/main/java/command/AddReminderCommand.java
+++ b/src/main/java/command/AddReminderCommand.java
@@ -10,12 +10,12 @@ public AddReminderCommand(String[] commandParts) {
super(false, commandParts);
try {
createReminder();
- } catch (CategoryNotFoundException | IncorrectCommandSyntaxException e) {
+ } catch (IncorrectCommandSyntaxException e) {
System.out.println(e.getMessage());
}
}
- private void createReminder() throws CategoryNotFoundException, IncorrectCommandSyntaxException {
+ private void createReminder() throws IncorrectCommandSyntaxException {
String reminderName = null;
double reminderAmount = 0.0;
String reminderDate = null;
@@ -43,10 +43,18 @@ private void createReminder() throws CategoryNotFoundException, IncorrectCommand
String reminderDateTime = reminderDate + " " + reminderTime;
reminder = new Reminder(reminderName, reminderAmount, reminderDateTime);
assert reminderCategory != null;
- reminder.setCategory(Reminder.Category.valueOf(reminderCategory.toUpperCase()));
+ try {
+ reminder.setCategory(reminderCategory.toUpperCase());
+ } catch (CategoryNotFoundException e) {
+ System.out.println(e.getMessage());
+ e.disableExecute(this);
+ }
}
public String execute(TransactionManager manager) {
+ if (!canExecute) {
+ return "Sorry, reminder not added.";
+ }
manager.addTransaction(reminder);
return "Ok. Added reminder";
}
diff --git a/src/main/java/command/BaseCommand.java b/src/main/java/command/BaseCommand.java
index 38d6c55b6e..c18109f03e 100644
--- a/src/main/java/command/BaseCommand.java
+++ b/src/main/java/command/BaseCommand.java
@@ -6,6 +6,7 @@
import financialtransactions.TransactionManager;
public abstract class BaseCommand {
+ protected boolean canExecute = true;
public boolean isExit;
protected Inflow inflow;
protected Outflow outflow;
@@ -15,6 +16,9 @@ public BaseCommand(Boolean isExit, String[] commandParts){
this.isExit = isExit;
this.commandParts = commandParts;
}
+ public void setCanExecuteToFalse() {
+ this.canExecute = false;
+ }
public abstract String execute(TransactionManager manager) throws Exception;
public boolean isExit() {
diff --git a/src/main/java/command/EditInflowCommand.java b/src/main/java/command/EditInflowCommand.java
index 845c072b42..d6b872a113 100644
--- a/src/main/java/command/EditInflowCommand.java
+++ b/src/main/java/command/EditInflowCommand.java
@@ -1,5 +1,6 @@
package command;
+import customexceptions.CategoryNotFoundException;
import customexceptions.IncorrectCommandSyntaxException;
import financialtransactions.Inflow;
import financialtransactions.TransactionManager;
@@ -41,7 +42,15 @@ public String execute(TransactionManager manager) throws Exception {
String inflowDateTime = inflowDate + " " + inflowTime;
Inflow updatedInflow = new Inflow(inflowName, inflowAmount, inflowDateTime);
assert inflowCategory != null : "inflowCategory should not be null";
- updatedInflow.setCategory(Inflow.Category.valueOf(inflowCategory.toUpperCase()));
+ try {
+ updatedInflow.setCategory(inflowCategory);
+ } catch (CategoryNotFoundException e) {
+ System.out.println(e.getMessage());
+ e.disableExecute(this);
+ }
+ if (!canExecute) {
+ return "Sorry, inflow not edited.";
+ }
manager.editInflow(inflowIndex, updatedInflow);
return "Ok. Edited inflow";
}
diff --git a/src/main/java/command/EditOutflowCommand.java b/src/main/java/command/EditOutflowCommand.java
index 2e39f9447b..e5c403624b 100644
--- a/src/main/java/command/EditOutflowCommand.java
+++ b/src/main/java/command/EditOutflowCommand.java
@@ -1,5 +1,6 @@
package command;
+import customexceptions.CategoryNotFoundException;
import customexceptions.IncorrectCommandSyntaxException;
import financialtransactions.Outflow;
import financialtransactions.TransactionManager;
@@ -41,7 +42,15 @@ public String execute(TransactionManager manager) throws Exception {
String outflowDateTime = outflowDate + " " + outflowTime;
Outflow updatedOutflow = new Outflow(outflowName, outflowAmount, outflowDateTime);
assert outflowCategory != null : "outflowCategory should not be null";
- updatedOutflow.setCategory(Outflow.Category.valueOf(outflowCategory.toUpperCase()));
+ try {
+ updatedOutflow.setCategory(outflowCategory);
+ } catch (CategoryNotFoundException e) {
+ System.out.println(e.getMessage());
+ e.disableExecute(this);
+ }
+ if (!canExecute) {
+ return "Sorry, outflow not edited.";
+ }
manager.editOutflow(outflowIndex, updatedOutflow);
return "Ok. Edited outflow";
}
diff --git a/src/main/java/command/EditReminderCommand.java b/src/main/java/command/EditReminderCommand.java
index 4ae7d80520..70aa3e45f7 100644
--- a/src/main/java/command/EditReminderCommand.java
+++ b/src/main/java/command/EditReminderCommand.java
@@ -1,5 +1,6 @@
package command;
+import customexceptions.CategoryNotFoundException;
import customexceptions.IncorrectCommandSyntaxException;
import financialtransactions.Reminder;
import financialtransactions.TransactionManager;
@@ -41,7 +42,15 @@ public String execute(TransactionManager manager) throws Exception {
String reminderDateTime = reminderDate + " " + reminderTime;
Reminder updatedReminder = new Reminder(reminderName, reminderAmount, reminderDateTime);
assert reminderCategory != null : "reminderCategory should not be null";
- updatedReminder.setCategory(Reminder.Category.valueOf(reminderCategory.toUpperCase()));
+ try {
+ updatedReminder.setCategory(reminderCategory.toUpperCase());
+ } catch (CategoryNotFoundException e) {
+ System.out.println(e.getMessage());
+ e.disableExecute(this);
+ }
+ if (!canExecute) {
+ return "Sorry, reminder not edited.";
+ }
manager.editOutflow(reminderIndex, updatedReminder);
return "Ok. Edited reminder";
}
diff --git a/src/main/java/customexceptions/CategoryNotFoundException.java b/src/main/java/customexceptions/CategoryNotFoundException.java
index 39f4df5072..dd61bc63d2 100644
--- a/src/main/java/customexceptions/CategoryNotFoundException.java
+++ b/src/main/java/customexceptions/CategoryNotFoundException.java
@@ -1,9 +1,15 @@
package customexceptions;
+import command.BaseCommand;
+
import java.util.Arrays;
public class CategoryNotFoundException extends Exception {
public CategoryNotFoundException(Enum>[] categories) {
- super("Category not found. Available categories are: " + Arrays.toString(categories));
+ super("Category not found. Available categories are:\n" + Arrays.toString(categories));
+ }
+
+ public void disableExecute(BaseCommand command) {
+ command.setCanExecuteToFalse();
}
}
diff --git a/src/main/java/financeproject/data/Bob.txt b/src/main/java/financeproject/data/Bob.txt
index 420644bb63..07cf208888 100644
--- a/src/main/java/financeproject/data/Bob.txt
+++ b/src/main/java/financeproject/data/Bob.txt
@@ -1,8 +1,8 @@
100.00
-Stocks|400.00|Oct 24 2024 12:00PM|INVESTMENT|I
-Refund|100.00|Jun 23 2023 05:00PM|REFUND|I
+Payday|800.00|Feb 22 2022 12:09AM|INCOME|I
+Payday|800.00|Feb 22 2022 12:09AM|INCOME|I
+Salary|400.00|May 23 2022 07:00PM|INCOME|I
Salary|400.00|May 23 2022 07:00PM|INCOME|I
Salary|400.00|May 23 2022 07:00PM|INCOME|I
-Groceries|-150.00|Jun 23 2023 06:30PM|SHOPPING|O
Rent|-1500.00|Jun 23 2023 06:00PM|RENT|O
Rent|-1500.00|Jun 23 2023 06:00PM|RENT|O
diff --git a/src/main/java/financialtransactions/Inflow.java b/src/main/java/financialtransactions/Inflow.java
index 687836302b..efa5f0f28e 100644
--- a/src/main/java/financialtransactions/Inflow.java
+++ b/src/main/java/financialtransactions/Inflow.java
@@ -13,18 +13,24 @@ public Inflow(String name, double amount, String date) {
super(name, amount, date);
}
- public void setCategory(Category category) throws CategoryNotFoundException {
+ @Override
+ public void setCategory(String category) throws CategoryNotFoundException {
if (!isValidCategory(category)) {
throw new CategoryNotFoundException(Category.values());
}
- super.category = category;
+ super.category = Category.valueOf(category.toUpperCase());
}
- public boolean isValidCategory(Category category) {
- EnumSet categories = EnumSet.allOf(Category.class);
- return categories.contains(category);
+ public boolean isValidCategory(String category) {
+ for (Category enumCategory : Category.values()) {
+ if (enumCategory.toString().equalsIgnoreCase(category)) {
+ return true;
+ }
+ }
+ return false;
}
-
+
+
@Override
public String toSave() {
return super.toSave() + "|I\n";
diff --git a/src/main/java/financialtransactions/Outflow.java b/src/main/java/financialtransactions/Outflow.java
index a21b6c9769..1f5a9b6644 100644
--- a/src/main/java/financialtransactions/Outflow.java
+++ b/src/main/java/financialtransactions/Outflow.java
@@ -13,15 +13,19 @@ public Outflow(String name, double amount, String date) {
super(name, -1.00 * amount, date);
}
- public void setCategory(Category category) throws CategoryNotFoundException {
+ public void setCategory(String category) throws CategoryNotFoundException {
if (!isValidCategory(category)) {
throw new CategoryNotFoundException(Category.values());
}
- this.category = category;
+ this.category = Category.valueOf(category.toUpperCase());
}
- public boolean isValidCategory(Category category) {
- EnumSet categories = EnumSet.allOf(Category.class);
- return categories.contains(category);
+ public boolean isValidCategory(String category) {
+ for (Category enumCategory : Category.values()) {
+ if (enumCategory.toString().equalsIgnoreCase(category)) {
+ return true;
+ }
+ }
+ return false;
}
@Override
diff --git a/src/main/java/financialtransactions/Reminder.java b/src/main/java/financialtransactions/Reminder.java
index c281cb7a1c..c621e72579 100644
--- a/src/main/java/financialtransactions/Reminder.java
+++ b/src/main/java/financialtransactions/Reminder.java
@@ -13,16 +13,20 @@ public Reminder(String name, double amount, String date) {
super(name, -1.00 * amount, date);
}
- public void setCategory(Category category) throws CategoryNotFoundException {
+ public void setCategory(String category) throws CategoryNotFoundException {
if (!isValidCategory(category)) {
throw new CategoryNotFoundException(Category.values());
}
- this.category = category;
+ this.category = Category.valueOf(category.toUpperCase());
}
- public boolean isValidCategory(Category category) {
- EnumSet categories = EnumSet.allOf(Category.class);
- return categories.contains(category);
+ public boolean isValidCategory(String category) {
+ for (Category enumCategory : Category.values()) {
+ if (enumCategory.toString().equalsIgnoreCase(category)) {
+ return true;
+ }
+ }
+ return false;
}
@Override
diff --git a/src/main/java/financialtransactions/Transaction.java b/src/main/java/financialtransactions/Transaction.java
index e31a93e2e4..3e0337bcbc 100644
--- a/src/main/java/financialtransactions/Transaction.java
+++ b/src/main/java/financialtransactions/Transaction.java
@@ -41,8 +41,8 @@ public T getCategory() {
return category;
}
- protected abstract void setCategory(T category) throws CategoryNotFoundException;
- protected abstract boolean isValidCategory(T category);
+ protected abstract void setCategory(String category) throws CategoryNotFoundException;
+ protected abstract boolean isValidCategory(String category);
@Override
public String toString() {
diff --git a/src/main/java/storage/Storage.java b/src/main/java/storage/Storage.java
index 818e18cffe..3752d6540a 100644
--- a/src/main/java/storage/Storage.java
+++ b/src/main/java/storage/Storage.java
@@ -65,15 +65,15 @@ public TransactionManager loadFile(String username) {
double amount = Double.parseDouble(transactionInfo[1]);
if (transactionInfo[4].equals("I")) {
Inflow inflow = new Inflow(transactionInfo[0], amount, transactionInfo[2]);
- inflow.setCategory(Inflow.Category.valueOf(transactionInfo[3]));
+ inflow.setCategory(transactionInfo[3]);
manager.addTransaction(inflow);
} else if (transactionInfo[4].equals("O")){
Outflow outflow = new Outflow(transactionInfo[0], -amount, transactionInfo[2]);
- outflow.setCategory(Outflow.Category.valueOf(transactionInfo[3]));
+ outflow.setCategory(transactionInfo[3]);
manager.addTransaction(outflow);
} else {
Reminder reminder = new Reminder(transactionInfo[0], -amount, transactionInfo[2]);
- reminder.setCategory(Reminder.Category.valueOf(transactionInfo[3]));
+ reminder.setCategory(transactionInfo[3]);
manager.addTransaction(reminder);
}
}
diff --git a/src/test/java/financialtransactions/InflowTest.java b/src/test/java/financialtransactions/InflowTest.java
index 2a62d23322..fe25d2c7aa 100644
--- a/src/test/java/financialtransactions/InflowTest.java
+++ b/src/test/java/financialtransactions/InflowTest.java
@@ -10,7 +10,7 @@ public class InflowTest {
public void testSetCategory() {
Inflow inflow = new Inflow("February salary", 20.00, "2024-03-02");
try {
- inflow.setCategory(Inflow.Category.INCOME);
+ inflow.setCategory("Income");
} catch (CategoryNotFoundException e) {
System.out.println(e.getMessage());
}
diff --git a/src/test/java/financialtransactions/OutflowTest.java b/src/test/java/financialtransactions/OutflowTest.java
index bb708dbe9d..53d1e3d0e9 100644
--- a/src/test/java/financialtransactions/OutflowTest.java
+++ b/src/test/java/financialtransactions/OutflowTest.java
@@ -7,6 +7,6 @@ public class OutflowTest {
@Test
public void testIsValidCategory(){
Outflow outflow = new Outflow("2024 Sem 2 School Fees", 999999.99, "2024-04-01");
- assertTrue(outflow.isValidCategory(Outflow.Category.EDUCATION));
+ assertTrue(outflow.isValidCategory("EDUCATION"));
}
}
diff --git a/src/test/java/financialtransactions/TransactionManagerTest.java b/src/test/java/financialtransactions/TransactionManagerTest.java
index 6d01e7405e..082f99ef2f 100644
--- a/src/test/java/financialtransactions/TransactionManagerTest.java
+++ b/src/test/java/financialtransactions/TransactionManagerTest.java
@@ -12,7 +12,7 @@ public void toSaveTest() {
Inflow income = new Inflow("Salary payment", 400.00, "23/05/2022 1900");
try {
- income.setCategory(Inflow.Category.INCOME);
+ income.setCategory("INCOME");
} catch (CategoryNotFoundException e) {
System.out.println(e.getMessage());
}
@@ -20,7 +20,7 @@ public void toSaveTest() {
Outflow shopping = new Outflow("Shopping", 200, "23/05/2022 2000");
try {
- shopping.setCategory(Outflow.Category.SHOPPING);
+ shopping.setCategory("Shopping");
} catch (CategoryNotFoundException e) {
System.out.println(e.getMessage());
}
@@ -28,7 +28,7 @@ public void toSaveTest() {
Reminder bill = new Reminder("Water bills", 64.30, "25/06/2025 1500");
try {
- bill.setCategory(Reminder.Category.UTILITIES);
+ bill.setCategory("utilities");
} catch (CategoryNotFoundException e) {
System.out.println(e.getMessage());
}
diff --git a/src/test/java/seedu/OutflowTest.java b/src/test/java/seedu/OutflowTest.java
index aaa29729ef..de080dbcaf 100644
--- a/src/test/java/seedu/OutflowTest.java
+++ b/src/test/java/seedu/OutflowTest.java
@@ -10,7 +10,7 @@ public class OutflowTest {
public void testSetCategory() {
Outflow outflow = new Outflow("2024 Sem 2 School Fees", 999999.99, "2024-02-01");
try {
- outflow.setCategory(Outflow.Category.EDUCATION);
+ outflow.setCategory("Education");
} catch (CategoryNotFoundException e) {
System.out.println(e.getMessage());
}
From 245851d830f457244e53333dad486eb98471f3b0 Mon Sep 17 00:00:00 2001
From: ChongXern
Date: Thu, 4 Apr 2024 21:44:15 +0800
Subject: [PATCH 134/208] Fix checkstyle errors
---
src/main/java/command/BaseCommand.java | 2 +-
src/main/java/financialtransactions/Inflow.java | 2 --
src/main/java/financialtransactions/Outflow.java | 2 --
src/main/java/financialtransactions/Reminder.java | 2 --
4 files changed, 1 insertion(+), 7 deletions(-)
diff --git a/src/main/java/command/BaseCommand.java b/src/main/java/command/BaseCommand.java
index c18109f03e..87c68c24d5 100644
--- a/src/main/java/command/BaseCommand.java
+++ b/src/main/java/command/BaseCommand.java
@@ -6,11 +6,11 @@
import financialtransactions.TransactionManager;
public abstract class BaseCommand {
- protected boolean canExecute = true;
public boolean isExit;
protected Inflow inflow;
protected Outflow outflow;
protected Reminder reminder;
+ protected boolean canExecute = true;
String[] commandParts;
public BaseCommand(Boolean isExit, String[] commandParts){
this.isExit = isExit;
diff --git a/src/main/java/financialtransactions/Inflow.java b/src/main/java/financialtransactions/Inflow.java
index efa5f0f28e..8d97a07af3 100644
--- a/src/main/java/financialtransactions/Inflow.java
+++ b/src/main/java/financialtransactions/Inflow.java
@@ -2,8 +2,6 @@
import customexceptions.CategoryNotFoundException;
-import java.util.EnumSet;
-
public class Inflow extends Transaction {
public enum Category {
INCOME, INVESTMENT, GIFT, LOAN, REFUND, OTHER
diff --git a/src/main/java/financialtransactions/Outflow.java b/src/main/java/financialtransactions/Outflow.java
index 1f5a9b6644..df678075d6 100644
--- a/src/main/java/financialtransactions/Outflow.java
+++ b/src/main/java/financialtransactions/Outflow.java
@@ -2,8 +2,6 @@
import customexceptions.CategoryNotFoundException;
-import java.util.EnumSet;
-
public class Outflow extends Transaction {
public enum Category {
FOOD, RENT, DEBT, SHOPPING, TREAT, EDUCATION, TAX, OTHER
diff --git a/src/main/java/financialtransactions/Reminder.java b/src/main/java/financialtransactions/Reminder.java
index c621e72579..7171834e31 100644
--- a/src/main/java/financialtransactions/Reminder.java
+++ b/src/main/java/financialtransactions/Reminder.java
@@ -2,8 +2,6 @@
import customexceptions.CategoryNotFoundException;
-import java.util.EnumSet;
-
public class Reminder extends Transaction {
public enum Category {
INSTALLMENT, CREDITCARD, UTILITIES
From e9ead8974b1ca8cc2e41e419389dc5f102518fea Mon Sep 17 00:00:00 2001
From: Kishen271828
Date: Thu, 4 Apr 2024 22:08:45 +0800
Subject: [PATCH 135/208] Update UG based on v1.0 features
---
docs/UserGuide.md | 118 ++++++++++++++++++++++++++++++++++++++--------
1 file changed, 98 insertions(+), 20 deletions(-)
diff --git a/docs/UserGuide.md b/docs/UserGuide.md
index abd9fbe891..493172288d 100644
--- a/docs/UserGuide.md
+++ b/docs/UserGuide.md
@@ -1,42 +1,120 @@
-# User Guide
+# FinTrack User Guide
## Introduction
-{Give a product intro}
+FinTrack is a desktop app designed for individuals who want to manage their finances using a Command Line Interface (CLI). FinTrack offers a convenient way for users to track their income, expenses, and budgets through typed commands. With FinTrack, users can easily add income and expense transactions, categorize them, set budgets, and generate reports to gain valuable insights into their financial activities.
## Quick Start
-{Give steps to get started quickly}
-
1. Ensure that you have Java 11 or above installed.
-1. Down the latest version of `Duke` from [here](http://link.to/duke).
+2. Download the latest version of `FinTrack.jar` from [here].
+3. Copy the file to the folder you want to use as the home folder for your FinTrack app.
+4. Open a command terminal, navigate to the folder containing the jar file, and run the command `java -jar FinTrack.jar` to run the application.
+5. Upon starting FinTrack, you will first be prompted to type the username and password. The username is **Bob** and the password is **password**.
+
+## Features
+
+### Logging in into user session:
+
+- Securely logs the user into their Finance Manager session.
+
+### Viewing Help: `help`
+
+- Shows a message explaining how to access the help page or list of commands.
+
+Format: `help`
+
+### View Transaction History: view-history
+
+- Access getter for all the last n transactions made.
+
+Format: `view-history n/NUM`
+
+Example: `view-history n/20`
+
+### Add Inflow: add-inflow
+
+- Adds a new inflow of money to your financial records.
+- Date input is in DD/MM/YYYY format. Time input is 24-hour format.
+
+Format: `add-inflow n/NAME a/AMOUNT d/DATE t/TIME c/CATEGORY`
+
+Example: `add-inflow n/Salary a/5000 d/21/02/2024 t/1700 c/job`
+
+### Delete Inflow: delete-inflow
+
+- Checks for and deletes existing entry of inflow from financial record.
+- Before deleting, the list of inflows along with their indices can be viewed using the `view-history` command.
-## Features
+Format: `delete-source i/INDEX`
-{Give detailed description of each feature}
+Example: `delete-inflow i/2`
-### Adding a todo: `todo`
-Adds a new item to the list of todo items.
+### Add Outflow: add-outflow
-Format: `todo n/TODO_NAME d/DEADLINE`
+- Adds a new outflow of money to your financial records.
+- Date input is in DD/MM/YYYY format. Time input is 24-hour format.
-* The `DEADLINE` can be in a natural language format.
-* The `TODO_NAME` cannot contain punctuation.
+Format: `add-outflow n/NAME a/AMOUNT d/DATE t/TIME c/CATEGORY`
-Example of usage:
+Example: `add-outflow n/John a/100 d/19/02/2024 t/1600 c/entertainment`
-`todo n/Write the rest of the User Guide d/next week`
+### Delete Outflow: delete-outflow
-`todo n/Refactor the User Guide to remove passive voice d/13/04/2020`
+- Checks for and deletes existing entry of outflow from financial record.
+- Before deleting, the list of outflows along with their indices can be viewed using the `view-history` command.
+
+Format: `delete-outflow i/INDEX`
+
+Example: `delete-outflow i/5`
+
+### Edit Inflow: edit-inflow
+
+- Edits an existing entry of inflow from your financial records.
+- Before editing, the list of inflows along with their indices can be viewed using the `view-history` command.
+- Date input is in DD/MM/YYYY format. Time input is 24-hour format.
+- Input the index you want to edit and provide the details you want to update for the inflow.
+
+Format: `edit-inflow i/INDEX n/NAME a/AMOUNT d/DATE t/TIME c/CATEGORY`
+
+Example: `edit-inflow i/7 n/Salary a/5000 d/21/02/2024 t/1700 c/job`
+
+### Edit Outflow: edit-outflow
+
+- Edits an existing entry of outflow from your financial records.
+- Before editing, the list of outflows along with their indices can be viewed using the `view-history` command.
+- Date input is in DD/MM/YYYY format. Time input is 24-hour format.
+- Input the index you want to edit and provide the details you want to edit for the outflow.
+
+Format: `edit-outflow i/INDEX n/NAME a/AMOUNT d/DATE t/TIME c/CATEGORY`
+
+Example: `edit-outflow i/6 n/John a/100 d/19/02/2024 t/1600 c/entertainment`
+
+
+### Exiting the Program: `quit`
+
+- Quits from the FinTrack app.
+
+Format: `quit`
+
+### Saving the Data
+
+FinTrack data is saved in the hard disk automatically when the user exits the program. There is no need to save the data manually.
## FAQ
-**Q**: How do I transfer my data to another computer?
+**Q**: How do I transfer my data to another Computer?
-**A**: {your answer here}
+**A**: Install the app on the other computer and overwrite the empty data file it creates with the file that contains the data of your previous FinTrack home folder.
## Command Summary
-{Give a 'cheat sheet' of commands here}
-
-* Add todo `todo n/TODO_NAME d/DEADLINE`
+* View Help: `help`
+* View Transaction History: `view-history n/NUM`
+* Add Inflow: `add-inflow n/NAME a/AMOUNT d/DATE t/TIME c/CATEGORY`
+* Delete Inflow: `delete-inflow i/INDEX`
+* Edit Inflow: `edit-inflow i/INDEX n/NAME a/AMOUNT d/DATE t/TIME c/CATEGORY`
+* Add Outflow: `add-outflow n/NAME a/AMOUNT d/DATE t/TIME c/CATEGORY`
+* Delete Outflow: `delete-outflow i/INDEX`
+* Edit Outflow: `edit-outflow i/INDEX n/NAME a/AMOUNT d/DATE t/TIME c/CATEGORY`
+* Exit Program: `quit`
From 2c754e0f47ef159ab0929df5f24f3d5c01fbfffe Mon Sep 17 00:00:00 2001
From: Kishen271828
Date: Thu, 4 Apr 2024 22:13:15 +0800
Subject: [PATCH 136/208] Change category for example
---
docs/UserGuide.md | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/docs/UserGuide.md b/docs/UserGuide.md
index 493172288d..3dbcc77d1c 100644
--- a/docs/UserGuide.md
+++ b/docs/UserGuide.md
@@ -39,7 +39,7 @@ Example: `view-history n/20`
Format: `add-inflow n/NAME a/AMOUNT d/DATE t/TIME c/CATEGORY`
-Example: `add-inflow n/Salary a/5000 d/21/02/2024 t/1700 c/job`
+Example: `add-inflow n/Salary a/5000 d/21/02/2024 t/1700 c/income`
### Delete Inflow: delete-inflow
@@ -57,7 +57,7 @@ Example: `delete-inflow i/2`
Format: `add-outflow n/NAME a/AMOUNT d/DATE t/TIME c/CATEGORY`
-Example: `add-outflow n/John a/100 d/19/02/2024 t/1600 c/entertainment`
+Example: `add-outflow n/John a/100 d/19/02/2024 t/1600 c/treat`
### Delete Outflow: delete-outflow
@@ -77,7 +77,7 @@ Example: `delete-outflow i/5`
Format: `edit-inflow i/INDEX n/NAME a/AMOUNT d/DATE t/TIME c/CATEGORY`
-Example: `edit-inflow i/7 n/Salary a/5000 d/21/02/2024 t/1700 c/job`
+Example: `edit-inflow i/7 n/Salary a/5000 d/21/02/2024 t/1700 c/income`
### Edit Outflow: edit-outflow
@@ -88,7 +88,7 @@ Example: `edit-inflow i/7 n/Salary a/5000 d/21/02/2024 t/1700 c/job`
Format: `edit-outflow i/INDEX n/NAME a/AMOUNT d/DATE t/TIME c/CATEGORY`
-Example: `edit-outflow i/6 n/John a/100 d/19/02/2024 t/1600 c/entertainment`
+Example: `edit-outflow i/6 n/John a/100 d/19/02/2024 t/1600 c/food`
### Exiting the Program: `quit`
From fbe8f59d67c6c72e67d346381687e1a45d1e3453 Mon Sep 17 00:00:00 2001
From: Chong Xern <104547209+ChongXern@users.noreply.github.com>
Date: Thu, 4 Apr 2024 22:24:34 +0800
Subject: [PATCH 137/208] Update UserGuide with undo, bar chart and timer
---
docs/UserGuide.md | 28 ++++++++++++++++++++++++----
1 file changed, 24 insertions(+), 4 deletions(-)
diff --git a/docs/UserGuide.md b/docs/UserGuide.md
index 3dbcc77d1c..66ffa0c93b 100644
--- a/docs/UserGuide.md
+++ b/docs/UserGuide.md
@@ -27,11 +27,15 @@ Format: `help`
### View Transaction History: view-history
- Access getter for all the last n transactions made.
+- Optional `w/chart` can be added at the end to visualise transaction history with bar charts.
+- `all` tag allows the user to view all transactions made.
-Format: `view-history n/NUM`
-
-Example: `view-history n/20`
+Format: `view-history n/NUM [w/CHART]`
+Examples:
+- `view-history n/20 w/chart`
+- `view-history all`
+
### Add Inflow: add-inflow
- Adds a new inflow of money to your financial records.
@@ -90,6 +94,17 @@ Format: `edit-outflow i/INDEX n/NAME a/AMOUNT d/DATE t/TIME c/CATEGORY`
Example: `edit-outflow i/6 n/John a/100 d/19/02/2024 t/1600 c/food`
+### Undo last action: `undo`
+- This command will undo the last command inputted by the user.
+- Only applicable for the commands:
+ - `add-inflow`
+ - `add-outflow`
+ - `add-reminder`
+ - `delete-inflow`
+ - `delete-outflow`
+ - `delete-reminder`
+
+Format: `undo`
### Exiting the Program: `quit`
@@ -101,6 +116,10 @@ Format: `quit`
FinTrack data is saved in the hard disk automatically when the user exits the program. There is no need to save the data manually.
+### Inactivity Timer
+
+FinTrack allows a maximum of 3 minutes of inactivity on the software, then it will shut down by itself. However, a grace period of 30 seconds is offered to the user, whereby the user is asked whether there will be any further activity or not.
+
## FAQ
**Q**: How do I transfer my data to another Computer?
@@ -110,7 +129,7 @@ FinTrack data is saved in the hard disk automatically when the user exits the pr
## Command Summary
* View Help: `help`
-* View Transaction History: `view-history n/NUM`
+* View Transaction History: `view-history n/NUM [w/CHART]`
* Add Inflow: `add-inflow n/NAME a/AMOUNT d/DATE t/TIME c/CATEGORY`
* Delete Inflow: `delete-inflow i/INDEX`
* Edit Inflow: `edit-inflow i/INDEX n/NAME a/AMOUNT d/DATE t/TIME c/CATEGORY`
@@ -118,3 +137,4 @@ FinTrack data is saved in the hard disk automatically when the user exits the pr
* Delete Outflow: `delete-outflow i/INDEX`
* Edit Outflow: `edit-outflow i/INDEX n/NAME a/AMOUNT d/DATE t/TIME c/CATEGORY`
* Exit Program: `quit`
+* Undo: `undo`
From 49e0a3acdace9bd3159cfd929aff222ac54bc4d7 Mon Sep 17 00:00:00 2001
From: dylansiew <88567790+dylansiew@users.noreply.github.com>
Date: Thu, 4 Apr 2024 22:25:51 +0800
Subject: [PATCH 138/208] removing all print statements
---
src/main/java/command/AddInflowCommand.java | 8 ++---
src/main/java/command/AddOutflowCommand.java | 8 ++---
src/main/java/command/AddReminderCommand.java | 8 ++---
src/main/java/command/UndoCommand.java | 13 +++----
.../InactivityTimeoutException.java | 1 +
src/main/java/financeproject/Main.java | 13 +++++--
.../financialtransactions/Transaction.java | 5 ---
.../TransactionList.java | 11 +++---
.../TransactionManager.java | 34 ++++++++-----------
src/main/java/storage/BarChart.java | 10 +++---
src/main/java/storage/Storage.java | 22 +++++-------
src/main/java/template/BaseDate.java | 11 +++---
src/main/java/user/InactivityTimer.java | 1 -
.../java/command/AddInflowCommandTest.java | 9 ++++-
.../java/command/AddOutflowCommandTest.java | 9 ++++-
15 files changed, 80 insertions(+), 83 deletions(-)
diff --git a/src/main/java/command/AddInflowCommand.java b/src/main/java/command/AddInflowCommand.java
index a6a8f977a8..8f08ebca7d 100644
--- a/src/main/java/command/AddInflowCommand.java
+++ b/src/main/java/command/AddInflowCommand.java
@@ -6,13 +6,9 @@
public class AddInflowCommand extends BaseCommand {
- public AddInflowCommand(String[] commandParts) {
+ public AddInflowCommand(String[] commandParts) throws CategoryNotFoundException{
super(false, commandParts);
- try {
- createInflow();
- } catch (CategoryNotFoundException e) {
- System.out.println(e.getMessage());
- }
+ createInflow();
}
private void createInflow() throws CategoryNotFoundException {
diff --git a/src/main/java/command/AddOutflowCommand.java b/src/main/java/command/AddOutflowCommand.java
index d8c639bc5d..281464af79 100644
--- a/src/main/java/command/AddOutflowCommand.java
+++ b/src/main/java/command/AddOutflowCommand.java
@@ -6,13 +6,9 @@
public class AddOutflowCommand extends BaseCommand {
- public AddOutflowCommand(String[] commandParts) {
+ public AddOutflowCommand(String[] commandParts) throws CategoryNotFoundException{
super(false, commandParts);
- try {
- createOutflow();
- } catch (CategoryNotFoundException e) {
- System.out.println(e.getMessage());
- }
+ createOutflow();
}
private void createOutflow() throws CategoryNotFoundException {
diff --git a/src/main/java/command/AddReminderCommand.java b/src/main/java/command/AddReminderCommand.java
index 7daa2d596b..c207d88f70 100644
--- a/src/main/java/command/AddReminderCommand.java
+++ b/src/main/java/command/AddReminderCommand.java
@@ -5,13 +5,9 @@
import financialtransactions.TransactionManager;
public class AddReminderCommand extends BaseCommand {
- public AddReminderCommand(String[] commandParts) {
+ public AddReminderCommand(String[] commandParts) throws CategoryNotFoundException{
super(false, commandParts);
- try {
- createReminder();
- } catch (CategoryNotFoundException e) {
- System.out.println(e.getMessage());
- }
+ createReminder();
}
private void createReminder() throws CategoryNotFoundException {
diff --git a/src/main/java/command/UndoCommand.java b/src/main/java/command/UndoCommand.java
index 7b54f9a48e..75ad428cb4 100644
--- a/src/main/java/command/UndoCommand.java
+++ b/src/main/java/command/UndoCommand.java
@@ -38,30 +38,27 @@ public void setReminder(Reminder reminder) {
public String execute(TransactionManager manager) throws Exception {
if (!timer.canUndo()) {
- System.out.println("Sorry, no longer able to undo the last action as 10 seconds have passed.");
+ return "Sorry, no longer able to undo the last action as 10 seconds have passed.";
}
if (commandParts == null) {
- System.out.println("Sorry, there is no action to undo.");
+ return "Sorry, there is no action to undo.";
}
switch (action) {
case "delete-inflow":
canUndo = true;
int inflowIndex = Integer.parseInt(commandParts[1].substring(2));
Inflow inflowToRemove = manager.getNthInflowFromList(inflowIndex);
- manager.addTransaction(inflowToRemove);
- break;
+ return manager.addTransaction(inflowToRemove);
case "delete-outflow":
canUndo = true;
int outflowIndex = Integer.parseInt(commandParts[1].substring(2));
Outflow outflowToRemove = manager.getNthOutflowFromList(outflowIndex);
- manager.addTransaction(outflowToRemove);
- break;
+ return manager.addTransaction(outflowToRemove);
case "delete-reminder":
canUndo = true;
int reminderIndex = Integer.parseInt(commandParts[1].substring(2));
Reminder reminderToRemove = manager.getNthReminderFromList(reminderIndex);
- manager.addTransaction(reminderToRemove);
- break;
+ return manager.addTransaction(reminderToRemove);
case "add-inflow":
canUndo = true;
manager.removeTransaction(inflow);
diff --git a/src/main/java/customexceptions/InactivityTimeoutException.java b/src/main/java/customexceptions/InactivityTimeoutException.java
index 0efd0b8162..324502cf84 100644
--- a/src/main/java/customexceptions/InactivityTimeoutException.java
+++ b/src/main/java/customexceptions/InactivityTimeoutException.java
@@ -5,6 +5,7 @@ public class InactivityTimeoutException extends Exception {
private boolean isGracePeriod = false; //Returns true if system is past 2.5 min, false otherwise
public InactivityTimeoutException(boolean isTimeOut, boolean isGracePeriod) {
+ super("Session has timed out");
this.isTimeOut = isTimeOut;
this.isGracePeriod = isGracePeriod;
}
diff --git a/src/main/java/financeproject/Main.java b/src/main/java/financeproject/Main.java
index 4783f11a98..e1eac313de 100644
--- a/src/main/java/financeproject/Main.java
+++ b/src/main/java/financeproject/Main.java
@@ -1,6 +1,7 @@
package financeproject;
import command.BaseCommand;
+import customexceptions.CategoryNotFoundException;
import customexceptions.ExceededAttemptsException;
import customexceptions.InactivityTimeoutException;
import customexceptions.IncompletePromptException;
@@ -38,11 +39,18 @@ public static void main(String[] args) throws SecurityException {
ui.printMessage(e.getMessage());
return;
}
- TransactionManager manager = storage.loadFile(user.getUsername());
+ TransactionManager manager;
+ try{
+ manager = storage.loadFile(user.getUsername());
+ } catch (CategoryNotFoundException e){
+ ui.printMessage(e.getMessage());
+ return;
+ }
ui.printMessage(manager.generateQuickReport());
// Main program flow
do {
+ ui.printMessage("How can we help you today? \n Enter 'help' to see commands");
response = ui.readInput();
try {
baseCommand = parser.parseCommand(response);
@@ -55,11 +63,12 @@ public static void main(String[] args) throws SecurityException {
ui.printMessage("Uh-oh, something went wrong: " + e.getMessage());
}
- storage.saveFile(user.getUsername(), manager);
+ ui.printMessage(storage.saveFile(user.getUsername(), manager));
try {
inactivityTimer.checkTimeElapsed();
} catch (InactivityTimeoutException e) {
+ ui.printMessage(e.getMessage());
if (e.isTimeOut()) {
assert baseCommand != null;
baseCommand.setIsExit(true);
diff --git a/src/main/java/financialtransactions/Transaction.java b/src/main/java/financialtransactions/Transaction.java
index cd81958e80..6e5183fc07 100644
--- a/src/main/java/financialtransactions/Transaction.java
+++ b/src/main/java/financialtransactions/Transaction.java
@@ -15,11 +15,6 @@ public abstract class Transaction {
public Transaction(String name, double amount, String date) {
assert name != null : "NULL name detected";
- if (name.length() > NAME_MAX_LEN) {
- System.out.println("Sorry, the description inputted exceeds the maximum permeable length. " +
- "Please try again.");
- return;
- }
this.name = name;
this.amount = amount;
if (date == null){
diff --git a/src/main/java/financialtransactions/TransactionList.java b/src/main/java/financialtransactions/TransactionList.java
index d9300b1b43..de4baf77be 100644
--- a/src/main/java/financialtransactions/TransactionList.java
+++ b/src/main/java/financialtransactions/TransactionList.java
@@ -1,5 +1,7 @@
package financialtransactions;
+import userinterface.UI;
+
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Comparator;
@@ -73,12 +75,13 @@ public String toSave() {
return baseString.toString();
}
//@@author
- protected void printTransactionsSafeInfo() {
+ protected void printTransactionsSaveInfo(UI ui) {
int index = 1;
+ String transactionString;
for (T transaction : transactionList) {
- System.out.print(index++);
- System.out.print(" " + transaction.getName() + " | " + transaction.getCategory());
- System.out.println(" | " + transaction.getClass());
+ transactionString = String.format("%d\t %s | %s | %s", index++, transaction.getName(),
+ transaction.getCategory(), transaction.getClass());
+ ui.printMessage(transactionString);
}
}
diff --git a/src/main/java/financialtransactions/TransactionManager.java b/src/main/java/financialtransactions/TransactionManager.java
index 05bf6fef85..b4c102cd36 100644
--- a/src/main/java/financialtransactions/TransactionManager.java
+++ b/src/main/java/financialtransactions/TransactionManager.java
@@ -24,52 +24,48 @@ public void setBudget(double budget) {
this.budget = budget;
}
- public void addTransaction(Transaction> transaction) {
+ public String addTransaction(Transaction> transaction) {
transactionList.addTransaction(transaction);
// transactionList.sortList();
if (transaction instanceof Inflow) {
Inflow inflow = (Inflow) transaction;
transactionList.setTransactionsType("Inflow");
inflows.addTransaction(inflow);
- return;
- }
- if (transaction instanceof Outflow) {
+ return String.format("Added: %s", inflow.toString());
+ } else if (transaction instanceof Outflow) {
Outflow outflow = (Outflow) transaction;
transactionList.setTransactionsType("Outflow");
outflows.addTransaction(outflow);
- return;
- }
- if (transaction instanceof Reminder) {
+ return String.format("Added: %s", outflow.toString());
+ } else if (transaction instanceof Reminder) {
Reminder reminder = (Reminder) transaction;
transactionList.setTransactionsType("Reminder");
reminders.addTransaction(reminder);
- return;
+ return String.format("Added: %s", reminder.toString());
}
- System.out.println("Invalid transaction type.");
+ return "Invalid transaction type.";
}
- public void removeTransaction(Transaction> transaction) {
+ public String removeTransaction(Transaction> transaction) {
int index = transactionList.getIndexOfParticularTransaction(transaction);
transactionList.removeTransactionIndex(index);
if (transaction instanceof Inflow) {
Inflow inflow = (Inflow) transaction;
int inflowIndex = inflows.getIndexOfParticularTransaction(inflow);
inflows.removeTransactionIndex(inflowIndex);
- return;
- }
- if (transaction instanceof Outflow) {
+ return String.format("Removed: %s", inflow.toString());
+ } else if (transaction instanceof Outflow) {
Outflow outflow = (Outflow) transaction;
int outflowIndex = outflows.getIndexOfParticularTransaction(outflow);
outflows.removeTransactionIndex(outflowIndex);
- return;
- }
- if (transaction instanceof Reminder) {
+ return String.format("Removed: %s", outflow.toString());
+ } else if (transaction instanceof Reminder) {
Reminder reminder = (Reminder) transaction;
int reminderIndex = reminders.getIndexOfParticularTransaction(reminder);
reminders.removeTransactionIndex(reminderIndex);
- return;
+ return String.format("Removed: %s", reminder.toString());
}
- System.out.println("Invalid transaction type.");
+ return "Invalid transaction type.";
}
public Inflow removeInflow(int index) throws Exception {
@@ -168,7 +164,7 @@ public String showLastNTransactions(int n, boolean isIncludeBarChart) throws Exc
if (isIncludeBarChart) {
BarChart> barChart = new BarChart<>(transactionList);
- barChart.printBarChart();
+ returnedText = barChart.generateBarChart() + returnedText;
}
return returnedText;
diff --git a/src/main/java/storage/BarChart.java b/src/main/java/storage/BarChart.java
index c7ad1b2fe9..bce17c83c7 100644
--- a/src/main/java/storage/BarChart.java
+++ b/src/main/java/storage/BarChart.java
@@ -31,8 +31,9 @@ public void computeTransactionFrequencies() throws Exception {
}
}
- public void printBarChart() throws Exception {
+ public String generateBarChart() throws Exception {
computeTransactionFrequencies();
+ String barChartString = "";
for (Map.Entry entry : categoryFrequencies.entrySet()) {
String category = entry.getKey();
Integer frequency = entry.getValue();
@@ -43,14 +44,15 @@ public void printBarChart() throws Exception {
int barSize = (int)(percentage * TOTAL_BAR_SIZE);
System.out.print(category);
for (int i = 0; i < LEGEND_SIZE - category.length(); i++) {
- System.out.print(" ");
+ barChartString += " ";
}
System.out.print(": ");
for (int i = 0; i < barSize; i++) {
- System.out.print("|");
+ barChartString += "|";
}
percentage = Math.round(percentage * 10000.0) / 100.0;
- System.out.println(" " + percentage + "%");
+ barChartString += (" " + percentage + "%\n");
}
+ return barChartString;
}
}
diff --git a/src/main/java/storage/Storage.java b/src/main/java/storage/Storage.java
index 4d2cb994b8..457e1481f4 100644
--- a/src/main/java/storage/Storage.java
+++ b/src/main/java/storage/Storage.java
@@ -23,14 +23,10 @@ public Storage(String filePath) {
this.filePath = filePath;
}
- public void addNewUser(String username, String password) {
- try {
- FileWriter fw = new FileWriter(filePath + "/passwords.txt", true);
- fw.write(username + "|" + password + "\n");
- fw.close();
- } catch (IOException e) {
- System.out.println("Could not add user");
- }
+ public void addNewUser(String username, String password) throws IOException{
+ FileWriter fw = new FileWriter(filePath + "/passwords.txt", true);
+ fw.write(username + "|" + password + "\n");
+ fw.close();
}
public BaseUser loadMockUser(){
@@ -50,12 +46,11 @@ public BaseUser loadUser(String username) throws UserNotFoundException {
throw new UserNotFoundException();
} catch (FileNotFoundException e) {
createFileDir();
- System.out.println("File is not found, please try again.");
return null;
}
}
- public TransactionManager loadFile(String username) {
+ public TransactionManager loadFile(String username) throws CategoryNotFoundException{
File f = new File(filePath + String.format("/%s.txt", username));
TransactionManager manager = new TransactionManager();
try {
@@ -86,8 +81,6 @@ public TransactionManager loadFile(String username) {
sc.close();
} catch (FileNotFoundException e) {
createFileDir();
- } catch (CategoryNotFoundException e) {
- System.out.println(e.getMessage());
}
return manager;
}
@@ -97,13 +90,14 @@ private void createFileDir() {
f.mkdir();
}
- public void saveFile(String username, TransactionManager tm) {
+ public String saveFile(String username, TransactionManager tm) {
try {
FileWriter fw = new FileWriter(filePath + String.format("/%s.txt", username));
fw.write(tm.toSave());
fw.close();
+ return "File saved...";
} catch (IOException e) {
- System.out.println("Unable to save tasks!");
+ return "Unable to save tasks!";
}
}
}
diff --git a/src/main/java/template/BaseDate.java b/src/main/java/template/BaseDate.java
index 010ccd98ab..62c925ba0c 100644
--- a/src/main/java/template/BaseDate.java
+++ b/src/main/java/template/BaseDate.java
@@ -28,26 +28,25 @@ public class BaseDate {
private static final ArrayList dateTimeFormats = dateTimeVary();
private LocalDateTime dateTime = null;
- private final String defaultTime = " 0000";
public BaseDate(String args) {
args = args.strip();
if (!args.contains(" ")) {
+ String defaultTime = " 0000";
args = args + defaultTime;
}
for (String format : dateTimeFormats) {
try {
formatter = DateTimeFormatter.ofPattern(format);
dateTime = LocalDateTime.parse(args, formatter);
- } catch (DateTimeParseException e) {
- continue;
+ } catch (DateTimeParseException ignored) {
}
}
}
private static ArrayList dateTimeVary() {
- ArrayList varyList = new ArrayList();
+ ArrayList varyList = new ArrayList<>();
for (String dateFormat : dateFormats) {
for (String timeFormat : timeFormats) {
varyList.add(String.format("%s %s", dateFormat, timeFormat));
@@ -64,14 +63,14 @@ public String toString() {
}
public boolean equals(BaseDate otherDate) {
- if (otherDate != null) {
+ if (otherDate != null && this.dateTime != null) {
return this.dateTime.toLocalDate().equals(otherDate.dateTime.toLocalDate());
}
return false;
}
public boolean isBefore(BaseDate otherDate) {
- if (otherDate != null) {
+ if (otherDate != null && this.dateTime != null) {
return this.dateTime.isBefore(otherDate.dateTime);
}
return false;
diff --git a/src/main/java/user/InactivityTimer.java b/src/main/java/user/InactivityTimer.java
index 9345986d00..2ab4c98235 100644
--- a/src/main/java/user/InactivityTimer.java
+++ b/src/main/java/user/InactivityTimer.java
@@ -20,7 +20,6 @@ public void resetTimer() {
public void checkTimeElapsed() throws InactivityTimeoutException {
long timeDifference = System.currentTimeMillis() - startTime;
if (timeDifference >= INACTIVITY_TIME) {
- System.out.println("Sorry, your session has ended. Please log in again.");
throw new InactivityTimeoutException(true, false);
} else if (timeDifference >= INACTIVITY_TIME - GRACE_TIME) {
throw new InactivityTimeoutException(false, true);
diff --git a/src/test/java/command/AddInflowCommandTest.java b/src/test/java/command/AddInflowCommandTest.java
index a487eeee13..82563179fd 100644
--- a/src/test/java/command/AddInflowCommandTest.java
+++ b/src/test/java/command/AddInflowCommandTest.java
@@ -11,7 +11,14 @@ public class AddInflowCommandTest {
public void testAddInflow() {
String arg = "add-inflow n/Salary a/400.00 d/23/05/2022 t/1900 c/income";
String[] splitCommand = arg.split(" ");
- AddInflowCommand command = new AddInflowCommand(splitCommand);
+ AddInflowCommand command;
+ try{
+ command = new AddInflowCommand(splitCommand);
+ } catch (Exception e){
+ System.out.println(e.getMessage());
+ return;
+ }
+
TransactionManager manager = new TransactionManager();
assertEquals(command.execute(manager), "Ok. Added inflow");
diff --git a/src/test/java/command/AddOutflowCommandTest.java b/src/test/java/command/AddOutflowCommandTest.java
index 05299ae792..318106661f 100644
--- a/src/test/java/command/AddOutflowCommandTest.java
+++ b/src/test/java/command/AddOutflowCommandTest.java
@@ -11,7 +11,14 @@ public class AddOutflowCommandTest{
public void testAddOutflowTest(){
String arg = "add-outflow n/Rent a/1500.00 d/23/06/2023 t/1800 c/rent";
String[] splitCommand = arg.split(" ");
- AddOutflowCommand command = new AddOutflowCommand(splitCommand);
+ AddOutflowCommand command;
+ try{
+ command = new AddOutflowCommand(splitCommand);
+ } catch (Exception e){
+ System.out.println(e.getMessage());
+ return;
+ }
+
TransactionManager manager = new TransactionManager();
assertEquals(command.execute(manager), "Ok. Added outflow");
From 9fcdf5f3489a9ff18ba5a76087432d119e3280c5 Mon Sep 17 00:00:00 2001
From: Kishen271828
Date: Thu, 4 Apr 2024 22:32:41 +0800
Subject: [PATCH 139/208] Add Category restriction info in UG for transactions
---
docs/UserGuide.md | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/docs/UserGuide.md b/docs/UserGuide.md
index 3dbcc77d1c..d7b118af27 100644
--- a/docs/UserGuide.md
+++ b/docs/UserGuide.md
@@ -24,7 +24,7 @@ FinTrack is a desktop app designed for individuals who want to manage their fina
Format: `help`
-### View Transaction History: view-history
+### View Transaction History: `view-history`
- Access getter for all the last n transactions made.
@@ -32,16 +32,17 @@ Format: `view-history n/NUM`
Example: `view-history n/20`
-### Add Inflow: add-inflow
+### Add Inflow: `add-inflow`
- Adds a new inflow of money to your financial records.
- Date input is in DD/MM/YYYY format. Time input is 24-hour format.
+- Only the following categories are allowed: *INCOME, INVESTMENT, GIFT, LOAN, REFUND, OTHER*
Format: `add-inflow n/NAME a/AMOUNT d/DATE t/TIME c/CATEGORY`
Example: `add-inflow n/Salary a/5000 d/21/02/2024 t/1700 c/income`
-### Delete Inflow: delete-inflow
+### Delete Inflow: `delete-inflow`
- Checks for and deletes existing entry of inflow from financial record.
- Before deleting, the list of inflows along with their indices can be viewed using the `view-history` command.
@@ -50,16 +51,17 @@ Format: `delete-source i/INDEX`
Example: `delete-inflow i/2`
-### Add Outflow: add-outflow
+### Add Outflow: `add-outflow`
- Adds a new outflow of money to your financial records.
- Date input is in DD/MM/YYYY format. Time input is 24-hour format.
+- Only the following categories are allowed: *FOOD, RENT, DEBT, SHOPPING, TREAT, EDUCATION, TAX, OTHER*
Format: `add-outflow n/NAME a/AMOUNT d/DATE t/TIME c/CATEGORY`
Example: `add-outflow n/John a/100 d/19/02/2024 t/1600 c/treat`
-### Delete Outflow: delete-outflow
+### Delete Outflow: `delete-outflow`
- Checks for and deletes existing entry of outflow from financial record.
- Before deleting, the list of outflows along with their indices can be viewed using the `view-history` command.
@@ -68,22 +70,24 @@ Format: `delete-outflow i/INDEX`
Example: `delete-outflow i/5`
-### Edit Inflow: edit-inflow
+### Edit Inflow: `edit-inflow`
- Edits an existing entry of inflow from your financial records.
- Before editing, the list of inflows along with their indices can be viewed using the `view-history` command.
- Date input is in DD/MM/YYYY format. Time input is 24-hour format.
+- Only the following categories are allowed: *INCOME, INVESTMENT, GIFT, LOAN, REFUND, OTHER*
- Input the index you want to edit and provide the details you want to update for the inflow.
Format: `edit-inflow i/INDEX n/NAME a/AMOUNT d/DATE t/TIME c/CATEGORY`
Example: `edit-inflow i/7 n/Salary a/5000 d/21/02/2024 t/1700 c/income`
-### Edit Outflow: edit-outflow
+### Edit Outflow: `edit-outflow`
- Edits an existing entry of outflow from your financial records.
- Before editing, the list of outflows along with their indices can be viewed using the `view-history` command.
- Date input is in DD/MM/YYYY format. Time input is 24-hour format.
+- Only the following categories are allowed: *FOOD, RENT, DEBT, SHOPPING, TREAT, EDUCATION, TAX, OTHER*
- Input the index you want to edit and provide the details you want to edit for the outflow.
Format: `edit-outflow i/INDEX n/NAME a/AMOUNT d/DATE t/TIME c/CATEGORY`
From 2deffa4f9071970a3ad3650380c90e536b5f8e41 Mon Sep 17 00:00:00 2001
From: Kishen271828
Date: Thu, 4 Apr 2024 22:45:16 +0800
Subject: [PATCH 140/208] Update UG for v1.0 features
---
docs/UserGuide.md | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/docs/UserGuide.md b/docs/UserGuide.md
index d7b118af27..1313a65589 100644
--- a/docs/UserGuide.md
+++ b/docs/UserGuide.md
@@ -20,15 +20,16 @@ FinTrack is a desktop app designed for individuals who want to manage their fina
### Viewing Help: `help`
-- Shows a message explaining how to access the help page or list of commands.
+- Shows a message explaining the different commands available and their formats.
Format: `help`
### View Transaction History: `view-history`
-- Access getter for all the last n transactions made.
+- Displays the last n transactions made.
+- `view-history all` command shows all the whole list of transactions.
-Format: `view-history n/NUM`
+Format: `view-history n/NUM` or `view-history all`
Example: `view-history n/20`
From ffa999b675a9a0d1bdef196cd337eb738ef389ad Mon Sep 17 00:00:00 2001
From: dylansiew <88567790+dylansiew@users.noreply.github.com>
Date: Thu, 4 Apr 2024 22:50:33 +0800
Subject: [PATCH 141/208] resolving merge conflicts
---
data/Bob.txt | 5 +++++
src/main/java/financeproject/Main.java | 10 ++--------
src/main/java/storage/Storage.java | 17 +++++++----------
3 files changed, 14 insertions(+), 18 deletions(-)
diff --git a/data/Bob.txt b/data/Bob.txt
index fb1088c65a..eb61939669 100644
--- a/data/Bob.txt
+++ b/data/Bob.txt
@@ -1 +1,6 @@
0.00
+Salary|400.00|May 23 2022 07:00PM|INCOME|I
+Rent|-1500.00|Jun 23 2023 06:00PM|RENT|O
+Stocks|400.00|Oct 24 2024 12:00PM|INVESTMENT|I
+Groceries|-150.00|Jun 23 2023 06:30PM|SHOPPING|O
+Refund|100.00|Jun 23 2023 05:00PM|REFUND|I
diff --git a/src/main/java/financeproject/Main.java b/src/main/java/financeproject/Main.java
index 68a5ab24e3..36718a5820 100644
--- a/src/main/java/financeproject/Main.java
+++ b/src/main/java/financeproject/Main.java
@@ -4,7 +4,6 @@
import customexceptions.ExceededAttemptsException;
import customexceptions.InactivityTimeoutException;
import customexceptions.IncompletePromptException;
-import customexceptions.UserNotFoundExcption;
import financialtransactions.TransactionManager;
import parser.Parser;
import storage.Storage;
@@ -40,17 +39,12 @@ public static void main(String[] args) throws SecurityException {
return;
}
TransactionManager manager;
- try{
- manager = storage.loadFile(user.getUsername());
- } catch (CategoryNotFoundException e){
- ui.printMessage(e.getMessage());
- return;
- }
+ manager = storage.loadFile(user.getUsername());
ui.printMessage(manager.generateQuickReport());
// Main program flow
do {
- ui.printMessage("How can we help you today? \n Enter 'help' to see commands");
+ ui.printMessage("How can we help you today? \nEnter 'help' to see commands");
response = ui.readInput();
try {
baseCommand = parser.parseCommand(response);
diff --git a/src/main/java/storage/Storage.java b/src/main/java/storage/Storage.java
index c25a8f483d..f47e3a0895 100644
--- a/src/main/java/storage/Storage.java
+++ b/src/main/java/storage/Storage.java
@@ -1,5 +1,6 @@
package storage;
+import customexceptions.CategoryNotFoundException;
import financialtransactions.Inflow;
import financialtransactions.Outflow;
import financialtransactions.Reminder;
@@ -12,7 +13,7 @@
import java.io.IOException;
import java.util.Scanner;
-import customexceptions.UserNotFoundExcption;
+import customexceptions.UserNotFoundException;
public class Storage {
private final String filePath;
@@ -33,17 +34,13 @@ public BaseUser loadUser(String username) throws UserNotFoundException {
if (line.startsWith(username)) {
String password = line.split("\\|")[1];
BaseUser newUser = new BaseUser(username, password);
- this.sc.close();
return newUser;
}
}
- this.sc.close();
- throw new UserNotFoundExcption();
+ throw new UserNotFoundException();
} catch (FileNotFoundException e) {
- if (!createFileDir()){
- throw new Exception("Failed to create directory");
- }
- this.sc.close();
+ createFileDir();
+ System.out.println("File is not found, please try again.");
return null;
}
}
@@ -62,7 +59,7 @@ public TransactionManager loadFile(String username) {
Inflow inflow = new Inflow(transactionInfo[0], amount, transactionInfo[2]);
inflow.setCategory(Inflow.Category.valueOf(transactionInfo[3]));
manager.addTransaction(inflow);
- } else if (transactionInfo[4].equals("O")){
+ } else if (transactionInfo[4].equals("O")) {
Outflow outflow = new Outflow(transactionInfo[0], -amount, transactionInfo[2]);
outflow.setCategory(Outflow.Category.valueOf(transactionInfo[3]));
manager.addTransaction(outflow);
@@ -74,7 +71,7 @@ public TransactionManager loadFile(String username) {
}
} catch (FileNotFoundException e) {
createFileDir();
- }
+ } catch (CategoryNotFoundException ignored){}
sc.close();
return manager;
}
From d2c7392622c8856e74e56aa76ada5996b28e372e Mon Sep 17 00:00:00 2001
From: chowy
Date: Thu, 4 Apr 2024 23:25:02 +0800
Subject: [PATCH 142/208] Updated UG
---
docs/UserGuide.md | 59 +++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 57 insertions(+), 2 deletions(-)
diff --git a/docs/UserGuide.md b/docs/UserGuide.md
index 24b4c5c097..492323a102 100644
--- a/docs/UserGuide.md
+++ b/docs/UserGuide.md
@@ -51,7 +51,7 @@ Example: `add-inflow n/Salary a/5000 d/21/02/2024 t/1700 c/income`
- Checks for and deletes existing entry of inflow from financial record.
- Before deleting, the list of inflows along with their indices can be viewed using the `view-history` command.
-Format: `delete-source i/INDEX`
+Format: `delete-inflow i/INDEX`
Example: `delete-inflow i/2`
@@ -74,6 +74,26 @@ Format: `delete-outflow i/INDEX`
Example: `delete-outflow i/5`
+### Add Reminder: `add-reminder`
+
+- Adds a new reminder of upcoming payment to your financial records.
+- Date input is in DD/MM/YYYY format. Time input is 24-hour format.
+- Take note that the date entered must be in the future.
+- Only the following categories are allowed: *INSTALLMENT, CREDITCARD, UTILITIES*
+
+Format: `add-reminder n/NAME a/AMOUNT d/DATE t/TIME c/CATEGORY`
+
+Example: `add-reminder n/water bills a/35 d/21/06/2024 t/1200 c/UTILITIES`
+
+### Delete Reminder: `delete-reminder`
+
+- Checks for and deletes existing entry of reminder from financial record.
+- Before deleting, the list of reminders along with their indices can be viewed using the `view-history` command.
+
+Format: `delete-reminder i/INDEX`
+
+Example: `delete-reminder i/5`
+
### Edit Inflow: `edit-inflow`
- Edits an existing entry of inflow from your financial records.
@@ -98,6 +118,18 @@ Format: `edit-outflow i/INDEX n/NAME a/AMOUNT d/DATE t/TIME c/CATEGORY`
Example: `edit-outflow i/6 n/John a/100 d/19/02/2024 t/1600 c/food`
+### Edit Reminder: `edit-reminder`
+
+- Edits an existing entry of reminder in your financial records.
+- Before editing, the list of reminders along with their indices can be viewed using the `view-history` command.
+- Date input is in DD/MM/YYYY format. Time input is 24-hour format.
+- Only the following categories are allowed: *INSTALLMENT, CREDITCARD, UTILITIES*
+- Input the index you want to edit and provide the details you want to edit for the outflow.
+
+Format: `edit-reminder i/INDEX n/NAME a/AMOUNT d/DATE t/TIME c/CATEGORY`
+
+Example: `edit-reminder i/2 n/water bills a/35 d/21/06/2024 t/1200 c/UTILITIES`
+
### Undo last action: `undo`
- This command will undo the last command inputted by the user.
- Only applicable for the commands:
@@ -110,6 +142,27 @@ Example: `edit-outflow i/6 n/John a/100 d/19/02/2024 t/1600 c/food`
Format: `undo`
+### Set a budget `set-budget`
+- Sets a per-month budget from a default of $0.00.
+
+Format: `set-budget a/AMOUNT`
+
+Examples of usage:
+
+`set-budget a/2000.00`
+
+### Generating a report `generate-report`
+- Generates a report of a certain month.
+- Take note that MMM is the 3-letter abbreviation of the month in all-caps.
+
+Format: `generate-report m/MMM y/YYYY`
+
+Examples of usage:
+
+`generate-report m/JUN y/2023`
+
+`generate-report m/MAR y/2024`
+
### Exiting the Program: `quit`
- Quits from the FinTrack app.
@@ -140,5 +193,7 @@ FinTrack allows a maximum of 3 minutes of inactivity on the software, then it wi
* Add Outflow: `add-outflow n/NAME a/AMOUNT d/DATE t/TIME c/CATEGORY`
* Delete Outflow: `delete-outflow i/INDEX`
* Edit Outflow: `edit-outflow i/INDEX n/NAME a/AMOUNT d/DATE t/TIME c/CATEGORY`
-* Exit Program: `quit`
* Undo: `undo`
+* Set budget: `set-budget a/AMOUNT`
+* Generate report: `generate-report m/MMM y/YYYY`
+* Exit Program: `quit`
\ No newline at end of file
From ae4d45dcd1b48617ddc6982c4251534b6e19dce2 Mon Sep 17 00:00:00 2001
From: Dylan Siew <88567790+dylansiew@users.noreply.github.com>
Date: Thu, 4 Apr 2024 23:38:34 +0800
Subject: [PATCH 143/208] fixing user error
---
src/main/java/financeproject/Main.java | 11 ++++-------
src/main/java/storage/Storage.java | 4 ++++
2 files changed, 8 insertions(+), 7 deletions(-)
diff --git a/src/main/java/financeproject/Main.java b/src/main/java/financeproject/Main.java
index 1a39a126fd..4950d06572 100644
--- a/src/main/java/financeproject/Main.java
+++ b/src/main/java/financeproject/Main.java
@@ -31,15 +31,12 @@ public static void main(String[] args) throws SecurityException {
try {
ui.printMessage("Username: ");
response = ui.readInput();
- user = storage.loadUser(response);
+ //user = storage.loadUser(response);
+ user = storage.loadMockUser();
Authentication.authenticateUser(user, ui);
- } catch (UserNotFoundException | ExceededAttemptsException e) {
- ui.printMessage(e.getMessage());
- return;
- }
- if (user != null) {
ui.printMessage("User has been authenticated. Starting program...");
- } else {
+ } catch (ExceededAttemptsException e) {
+ ui.printMessage(e.getMessage());
return;
}
diff --git a/src/main/java/storage/Storage.java b/src/main/java/storage/Storage.java
index 3752d6540a..fb62e872e7 100644
--- a/src/main/java/storage/Storage.java
+++ b/src/main/java/storage/Storage.java
@@ -33,6 +33,10 @@ public void addNewUser(String username, String password) {
}
}
+ public BaseUser loadMockUser(){
+ return new BaseUser("Bob", "password");
+ }
+
public BaseUser loadUser(String username) throws UserNotFoundException {
File f = new File(filePath + "/passwords.txt");
try {
From e9290509492442409b0c60500962f1bc560ac6aa Mon Sep 17 00:00:00 2001
From: Dylan Siew <88567790+dylansiew@users.noreply.github.com>
Date: Thu, 4 Apr 2024 23:42:00 +0800
Subject: [PATCH 144/208] removing import
---
src/main/java/financeproject/Main.java | 1 -
1 file changed, 1 deletion(-)
diff --git a/src/main/java/financeproject/Main.java b/src/main/java/financeproject/Main.java
index 4950d06572..17bfb917c0 100644
--- a/src/main/java/financeproject/Main.java
+++ b/src/main/java/financeproject/Main.java
@@ -4,7 +4,6 @@
import customexceptions.ExceededAttemptsException;
import customexceptions.InactivityTimeoutException;
import customexceptions.IncompletePromptException;
-import customexceptions.UserNotFoundException;
import customexceptions.IncorrectCommandSyntaxException;
import financialtransactions.TransactionManager;
import parser.Parser;
From 8ef9ffe99406d0a0656433321e6f565654ed219c Mon Sep 17 00:00:00 2001
From: Kishen271828
Date: Thu, 4 Apr 2024 23:46:10 +0800
Subject: [PATCH 145/208] Update UG
---
docs/UserGuide.md | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/docs/UserGuide.md b/docs/UserGuide.md
index 492323a102..12e36475f5 100644
--- a/docs/UserGuide.md
+++ b/docs/UserGuide.md
@@ -10,7 +10,7 @@ FinTrack is a desktop app designed for individuals who want to manage their fina
2. Download the latest version of `FinTrack.jar` from [here].
3. Copy the file to the folder you want to use as the home folder for your FinTrack app.
4. Open a command terminal, navigate to the folder containing the jar file, and run the command `java -jar FinTrack.jar` to run the application.
-5. Upon starting FinTrack, you will first be prompted to type the username and password. The username is **Bob** and the password is **password**.
+5. Upon starting FinTrack, you will first be prompted to type the username and password. The username is **Bob** and the password is **password**
## Features
@@ -39,6 +39,7 @@ Examples:
### Add Inflow: add-inflow
- Adds a new inflow of money to your financial records.
+- `NAME` should not have any white space characters in it.
- Date input is in DD/MM/YYYY format. Time input is 24-hour format.
- Only the following categories are allowed: *INCOME, INVESTMENT, GIFT, LOAN, REFUND, OTHER*
@@ -58,6 +59,7 @@ Example: `delete-inflow i/2`
### Add Outflow: `add-outflow`
- Adds a new outflow of money to your financial records.
+- `NAME` should not have any white space characters in it.
- Date input is in DD/MM/YYYY format. Time input is 24-hour format.
- Only the following categories are allowed: *FOOD, RENT, DEBT, SHOPPING, TREAT, EDUCATION, TAX, OTHER*
@@ -77,13 +79,14 @@ Example: `delete-outflow i/5`
### Add Reminder: `add-reminder`
- Adds a new reminder of upcoming payment to your financial records.
+- `NAME` should not have any white space characters in it.
- Date input is in DD/MM/YYYY format. Time input is 24-hour format.
- Take note that the date entered must be in the future.
- Only the following categories are allowed: *INSTALLMENT, CREDITCARD, UTILITIES*
Format: `add-reminder n/NAME a/AMOUNT d/DATE t/TIME c/CATEGORY`
-Example: `add-reminder n/water bills a/35 d/21/06/2024 t/1200 c/UTILITIES`
+Example: `add-reminder n/water_bills a/35 d/21/06/2024 t/1200 c/UTILITIES`
### Delete Reminder: `delete-reminder`
@@ -98,6 +101,7 @@ Example: `delete-reminder i/5`
- Edits an existing entry of inflow from your financial records.
- Before editing, the list of inflows along with their indices can be viewed using the `view-history` command.
+- `NAME` should not have any white space characters in it.
- Date input is in DD/MM/YYYY format. Time input is 24-hour format.
- Only the following categories are allowed: *INCOME, INVESTMENT, GIFT, LOAN, REFUND, OTHER*
- Input the index you want to edit and provide the details you want to update for the inflow.
@@ -110,6 +114,7 @@ Example: `edit-inflow i/7 n/Salary a/5000 d/21/02/2024 t/1700 c/income`
- Edits an existing entry of outflow from your financial records.
- Before editing, the list of outflows along with their indices can be viewed using the `view-history` command.
+- `NAME` should not have any white space characters in it.
- Date input is in DD/MM/YYYY format. Time input is 24-hour format.
- Only the following categories are allowed: *FOOD, RENT, DEBT, SHOPPING, TREAT, EDUCATION, TAX, OTHER*
- Input the index you want to edit and provide the details you want to edit for the outflow.
@@ -122,6 +127,7 @@ Example: `edit-outflow i/6 n/John a/100 d/19/02/2024 t/1600 c/food`
- Edits an existing entry of reminder in your financial records.
- Before editing, the list of reminders along with their indices can be viewed using the `view-history` command.
+- `NAME` should not have any white space characters in it.
- Date input is in DD/MM/YYYY format. Time input is 24-hour format.
- Only the following categories are allowed: *INSTALLMENT, CREDITCARD, UTILITIES*
- Input the index you want to edit and provide the details you want to edit for the outflow.
From 19a13a362715bd158a4c8190e6ffec508ec4c318 Mon Sep 17 00:00:00 2001
From: dylansiew <88567790+dylansiew@users.noreply.github.com>
Date: Thu, 4 Apr 2024 23:46:38 +0800
Subject: [PATCH 146/208] fixing bugs
---
src/main/java/financeproject/Main.java | 2 ++
src/main/java/user/Authentication.java | 2 --
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/main/java/financeproject/Main.java b/src/main/java/financeproject/Main.java
index 17bfb917c0..d1a7e641cb 100644
--- a/src/main/java/financeproject/Main.java
+++ b/src/main/java/financeproject/Main.java
@@ -45,6 +45,8 @@ public static void main(String[] args) throws SecurityException {
// Main program flow
do {
response = ui.readInput();
+ ui.printMessage("How can we help you financially today?\n" + //
+ "Type 'help' to view guide\n");
try {
baseCommand = parser.parseCommand(response);
response = baseCommand.execute(manager);
diff --git a/src/main/java/user/Authentication.java b/src/main/java/user/Authentication.java
index 8322a9cc2d..40b17f5157 100644
--- a/src/main/java/user/Authentication.java
+++ b/src/main/java/user/Authentication.java
@@ -19,8 +19,6 @@ public String getUsername() {
}
public boolean checkPassword(String username, String password) {
- System.out.println(password + " and " + this.password);
- System.out.println(username + " and " + this.username);
boolean isMatch = this.password.equals(password) && this.username.equals(username);
return isMatch;
}
From 1cc162ea870c55e723f3686de0959e46c0a833c3 Mon Sep 17 00:00:00 2001
From: Dylan Siew <88567790+dylansiew@users.noreply.github.com>
Date: Thu, 4 Apr 2024 23:55:37 +0800
Subject: [PATCH 147/208] adding diagrams
---
docs/DeveloperGuide.md | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/docs/DeveloperGuide.md b/docs/DeveloperGuide.md
index 8207fa2743..993a240152 100644
--- a/docs/DeveloperGuide.md
+++ b/docs/DeveloperGuide.md
@@ -134,7 +134,13 @@ This application simplifies personal financial management by providing an intuit
- After logging in, do not input any commands for the duration specified by the inactivity timer to test automatic logout.
- A maximum of 2.5 minutes of inactivity will trigger the application to check with the user whether the user is still active or not. Input `yes` to indicate continued activity, otherwise input `no` to exit.
- 30 seconds after the 2.5 min (3 min), the application will automatically exit.
-- Implemented to provide enhanced security, so no third party can access finance transactions.
+- Implemented to provide enhanced security, so no third party can access finance transactions.
+
+
+![photo_2024-04-04 23 54 55](https://github.com/AY2324S2-CS2113-F14-4/tp/assets/88567790/aa2df04e-c493-443e-a4f1-e3cfc506e56a)
+![photo_2024-04-04 23 54 54](https://github.com/AY2324S2-CS2113-F14-4/tp/assets/88567790/95585373-a8a8-4d12-bfce-80cde6f57ebc)
+![photo_2024-04-04 23 54 53](https://github.com/AY2324S2-CS2113-F14-4/tp/assets/88567790/64698f02-9acd-42b5-a8d6-1cbc22574a05)
+
### Data Persistence:
- Exit the application and restart it to ensure that previously entered transactions are still present.
From 89426304725d7877ea054312480eddce98ebb015 Mon Sep 17 00:00:00 2001
From: Kishen271828
Date: Fri, 5 Apr 2024 00:42:17 +0800
Subject: [PATCH 148/208] Add hyperlink
---
docs/UserGuide.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/UserGuide.md b/docs/UserGuide.md
index 12e36475f5..5734641ec1 100644
--- a/docs/UserGuide.md
+++ b/docs/UserGuide.md
@@ -7,7 +7,7 @@ FinTrack is a desktop app designed for individuals who want to manage their fina
## Quick Start
1. Ensure that you have Java 11 or above installed.
-2. Download the latest version of `FinTrack.jar` from [here].
+2. Download the latest version of `FinTrack.jar` from [here](https://github.com/AY2324S2-CS2113-F14-4/tp/releases/tag/v2.0).
3. Copy the file to the folder you want to use as the home folder for your FinTrack app.
4. Open a command terminal, navigate to the folder containing the jar file, and run the command `java -jar FinTrack.jar` to run the application.
5. Upon starting FinTrack, you will first be prompted to type the username and password. The username is **Bob** and the password is **password**
From 6a45d0ea48328ba38118843efb850e4be6aa15b5 Mon Sep 17 00:00:00 2001
From: ChongXern
Date: Fri, 5 Apr 2024 13:11:31 +0800
Subject: [PATCH 149/208] Update User Guide with Features and Hyperlinks
---
META-INF/MANIFEST.MF | 3 +++
docs/UserGuide.md | 19 +++++++++++++++++++
2 files changed, 22 insertions(+)
create mode 100644 META-INF/MANIFEST.MF
diff --git a/META-INF/MANIFEST.MF b/META-INF/MANIFEST.MF
new file mode 100644
index 0000000000..3748942f1e
--- /dev/null
+++ b/META-INF/MANIFEST.MF
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Main-Class: financeproject.Main
+
diff --git a/docs/UserGuide.md b/docs/UserGuide.md
index 12e36475f5..58b480e879 100644
--- a/docs/UserGuide.md
+++ b/docs/UserGuide.md
@@ -13,6 +13,25 @@ FinTrack is a desktop app designed for individuals who want to manage their fina
5. Upon starting FinTrack, you will first be prompted to type the username and password. The username is **Bob** and the password is **password**
## Features
+- [Logging in into user session](#logging-in-into-user-session)
+- [Viewing help](#viewing-help-help)
+- [View Transaction History](#view-transaction-history-view-history)
+- [Add Inflow](#add-inflow-add-inflow)
+- [Delete Inflow](#delete-inflow-delete-inflow)
+- [Add Outflow](#add-outflow-add-outflow)
+- [Delete Outflow](#delete-outflow-delete-outflow)
+- [Add Reminder](#add-reminder-add-reminder)
+- [Delete Reminder](#delete-reminder-delete-reminder)
+- [Edit Inflow](#edit-inflow-edit-inflow)
+- [Edit Outflow](#edit-outflow-edit-outflow)
+- [Edit Reminder](#edit-reminder-edit-reminder)
+- [Undo last action](#undo-last-action-undo)
+- [Set budget](#set-a-budget-set-budget)
+- [Generate report](#generating-a-report-generate-report)
+- [Exit Program](#exiting-the-program-quit)
+- [Saving Data](#saving-the-data)
+- [Inactivity Timer](#inactivity-timer)
+
### Logging in into user session:
From ee8dcb30010d0cb47df8b95a742510a632777971 Mon Sep 17 00:00:00 2001
From: dylansiew <88567790+dylansiew@users.noreply.github.com>
Date: Fri, 5 Apr 2024 14:47:12 +0800
Subject: [PATCH 150/208] using of ui to print
---
src/main/java/command/AddInflowCommand.java | 17 +++---------
src/main/java/command/AddOutflowCommand.java | 17 +++---------
src/main/java/command/AddReminderCommand.java | 17 +++---------
src/main/java/command/EditInflowCommand.java | 9 ++-----
src/main/java/command/EditOutflowCommand.java | 9 ++-----
.../java/command/EditReminderCommand.java | 9 ++-----
src/main/java/command/UndoCommand.java | 4 +--
.../InactivityTimeoutException.java | 1 +
src/main/java/financeproject/Main.java | 19 +++++++++++---
.../financialtransactions/Transaction.java | 5 ----
.../TransactionList.java | 8 +++---
.../TransactionManager.java | 26 +++++++++----------
src/main/java/storage/Storage.java | 21 ++++++++-------
src/main/java/user/InactivityTimer.java | 1 -
.../java/command/AddInflowCommandTest.java | 11 +++++---
.../java/command/AddOutflowCommandTest.java | 13 +++++++---
16 files changed, 80 insertions(+), 107 deletions(-)
diff --git a/src/main/java/command/AddInflowCommand.java b/src/main/java/command/AddInflowCommand.java
index 43d07ad549..2825a4d774 100644
--- a/src/main/java/command/AddInflowCommand.java
+++ b/src/main/java/command/AddInflowCommand.java
@@ -7,16 +7,12 @@
public class AddInflowCommand extends BaseCommand {
- public AddInflowCommand(String[] commandParts) {
+ public AddInflowCommand(String[] commandParts) throws IncorrectCommandSyntaxException, CategoryNotFoundException{
super(false, commandParts);
- try {
- createInflow();
- } catch (IncorrectCommandSyntaxException e) {
- System.out.println(e.getMessage());
- }
+ createInflow();
}
- private void createInflow() throws IncorrectCommandSyntaxException {
+ private void createInflow() throws IncorrectCommandSyntaxException, CategoryNotFoundException {
//@@author Kishen271828
String inflowName = null;
double inflowAmount = 0;
@@ -45,12 +41,7 @@ private void createInflow() throws IncorrectCommandSyntaxException {
String inflowDateTime = inflowDate + " " + inflowTime;
inflow = new Inflow(inflowName, inflowAmount, inflowDateTime);
assert inflowCategory != null;
- try {
- inflow.setCategory(inflowCategory);
- } catch (CategoryNotFoundException e) {
- System.out.println(e.getMessage());
- e.disableExecute(this);
- }
+ inflow.setCategory(inflowCategory);
}
public String execute(TransactionManager manager) {
diff --git a/src/main/java/command/AddOutflowCommand.java b/src/main/java/command/AddOutflowCommand.java
index f2563f34af..156eef8177 100644
--- a/src/main/java/command/AddOutflowCommand.java
+++ b/src/main/java/command/AddOutflowCommand.java
@@ -7,16 +7,12 @@
public class AddOutflowCommand extends BaseCommand {
- public AddOutflowCommand(String[] commandParts) {
+ public AddOutflowCommand(String[] commandParts) throws IncorrectCommandSyntaxException, CategoryNotFoundException {
super(false, commandParts);
- try {
- createOutflow();
- } catch (IncorrectCommandSyntaxException e) {
- System.out.println(e.getMessage());
- }
+ createOutflow();
}
- private void createOutflow() throws IncorrectCommandSyntaxException {
+ private void createOutflow() throws IncorrectCommandSyntaxException, CategoryNotFoundException {
//@@author Kishen271828
String outflowName = null;
double outflowAmount = 0.0;
@@ -46,12 +42,7 @@ private void createOutflow() throws IncorrectCommandSyntaxException {
outflow = new Outflow(outflowName, outflowAmount, outflowDateTime);
assert outflowCategory != null;
- try {
- outflow.setCategory(outflowCategory);
- } catch (CategoryNotFoundException e) {
- System.out.println(e.getMessage());
- e.disableExecute(this);
- }
+ outflow.setCategory(outflowCategory);
}
public String execute(TransactionManager manager) {
diff --git a/src/main/java/command/AddReminderCommand.java b/src/main/java/command/AddReminderCommand.java
index 4ef8603622..b1aa4179ea 100644
--- a/src/main/java/command/AddReminderCommand.java
+++ b/src/main/java/command/AddReminderCommand.java
@@ -6,16 +6,12 @@
import financialtransactions.TransactionManager;
public class AddReminderCommand extends BaseCommand {
- public AddReminderCommand(String[] commandParts) {
+ public AddReminderCommand(String[] commandParts) throws IncorrectCommandSyntaxException, CategoryNotFoundException {
super(false, commandParts);
- try {
- createReminder();
- } catch (IncorrectCommandSyntaxException e) {
- System.out.println(e.getMessage());
- }
+ createReminder();
}
- private void createReminder() throws IncorrectCommandSyntaxException {
+ private void createReminder() throws IncorrectCommandSyntaxException, CategoryNotFoundException {
String reminderName = null;
double reminderAmount = 0.0;
String reminderDate = null;
@@ -43,12 +39,7 @@ private void createReminder() throws IncorrectCommandSyntaxException {
String reminderDateTime = reminderDate + " " + reminderTime;
reminder = new Reminder(reminderName, reminderAmount, reminderDateTime);
assert reminderCategory != null;
- try {
- reminder.setCategory(reminderCategory.toUpperCase());
- } catch (CategoryNotFoundException e) {
- System.out.println(e.getMessage());
- e.disableExecute(this);
- }
+ reminder.setCategory(reminderCategory.toUpperCase());
}
public String execute(TransactionManager manager) {
diff --git a/src/main/java/command/EditInflowCommand.java b/src/main/java/command/EditInflowCommand.java
index d6b872a113..08b904e783 100644
--- a/src/main/java/command/EditInflowCommand.java
+++ b/src/main/java/command/EditInflowCommand.java
@@ -10,7 +10,7 @@ public EditInflowCommand(String[] commandParts) {
super(false, commandParts);
}
- public String execute(TransactionManager manager) throws Exception {
+ public String execute(TransactionManager manager) throws Exception, CategoryNotFoundException {
int inflowIndex = -1;
String inflowName = null;
double inflowAmount = 0;
@@ -42,12 +42,7 @@ public String execute(TransactionManager manager) throws Exception {
String inflowDateTime = inflowDate + " " + inflowTime;
Inflow updatedInflow = new Inflow(inflowName, inflowAmount, inflowDateTime);
assert inflowCategory != null : "inflowCategory should not be null";
- try {
- updatedInflow.setCategory(inflowCategory);
- } catch (CategoryNotFoundException e) {
- System.out.println(e.getMessage());
- e.disableExecute(this);
- }
+ updatedInflow.setCategory(inflowCategory);
if (!canExecute) {
return "Sorry, inflow not edited.";
}
diff --git a/src/main/java/command/EditOutflowCommand.java b/src/main/java/command/EditOutflowCommand.java
index e5c403624b..5ba3196eb8 100644
--- a/src/main/java/command/EditOutflowCommand.java
+++ b/src/main/java/command/EditOutflowCommand.java
@@ -10,7 +10,7 @@ public EditOutflowCommand(String[] commandParts) {
super(false, commandParts);
}
- public String execute(TransactionManager manager) throws Exception {
+ public String execute(TransactionManager manager) throws Exception, CategoryNotFoundException {
int outflowIndex = -1;
String outflowName = null;
double outflowAmount = 0.0;
@@ -42,12 +42,7 @@ public String execute(TransactionManager manager) throws Exception {
String outflowDateTime = outflowDate + " " + outflowTime;
Outflow updatedOutflow = new Outflow(outflowName, outflowAmount, outflowDateTime);
assert outflowCategory != null : "outflowCategory should not be null";
- try {
- updatedOutflow.setCategory(outflowCategory);
- } catch (CategoryNotFoundException e) {
- System.out.println(e.getMessage());
- e.disableExecute(this);
- }
+ updatedOutflow.setCategory(outflowCategory);
if (!canExecute) {
return "Sorry, outflow not edited.";
}
diff --git a/src/main/java/command/EditReminderCommand.java b/src/main/java/command/EditReminderCommand.java
index 70aa3e45f7..c0e798cf9e 100644
--- a/src/main/java/command/EditReminderCommand.java
+++ b/src/main/java/command/EditReminderCommand.java
@@ -10,7 +10,7 @@ public EditReminderCommand(String[] commandParts) {
super(false, commandParts);
}
- public String execute(TransactionManager manager) throws Exception {
+ public String execute(TransactionManager manager) throws Exception, CategoryNotFoundException {
int reminderIndex = -1;
String reminderName = null;
double reminderAmount = 0.0;
@@ -42,12 +42,7 @@ public String execute(TransactionManager manager) throws Exception {
String reminderDateTime = reminderDate + " " + reminderTime;
Reminder updatedReminder = new Reminder(reminderName, reminderAmount, reminderDateTime);
assert reminderCategory != null : "reminderCategory should not be null";
- try {
- updatedReminder.setCategory(reminderCategory.toUpperCase());
- } catch (CategoryNotFoundException e) {
- System.out.println(e.getMessage());
- e.disableExecute(this);
- }
+ updatedReminder.setCategory(reminderCategory.toUpperCase());
if (!canExecute) {
return "Sorry, reminder not edited.";
}
diff --git a/src/main/java/command/UndoCommand.java b/src/main/java/command/UndoCommand.java
index 7b54f9a48e..7961c3c977 100644
--- a/src/main/java/command/UndoCommand.java
+++ b/src/main/java/command/UndoCommand.java
@@ -38,10 +38,10 @@ public void setReminder(Reminder reminder) {
public String execute(TransactionManager manager) throws Exception {
if (!timer.canUndo()) {
- System.out.println("Sorry, no longer able to undo the last action as 10 seconds have passed.");
+ return ("Sorry, no longer able to undo the last action as 10 seconds have passed.");
}
if (commandParts == null) {
- System.out.println("Sorry, there is no action to undo.");
+ return ("Sorry, there is no action to undo.");
}
switch (action) {
case "delete-inflow":
diff --git a/src/main/java/customexceptions/InactivityTimeoutException.java b/src/main/java/customexceptions/InactivityTimeoutException.java
index 0efd0b8162..324502cf84 100644
--- a/src/main/java/customexceptions/InactivityTimeoutException.java
+++ b/src/main/java/customexceptions/InactivityTimeoutException.java
@@ -5,6 +5,7 @@ public class InactivityTimeoutException extends Exception {
private boolean isGracePeriod = false; //Returns true if system is past 2.5 min, false otherwise
public InactivityTimeoutException(boolean isTimeOut, boolean isGracePeriod) {
+ super("Session has timed out");
this.isTimeOut = isTimeOut;
this.isGracePeriod = isGracePeriod;
}
diff --git a/src/main/java/financeproject/Main.java b/src/main/java/financeproject/Main.java
index d1a7e641cb..15654a346a 100644
--- a/src/main/java/financeproject/Main.java
+++ b/src/main/java/financeproject/Main.java
@@ -1,6 +1,7 @@
package financeproject;
import command.BaseCommand;
+import customexceptions.CategoryNotFoundException;
import customexceptions.ExceededAttemptsException;
import customexceptions.InactivityTimeoutException;
import customexceptions.IncompletePromptException;
@@ -38,8 +39,14 @@ public static void main(String[] args) throws SecurityException {
ui.printMessage(e.getMessage());
return;
}
+ TransactionManager manager;
+ try{
+ manager = storage.loadFile(user.getUsername());
+ } catch (CategoryNotFoundException e){
+ ui.printMessage(e.getMessage());
+ return;
+ }
- TransactionManager manager = storage.loadFile(user.getUsername());
ui.printMessage(manager.generateQuickReport());
// Main program flow
@@ -58,7 +65,11 @@ public static void main(String[] args) throws SecurityException {
ui.printMessage("Uh-oh, something went wrong: " + e.getMessage());
}
- storage.saveFile(user.getUsername(), manager);
+ try{
+ storage.saveFile(user.getUsername(), manager);
+ } catch (Exception e){
+ ui.printMessage(e.getMessage());
+ }
try {
inactivityTimer.checkTimeElapsed();
@@ -71,11 +82,11 @@ public static void main(String[] args) throws SecurityException {
String wantToContinue = ui.readInput();
if (wantToContinue.equalsIgnoreCase("y") ||
wantToContinue.equalsIgnoreCase("yes")) {
- System.out.println("Session continued.");
+ ui.printMessage("Session continued.");
inactivityTimer.resetTimer();
} else if (wantToContinue.equalsIgnoreCase("n") ||
wantToContinue.equalsIgnoreCase("no")) {
- System.out.println("Session ended. ");
+ ui.printMessage("Session ended. ");
assert baseCommand != null;
baseCommand.setIsExit(true);
}
diff --git a/src/main/java/financialtransactions/Transaction.java b/src/main/java/financialtransactions/Transaction.java
index 3e0337bcbc..f53fc6d0d3 100644
--- a/src/main/java/financialtransactions/Transaction.java
+++ b/src/main/java/financialtransactions/Transaction.java
@@ -15,11 +15,6 @@ public abstract class Transaction {
public Transaction(String name, double amount, String date) {
assert name != null : "NULL name detected";
- if (name.length() > NAME_MAX_LEN) {
- System.out.println("Sorry, the description inputted exceeds the maximum permeable length. " +
- "Please try again.");
- return;
- }
this.name = name;
this.amount = amount;
if (date == null){
diff --git a/src/main/java/financialtransactions/TransactionList.java b/src/main/java/financialtransactions/TransactionList.java
index 8334e8fe46..10c1a19d3f 100644
--- a/src/main/java/financialtransactions/TransactionList.java
+++ b/src/main/java/financialtransactions/TransactionList.java
@@ -74,13 +74,13 @@ public String toSave() {
}
//@@author
- protected void printTransactionsSafeInfo() {
+ protected String printTransactionsSafeInfo() {
int index = 1;
+ String response = "";
for (T transaction : transactionList) {
- System.out.print(index++);
- System.out.print(" " + transaction.getName() + " | " + transaction.getCategory());
- System.out.println(" | " + transaction.getClass());
+ response += String.format("%d\t%s | %s | %s", index++, transaction.getName(), transaction.getCategory(), transaction.getClass());
}
+ return response;
}
public String getTransactionsType() {
diff --git a/src/main/java/financialtransactions/TransactionManager.java b/src/main/java/financialtransactions/TransactionManager.java
index b369befb12..4a81a1d48c 100644
--- a/src/main/java/financialtransactions/TransactionManager.java
+++ b/src/main/java/financialtransactions/TransactionManager.java
@@ -24,52 +24,50 @@ public void setBudget(double budget) {
this.budget = budget;
}
- public void addTransaction(Transaction> transaction) {
+ public String addTransaction(Transaction> transaction) {
transactionList.addTransaction(transaction);
transactionList.sortTransactions();
if (transaction instanceof Inflow) {
Inflow inflow = (Inflow) transaction;
transactionList.setTransactionsType("Inflow");
inflows.addTransaction(inflow);
- return;
- }
- if (transaction instanceof Outflow) {
+ return String.format("Added: %s", inflow.toString());
+ } else if (transaction instanceof Outflow) {
Outflow outflow = (Outflow) transaction;
transactionList.setTransactionsType("Outflow");
outflows.addTransaction(outflow);
- return;
- }
- if (transaction instanceof Reminder) {
+ return String.format("Added: %s", outflow.toString());
+ } else if (transaction instanceof Reminder) {
Reminder reminder = (Reminder) transaction;
transactionList.setTransactionsType("Reminder");
reminders.addTransaction(reminder);
- return;
+ return String.format("Added: %s", reminder.toString());
}
- System.out.println("Invalid transaction type.");
+ return ("Invalid transaction type.");
}
- public void removeTransaction(Transaction> transaction) {
+ public String removeTransaction(Transaction> transaction) {
int index = transactionList.getIndexOfParticularTransaction(transaction);
transactionList.removeTransactionIndex(index);
if (transaction instanceof Inflow) {
Inflow inflow = (Inflow) transaction;
int inflowIndex = inflows.getIndexOfParticularTransaction(inflow);
inflows.removeTransactionIndex(inflowIndex);
- return;
+ return String.format("Removed: %s", inflow.toString());
}
if (transaction instanceof Outflow) {
Outflow outflow = (Outflow) transaction;
int outflowIndex = outflows.getIndexOfParticularTransaction(outflow);
outflows.removeTransactionIndex(outflowIndex);
- return;
+ return String.format("Removed: %s", outflow.toString());
}
if (transaction instanceof Reminder) {
Reminder reminder = (Reminder) transaction;
int reminderIndex = reminders.getIndexOfParticularTransaction(reminder);
reminders.removeTransactionIndex(reminderIndex);
- return;
+ return String.format("Removed: %s", reminder.toString());
}
- System.out.println("Invalid transaction type.");
+ return ("Invalid transaction type.");
}
public Inflow removeInflow(int index) throws Exception {
diff --git a/src/main/java/storage/Storage.java b/src/main/java/storage/Storage.java
index fb62e872e7..ab459a0c60 100644
--- a/src/main/java/storage/Storage.java
+++ b/src/main/java/storage/Storage.java
@@ -23,13 +23,13 @@ public Storage(String filePath) {
this.filePath = filePath;
}
- public void addNewUser(String username, String password) {
+ public void addNewUser(String username, String password) throws Exception {
try {
FileWriter fw = new FileWriter(filePath + "/passwords.txt", true);
fw.write(username + "|" + password + "\n");
fw.close();
} catch (IOException e) {
- System.out.println("Could not add user");
+ throw new Exception("Error adding user");
}
}
@@ -52,17 +52,20 @@ public BaseUser loadUser(String username) throws UserNotFoundException {
throw new UserNotFoundException();
} catch (FileNotFoundException e) {
createFileDir();
- System.out.println("File is not found, please try again.");
- return null;
+ throw new UserNotFoundException();
}
}
- public TransactionManager loadFile(String username) {
+ public TransactionManager loadFile(String username) throws CategoryNotFoundException {
File f = new File(filePath + String.format("/%s.txt", username));
TransactionManager manager = new TransactionManager();
try {
Scanner sc = new Scanner(f);
- manager.setBudget(Double.parseDouble(sc.nextLine()));
+ double budget = 0.00;
+ if (sc.hasNextLine()){
+ budget = Double.parseDouble(sc.nextLine());
+ }
+ manager.setBudget(budget);
while (sc.hasNext()) {
String[] transactionInfo = sc.nextLine().split("\\|");
assert transactionInfo.length == 5 : "Transaction info should have 5 arguments";
@@ -84,8 +87,6 @@ public TransactionManager loadFile(String username) {
sc.close();
} catch (FileNotFoundException e) {
createFileDir();
- } catch (CategoryNotFoundException e) {
- System.out.println(e.getMessage());
}
return manager;
}
@@ -95,13 +96,13 @@ private void createFileDir() {
f.mkdir();
}
- public void saveFile(String username, TransactionManager tm) {
+ public void saveFile(String username, TransactionManager tm) throws Exception {
try {
FileWriter fw = new FileWriter(filePath + String.format("/%s.txt", username));
fw.write(tm.toSave());
fw.close();
} catch (IOException e) {
- System.out.println("Unable to save tasks!");
+ throw new Exception("Error saving file");
}
}
}
diff --git a/src/main/java/user/InactivityTimer.java b/src/main/java/user/InactivityTimer.java
index 9345986d00..2ab4c98235 100644
--- a/src/main/java/user/InactivityTimer.java
+++ b/src/main/java/user/InactivityTimer.java
@@ -20,7 +20,6 @@ public void resetTimer() {
public void checkTimeElapsed() throws InactivityTimeoutException {
long timeDifference = System.currentTimeMillis() - startTime;
if (timeDifference >= INACTIVITY_TIME) {
- System.out.println("Sorry, your session has ended. Please log in again.");
throw new InactivityTimeoutException(true, false);
} else if (timeDifference >= INACTIVITY_TIME - GRACE_TIME) {
throw new InactivityTimeoutException(false, true);
diff --git a/src/test/java/command/AddInflowCommandTest.java b/src/test/java/command/AddInflowCommandTest.java
index a487eeee13..89d88ae275 100644
--- a/src/test/java/command/AddInflowCommandTest.java
+++ b/src/test/java/command/AddInflowCommandTest.java
@@ -11,9 +11,14 @@ public class AddInflowCommandTest {
public void testAddInflow() {
String arg = "add-inflow n/Salary a/400.00 d/23/05/2022 t/1900 c/income";
String[] splitCommand = arg.split(" ");
- AddInflowCommand command = new AddInflowCommand(splitCommand);
+ try{
+ AddInflowCommand command = new AddInflowCommand(splitCommand);
+ TransactionManager manager = new TransactionManager();
+ assertEquals(command.execute(manager), "Ok. Added inflow");
+ } catch (Exception e){
+ System.out.println(e.getMessage());
+ }
- TransactionManager manager = new TransactionManager();
- assertEquals(command.execute(manager), "Ok. Added inflow");
+
}
}
diff --git a/src/test/java/command/AddOutflowCommandTest.java b/src/test/java/command/AddOutflowCommandTest.java
index 05299ae792..1f1ab36782 100644
--- a/src/test/java/command/AddOutflowCommandTest.java
+++ b/src/test/java/command/AddOutflowCommandTest.java
@@ -6,14 +6,19 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
-public class AddOutflowCommandTest{
+public class AddOutflowCommandTest {
@Test
public void testAddOutflowTest(){
String arg = "add-outflow n/Rent a/1500.00 d/23/06/2023 t/1800 c/rent";
String[] splitCommand = arg.split(" ");
- AddOutflowCommand command = new AddOutflowCommand(splitCommand);
- TransactionManager manager = new TransactionManager();
- assertEquals(command.execute(manager), "Ok. Added outflow");
+ try{
+ AddOutflowCommand command = new AddOutflowCommand(splitCommand);
+ TransactionManager manager = new TransactionManager();
+ assertEquals(command.execute(manager), "Ok. Added outflow");
+ } catch (Exception e){
+ System.out.println(e.getMessage());
+ }
+
}
}
From 8266a43c39324c11d93aed466ac079beb8472f94 Mon Sep 17 00:00:00 2001
From: dylansiew <88567790+dylansiew@users.noreply.github.com>
Date: Fri, 5 Apr 2024 14:56:34 +0800
Subject: [PATCH 151/208] fixing of scanner
---
src/main/java/financeproject/Main.java | 2 +-
src/main/java/storage/Storage.java | 32 +++++++++++++++++++-------
2 files changed, 25 insertions(+), 9 deletions(-)
diff --git a/src/main/java/financeproject/Main.java b/src/main/java/financeproject/Main.java
index a813511df5..44def93fb1 100644
--- a/src/main/java/financeproject/Main.java
+++ b/src/main/java/financeproject/Main.java
@@ -65,7 +65,7 @@ public static void main(String[] args) throws SecurityException {
}
try{
- storage.saveFile(user.getUsername(), manager);
+ ui.printMessage(storage.saveFile(user.getUsername(), manager));
} catch (Exception e){
ui.printMessage(e.getMessage());
}
diff --git a/src/main/java/storage/Storage.java b/src/main/java/storage/Storage.java
index 720b6e5bb1..af75e2acee 100644
--- a/src/main/java/storage/Storage.java
+++ b/src/main/java/storage/Storage.java
@@ -21,10 +21,21 @@ public class Storage {
public Storage(String filePath) {
this.filePath = filePath;
}
-
+
+ public void addNewUser(String username, String password) throws Exception {
+ try {
+ FileWriter fw = new FileWriter(filePath + "/passwords.txt", true);
+ fw.write(username + "|" + password + "\n");
+ fw.close();
+ } catch (IOException e) {
+ throw new Exception("Error adding user");
+ }
+ }
+
public BaseUser loadMockUser(){
return new BaseUser("Bob", "password");
}
+
public BaseUser loadUser(String username) throws UserNotFoundException {
File f = new File(filePath + "/passwords.txt");
try {
@@ -44,13 +55,18 @@ public BaseUser loadUser(String username) throws UserNotFoundException {
}
}
- public TransactionManager loadFile(String username) throws CategoryNotFoundException{
+ public TransactionManager loadFile(String username) throws CategoryNotFoundException {
File f = new File(filePath + String.format("/%s.txt", username));
TransactionManager manager = new TransactionManager();
+ Scanner sc;
try {
- this.sc = new Scanner(f);
- manager.setBudget(Double.parseDouble(sc.nextLine()));
- while (this.sc.hasNext()) {
+ sc = new Scanner(f);
+ double budget = 0.00;
+ if (sc.hasNextLine()){
+ budget = Double.parseDouble(sc.nextLine());
+ }
+ manager.setBudget(budget);
+ while (sc.hasNext()) {
String[] transactionInfo = sc.nextLine().split("\\|");
assert transactionInfo.length == 5 : "Transaction info should have 5 arguments";
double amount = Double.parseDouble(transactionInfo[1]);
@@ -68,10 +84,10 @@ public TransactionManager loadFile(String username) throws CategoryNotFoundExcep
manager.addTransaction(reminder);
}
}
+ sc.close();
} catch (FileNotFoundException e) {
createFileDir();
}
- sc.close();
return manager;
}
@@ -80,14 +96,14 @@ private boolean createFileDir() {
return f.mkdir();
}
- public String saveFile(String username, TransactionManager tm) {
+ public String saveFile(String username, TransactionManager tm) throws Exception {
try {
FileWriter fw = new FileWriter(filePath + String.format("/%s.txt", username));
fw.write(tm.toSave());
fw.close();
return "File saved...";
} catch (IOException e) {
- return "Unable to save tasks!";
+ throw new Exception("Error saving file");
}
}
}
From b414e5de7c4d80a7617501919cd6cfb0c0f1cf2e Mon Sep 17 00:00:00 2001
From: dylansiew <88567790+dylansiew@users.noreply.github.com>
Date: Fri, 5 Apr 2024 15:10:00 +0800
Subject: [PATCH 152/208] resolving formatting errors
---
src/main/java/financialtransactions/TransactionList.java | 3 ++-
src/main/java/storage/Storage.java | 5 +++--
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/src/main/java/financialtransactions/TransactionList.java b/src/main/java/financialtransactions/TransactionList.java
index 10c1a19d3f..7b456fcfc3 100644
--- a/src/main/java/financialtransactions/TransactionList.java
+++ b/src/main/java/financialtransactions/TransactionList.java
@@ -78,7 +78,8 @@ protected String printTransactionsSafeInfo() {
int index = 1;
String response = "";
for (T transaction : transactionList) {
- response += String.format("%d\t%s | %s | %s", index++, transaction.getName(), transaction.getCategory(), transaction.getClass());
+ response += String.format("%d\t%s | %s | %s", index++, transaction.getName(),
+ transaction.getCategory(), transaction.getClass());
}
return response;
}
diff --git a/src/main/java/storage/Storage.java b/src/main/java/storage/Storage.java
index af75e2acee..2e4dcd01be 100644
--- a/src/main/java/storage/Storage.java
+++ b/src/main/java/storage/Storage.java
@@ -28,10 +28,11 @@ public void addNewUser(String username, String password) throws Exception {
fw.write(username + "|" + password + "\n");
fw.close();
} catch (IOException e) {
- throw new Exception("Error adding user");
+ throw new Exception("Error adding user");
}
}
+
public BaseUser loadMockUser(){
return new BaseUser("Bob", "password");
}
@@ -60,7 +61,7 @@ public TransactionManager loadFile(String username) throws CategoryNotFoundExcep
TransactionManager manager = new TransactionManager();
Scanner sc;
try {
- sc = new Scanner(f);
+ sc = new Scanner(f);
double budget = 0.00;
if (sc.hasNextLine()){
budget = Double.parseDouble(sc.nextLine());
From 88e4681e4a6a4284b299de1d20065f38e4dee69c Mon Sep 17 00:00:00 2001
From: dylansiew <88567790+dylansiew@users.noreply.github.com>
Date: Fri, 5 Apr 2024 15:16:51 +0800
Subject: [PATCH 153/208] adding more FAQ
---
docs/UserGuide.md | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/docs/UserGuide.md b/docs/UserGuide.md
index 87611984e9..3633063713 100644
--- a/docs/UserGuide.md
+++ b/docs/UserGuide.md
@@ -208,6 +208,30 @@ FinTrack allows a maximum of 3 minutes of inactivity on the software, then it wi
**A**: Install the app on the other computer and overwrite the empty data file it creates with the file that contains the data of your previous FinTrack home folder.
+**Q**: Can I customize the categories for transactions in FinTrack?
+
+**A**: Currently, FinTrack comes with predefined categories for both inflow and outflow transactions. Custom categories are not supported in the current version, but we're always looking to improve and may include this feature in future releases.
+
+**Q**: Is it possible to have multiple user accounts on FinTrack?
+
+**A**: FinTrack is designed to be used by a single user, and it does not support multiple user accounts in its current version. If multiple users wish to use FinTrack, they would need to install it in separate directories or use different machines.
+
+**Q**: What should I do if I encounter an error or a bug?
+
+**A**: If you encounter any errors or bugs while using FinTrack, please report them to our support team. You can do this by creating an issue on our GitHub repository. Please provide detailed information about the issue and steps to reproduce it, if possible.
+
+**Q**: Can FinTrack be used on mobile devices?
+
+**A**: FinTrack is a desktop application designed for use on computers with Java 11 or above. It is not currently available for mobile devices. However, accessing the application via remote desktop software might be a workaround for accessing FinTrack on a mobile device.
+
+**Q**: How secure is my financial data with FinTrack?
+
+**A**: Your financial data is stored locally on your device and is not transmitted over the internet. We recommend keeping your device secure and regularly backing up your FinTrack data file to prevent data loss. Ensure your device has adequate security measures, such as updated antivirus software and a strong login password.
+
+**Q**: Can I export FinTrack data for use in other applications?
+
+**A**: FinTrack does not currently support exporting data directly to other financial software or applications. However, you can manually input the data into other applications if they support similar transaction formats.
+
## Command Summary
* View Help: `help`
From 51d56aae82c766bd032965e6ec5da2c7a28a44b8 Mon Sep 17 00:00:00 2001
From: Dylan Siew <88567790+dylansiew@users.noreply.github.com>
Date: Fri, 5 Apr 2024 15:32:50 +0800
Subject: [PATCH 154/208] Update DeveloperGuide.md
---
docs/DeveloperGuide.md | 3 +++
1 file changed, 3 insertions(+)
diff --git a/docs/DeveloperGuide.md b/docs/DeveloperGuide.md
index 993a240152..a93206093e 100644
--- a/docs/DeveloperGuide.md
+++ b/docs/DeveloperGuide.md
@@ -7,6 +7,9 @@
## Design & implementation
+![java](https://github.com/AY2324S2-CS2113-F14-4/tp/assets/88567790/2588478b-65bd-4e65-a295-6bc96ee6c23b)
+
+
The financial manager application is designed using an object-oriented approach, focusing on user authentication, transaction management, and user interaction. The core components include:
- **Main Application Loop**: Handles the initialization of the application, including loading data from storage, authenticating the user, and processing user commands until the application exits.
From 90af69b430d4f3fae102d639d2a7a9d061a28e73 Mon Sep 17 00:00:00 2001
From: ChongXern
Date: Thu, 11 Apr 2024 15:42:34 +0800
Subject: [PATCH 155/208] Reposition timer object for each command class
---
src/main/java/command/AddInflowCommand.java | 2 ++
src/main/java/command/AddOutflowCommand.java | 2 ++
src/main/java/command/AddReminderCommand.java | 2 ++
src/main/java/command/BaseCommand.java | 2 ++
src/main/java/command/DeleteInflowCommand.java | 2 ++
src/main/java/command/DeleteOutflowCommand.java | 2 ++
src/main/java/command/DeleteReminderCommand.java | 2 ++
src/main/java/command/UndoCommand.java | 3 +--
src/main/java/storage/BarChart.java | 1 +
src/main/java/user/InactivityTimer.java | 1 +
10 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/src/main/java/command/AddInflowCommand.java b/src/main/java/command/AddInflowCommand.java
index 43d07ad549..f2ba482ac1 100644
--- a/src/main/java/command/AddInflowCommand.java
+++ b/src/main/java/command/AddInflowCommand.java
@@ -4,11 +4,13 @@
import customexceptions.IncorrectCommandSyntaxException;
import financialtransactions.Inflow;
import financialtransactions.TransactionManager;
+import user.InactivityTimer;
public class AddInflowCommand extends BaseCommand {
public AddInflowCommand(String[] commandParts) {
super(false, commandParts);
+ timer = new InactivityTimer();
try {
createInflow();
} catch (IncorrectCommandSyntaxException e) {
diff --git a/src/main/java/command/AddOutflowCommand.java b/src/main/java/command/AddOutflowCommand.java
index f2563f34af..a4030ef3e1 100644
--- a/src/main/java/command/AddOutflowCommand.java
+++ b/src/main/java/command/AddOutflowCommand.java
@@ -4,11 +4,13 @@
import customexceptions.IncorrectCommandSyntaxException;
import financialtransactions.Outflow;
import financialtransactions.TransactionManager;
+import user.InactivityTimer;
public class AddOutflowCommand extends BaseCommand {
public AddOutflowCommand(String[] commandParts) {
super(false, commandParts);
+ timer = new InactivityTimer();
try {
createOutflow();
} catch (IncorrectCommandSyntaxException e) {
diff --git a/src/main/java/command/AddReminderCommand.java b/src/main/java/command/AddReminderCommand.java
index 4ef8603622..6de419cf0f 100644
--- a/src/main/java/command/AddReminderCommand.java
+++ b/src/main/java/command/AddReminderCommand.java
@@ -4,10 +4,12 @@
import customexceptions.IncorrectCommandSyntaxException;
import financialtransactions.Reminder;
import financialtransactions.TransactionManager;
+import user.InactivityTimer;
public class AddReminderCommand extends BaseCommand {
public AddReminderCommand(String[] commandParts) {
super(false, commandParts);
+ timer = new InactivityTimer();
try {
createReminder();
} catch (IncorrectCommandSyntaxException e) {
diff --git a/src/main/java/command/BaseCommand.java b/src/main/java/command/BaseCommand.java
index 87c68c24d5..dc770fdc48 100644
--- a/src/main/java/command/BaseCommand.java
+++ b/src/main/java/command/BaseCommand.java
@@ -4,6 +4,7 @@
import financialtransactions.Outflow;
import financialtransactions.Reminder;
import financialtransactions.TransactionManager;
+import user.InactivityTimer;
public abstract class BaseCommand {
public boolean isExit;
@@ -11,6 +12,7 @@ public abstract class BaseCommand {
protected Outflow outflow;
protected Reminder reminder;
protected boolean canExecute = true;
+ protected InactivityTimer timer;
String[] commandParts;
public BaseCommand(Boolean isExit, String[] commandParts){
this.isExit = isExit;
diff --git a/src/main/java/command/DeleteInflowCommand.java b/src/main/java/command/DeleteInflowCommand.java
index acfbb25328..ba4f59f42c 100644
--- a/src/main/java/command/DeleteInflowCommand.java
+++ b/src/main/java/command/DeleteInflowCommand.java
@@ -2,10 +2,12 @@
import customexceptions.IncorrectCommandSyntaxException;
import financialtransactions.TransactionManager;
+import user.InactivityTimer;
public class DeleteInflowCommand extends BaseCommand {
public DeleteInflowCommand(String[] commandParts) {
super(false, commandParts);
+ timer = new InactivityTimer();
}
public String execute(TransactionManager manager) throws Exception {
diff --git a/src/main/java/command/DeleteOutflowCommand.java b/src/main/java/command/DeleteOutflowCommand.java
index 7b841ed98e..c76f05e1a6 100644
--- a/src/main/java/command/DeleteOutflowCommand.java
+++ b/src/main/java/command/DeleteOutflowCommand.java
@@ -2,10 +2,12 @@
import customexceptions.IncorrectCommandSyntaxException;
import financialtransactions.TransactionManager;
+import user.InactivityTimer;
public class DeleteOutflowCommand extends BaseCommand {
public DeleteOutflowCommand(String[] commandParts) {
super(false, commandParts);
+ timer = new InactivityTimer();
}
public String execute(TransactionManager manager) throws Exception {
diff --git a/src/main/java/command/DeleteReminderCommand.java b/src/main/java/command/DeleteReminderCommand.java
index 73acb5bd10..7286629561 100644
--- a/src/main/java/command/DeleteReminderCommand.java
+++ b/src/main/java/command/DeleteReminderCommand.java
@@ -2,10 +2,12 @@
import customexceptions.IncorrectCommandSyntaxException;
import financialtransactions.TransactionManager;
+import user.InactivityTimer;
public class DeleteReminderCommand extends BaseCommand {
public DeleteReminderCommand(String[] commandParts) {
super(false, commandParts);
+ timer = new InactivityTimer();
}
public String execute(TransactionManager manager) throws Exception {
diff --git a/src/main/java/command/UndoCommand.java b/src/main/java/command/UndoCommand.java
index 7b54f9a48e..de0423f73b 100644
--- a/src/main/java/command/UndoCommand.java
+++ b/src/main/java/command/UndoCommand.java
@@ -6,17 +6,16 @@
import financialtransactions.TransactionManager;
import user.InactivityTimer;
+//@@author ChongXern
public class UndoCommand extends BaseCommand {
private Inflow inflow;
private Outflow outflow;
private Reminder reminder;
private String action;
private boolean canUndo = false;
- private InactivityTimer timer;
public UndoCommand(String[] commandParts) {
super(false, commandParts);
- this.timer = new InactivityTimer();
action = commandParts[0];
}
diff --git a/src/main/java/storage/BarChart.java b/src/main/java/storage/BarChart.java
index c7ad1b2fe9..a04e256773 100644
--- a/src/main/java/storage/BarChart.java
+++ b/src/main/java/storage/BarChart.java
@@ -5,6 +5,7 @@
import java.util.HashMap;
import java.util.Map;
+//@@author ChongXern
public class BarChart> {
private static final int TOTAL_BAR_SIZE = 50;
private static final int LEGEND_SIZE = 10;
diff --git a/src/main/java/user/InactivityTimer.java b/src/main/java/user/InactivityTimer.java
index 9345986d00..9859005c34 100644
--- a/src/main/java/user/InactivityTimer.java
+++ b/src/main/java/user/InactivityTimer.java
@@ -2,6 +2,7 @@
import customexceptions.InactivityTimeoutException;
+//@@author ChongXern
public class InactivityTimer {
public static final int INACTIVITY_TIME = 180_000;
public static final int GRACE_TIME = 30_000;
From fe15bafae5909eb651f94f15f7bd936faf6deeef Mon Sep 17 00:00:00 2001
From: ChongXern
Date: Thu, 11 Apr 2024 15:47:35 +0800
Subject: [PATCH 156/208] Remove unused InactivityTimer import
---
src/main/java/command/UndoCommand.java | 1 -
src/main/java/parser/Parser.java | 15 ++++++++++++---
2 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/src/main/java/command/UndoCommand.java b/src/main/java/command/UndoCommand.java
index de0423f73b..653ce4d46c 100644
--- a/src/main/java/command/UndoCommand.java
+++ b/src/main/java/command/UndoCommand.java
@@ -4,7 +4,6 @@
import financialtransactions.Outflow;
import financialtransactions.Reminder;
import financialtransactions.TransactionManager;
-import user.InactivityTimer;
//@@author ChongXern
public class UndoCommand extends BaseCommand {
diff --git a/src/main/java/parser/Parser.java b/src/main/java/parser/Parser.java
index b48ccf174c..300f11e086 100644
--- a/src/main/java/parser/Parser.java
+++ b/src/main/java/parser/Parser.java
@@ -95,17 +95,26 @@ public BaseCommand parseCommand(String command) throws Exception {
if (commandParts.length < 7) {
throw new IncompletePromptException(command);
}
- return new EditInflowCommand(commandParts);
+ lastCommandParts = commandParts;
+ lastCommand = new EditInflowCommand(commandParts);
+ lastInflow = lastCommand.getInflow();
+ return lastCommand;
case "edit-outflow":
if (commandParts.length < 7) {
throw new IncompletePromptException(command);
}
- return new EditOutflowCommand(commandParts);
+ lastCommandParts = commandParts;
+ lastCommand = new EditOutflowCommand(commandParts);
+ lastOutflow = lastCommand.getOutflow();
+ return lastCommand;
case "edit-reminder":
if (commandParts.length < 7) {
throw new IncompletePromptException(command);
}
- return new EditReminderCommand(commandParts);
+ lastCommandParts = commandParts;
+ lastCommand = new EditReminderCommand(commandParts);
+ lastReminder = lastCommand.getReminder();
+ return lastCommand;
case "set-budget":
if (commandParts.length < 2) {
throw new IncompletePromptException(command);
From 919f32258cd61e9c728ffda5c17deee014481d7a Mon Sep 17 00:00:00 2001
From: Chong Xern <104547209+ChongXern@users.noreply.github.com>
Date: Thu, 11 Apr 2024 22:03:24 +0800
Subject: [PATCH 157/208] Add Project Portfolio Page for Chong Xern
---
docs/team/chongxern.md | 12 ++++++++++++
1 file changed, 12 insertions(+)
create mode 100644 docs/team/chongxern.md
diff --git a/docs/team/chongxern.md b/docs/team/chongxern.md
new file mode 100644
index 0000000000..8a1dda0fa1
--- /dev/null
+++ b/docs/team/chongxern.md
@@ -0,0 +1,12 @@
+# Chong Xern - Project Portfolio Page
+
+## Overview
+Finance tracking application that helps keep track of all things related to finances such as income, spending, expenditure, reminders, gifts and more.
+
+### Summary of Contributions
+[Code Contributed](https://nus-cs2113-ay2324s2.github.io/tp-dashboard/?search=&sort=groupTitle&sortWithin=title&timeframe=commit&mergegroup=&groupSelect=groupByRepos&breakdown=true&checkedFileTypes=docs~functional-code~test-code~other&since=2024-02-23&tabOpen=true&tabType=authorship&tabAuthor=ChongXern&tabRepo=AY2324S2-CS2113-F14-4%2Ftp%5Bmaster%5D&authorshipIsMergeGroup=false&authorshipFileTypes=docs~functional-code~test-code~other&authorshipIsBinaryFileTypeChecked=false&authorshipIsIgnoredFilesChecked=false/) by Chong Xern
+#### Enhancements Implemented
+
+#### Contributions to User Guide
+
+#### Contributions to Developer Guide
From b40aee03a67f2d23fd8d57e3d0db375610b85d49 Mon Sep 17 00:00:00 2001
From: ChongXern
Date: Thu, 11 Apr 2024 22:12:12 +0800
Subject: [PATCH 158/208] Resolve Issue #100
Enable entering with uppercase to view chart
---
src/main/java/command/ViewHistoryCommand.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/java/command/ViewHistoryCommand.java b/src/main/java/command/ViewHistoryCommand.java
index bb90f7fdd6..6fd558a38f 100644
--- a/src/main/java/command/ViewHistoryCommand.java
+++ b/src/main/java/command/ViewHistoryCommand.java
@@ -21,7 +21,7 @@ public String execute(TransactionManager manager) throws Exception{
} else {
throw new IncorrectCommandSyntaxException(commandParts[0]);
}
- boolean isIncludeBarChart = commandParts.length == 3 && commandParts[2].equals("w/chart");
+ boolean isIncludeBarChart = commandParts.length == 3 && commandParts[2].equalsIgnoreCase("w/chart");
return manager.showLastNTransactions(numTransactions, isIncludeBarChart);
}
}
From 6fc74eb0552e8af11a26bebddbab25a6cd7bf8d4 Mon Sep 17 00:00:00 2001
From: Chong Xern <104547209+ChongXern@users.noreply.github.com>
Date: Thu, 11 Apr 2024 22:23:03 +0800
Subject: [PATCH 159/208] Update Project Portfolio Page chongxern.md
---
docs/team/chongxern.md | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/docs/team/chongxern.md b/docs/team/chongxern.md
index 8a1dda0fa1..e72c8b1e70 100644
--- a/docs/team/chongxern.md
+++ b/docs/team/chongxern.md
@@ -4,9 +4,26 @@
Finance tracking application that helps keep track of all things related to finances such as income, spending, expenditure, reminders, gifts and more.
### Summary of Contributions
-[Code Contributed](https://nus-cs2113-ay2324s2.github.io/tp-dashboard/?search=&sort=groupTitle&sortWithin=title&timeframe=commit&mergegroup=&groupSelect=groupByRepos&breakdown=true&checkedFileTypes=docs~functional-code~test-code~other&since=2024-02-23&tabOpen=true&tabType=authorship&tabAuthor=ChongXern&tabRepo=AY2324S2-CS2113-F14-4%2Ftp%5Bmaster%5D&authorshipIsMergeGroup=false&authorshipFileTypes=docs~functional-code~test-code~other&authorshipIsBinaryFileTypeChecked=false&authorshipIsIgnoredFilesChecked=false/) by Chong Xern
+[**Code Contributed**](https://nus-cs2113-ay2324s2.github.io/tp-dashboard/?search=&sort=groupTitle&sortWithin=title&timeframe=commit&mergegroup=&groupSelect=groupByRepos&breakdown=true&checkedFileTypes=docs~functional-code~test-code~other&since=2024-02-23&tabOpen=true&tabType=authorship&tabAuthor=ChongXern&tabRepo=AY2324S2-CS2113-F14-4%2Ftp%5Bmaster%5D&authorshipIsMergeGroup=false&authorshipFileTypes=docs~functional-code~test-code~other&authorshipIsBinaryFileTypeChecked=false&authorshipIsIgnoredFilesChecked=false/) by Chong Xern
#### Enhancements Implemented
+1. **Undo last action functionality**
+
+Allow actions such as `add-inflow` and `delete-outflow` to be undone using the `undo` command, but only if within 10 seconds.
+
+2. **Bar chart feature for** `view-history`
+
+Enable descriptive bar chart of transactions to be viewed using `w/chart`
+
+3. **Inactivity Timer**
+
+Used to check that the user is still inputting commands or is inactive. Also used for aforementioned `undo` command to check if 10 seconds has passed.
+
+4. **Bug fixes**
+
+5. **JUnit testing**
#### Contributions to User Guide
+Added personal contributions to my enhancements, as well as adding more information to other functionalities and improving the formatting of the User Guide with hyperlinks to sections.
#### Contributions to Developer Guide
+Added relevant descriptions and information to enhancments and user guides,
From 2b2d5746a5f4ce9e205d396b89c811b7b956cc44 Mon Sep 17 00:00:00 2001
From: ChongXern
Date: Thu, 11 Apr 2024 23:16:07 +0800
Subject: [PATCH 160/208] Resolve Issue #123
---
src/main/java/command/AddInflowCommand.java | 6 +++++-
src/main/java/command/AddOutflowCommand.java | 5 ++++-
src/main/java/command/AddReminderCommand.java | 5 ++++-
src/main/java/command/EditInflowCommand.java | 5 ++++-
src/main/java/command/EditOutflowCommand.java | 5 ++++-
src/main/java/command/EditReminderCommand.java | 5 ++++-
src/main/java/financeproject/Main.java | 9 ++++++++-
7 files changed, 33 insertions(+), 7 deletions(-)
diff --git a/src/main/java/command/AddInflowCommand.java b/src/main/java/command/AddInflowCommand.java
index 400277b9b2..c9dcf8eda3 100644
--- a/src/main/java/command/AddInflowCommand.java
+++ b/src/main/java/command/AddInflowCommand.java
@@ -8,7 +8,7 @@
public class AddInflowCommand extends BaseCommand {
- public AddInflowCommand(String[] commandParts) throws IncorrectCommandSyntaxException, CategoryNotFoundException{
+ public AddInflowCommand(String[] commandParts) throws CategoryNotFoundException, IllegalArgumentException {
super(false, commandParts);
timer = new InactivityTimer();
try {
@@ -34,6 +34,9 @@ private void createInflow() throws IncorrectCommandSyntaxException, CategoryNotF
inflowName = part.substring(2);
} else if (part.startsWith("a/")) {
inflowAmount = Double.parseDouble(part.substring(2));
+ if (inflowAmount <= 0) {
+ throw new IllegalArgumentException("Sorry, inflow amount must be positive.");
+ }
} else if (part.startsWith("d/")) {
inflowDate = part.substring(2);
} else if (part.startsWith("t/")) {
@@ -58,4 +61,5 @@ public String execute(TransactionManager manager) {
manager.addTransaction(inflow);
return "Ok. Added inflow";
}
+
}
diff --git a/src/main/java/command/AddOutflowCommand.java b/src/main/java/command/AddOutflowCommand.java
index b82b0483c2..e0d54f9e88 100644
--- a/src/main/java/command/AddOutflowCommand.java
+++ b/src/main/java/command/AddOutflowCommand.java
@@ -12,7 +12,7 @@ public AddOutflowCommand(String[] commandParts) throws IncorrectCommandSyntaxExc
timer = new InactivityTimer();
try {
createOutflow();
- } catch (IncorrectCommandSyntaxException e) {
+ } catch (IncorrectCommandSyntaxException | IllegalArgumentException e) {
System.out.println(e.getMessage());
}
}
@@ -33,6 +33,9 @@ private void createOutflow() throws IncorrectCommandSyntaxException, CategoryNot
outflowName = part.substring(2);
} else if (part.startsWith("a/")) {
outflowAmount = Double.parseDouble(part.substring(2));
+ if (outflowAmount <= 0) {
+ throw new IllegalArgumentException("Sorry, inflow amount must be positive.");
+ }
} else if (part.startsWith("d/")) {
outflowDate = part.substring(2);
} else if (part.startsWith("t/")) {
diff --git a/src/main/java/command/AddReminderCommand.java b/src/main/java/command/AddReminderCommand.java
index f996e2721c..0db5478f1f 100644
--- a/src/main/java/command/AddReminderCommand.java
+++ b/src/main/java/command/AddReminderCommand.java
@@ -12,7 +12,7 @@ public AddReminderCommand(String[] commandParts) throws IncorrectCommandSyntaxEx
timer = new InactivityTimer();
try {
createReminder();
- } catch (IncorrectCommandSyntaxException e) {
+ } catch (IncorrectCommandSyntaxException | IllegalArgumentException e) {
System.out.println(e.getMessage());
}
}
@@ -32,6 +32,9 @@ private void createReminder() throws IncorrectCommandSyntaxException, CategoryNo
reminderName = part.substring(2);
} else if (part.startsWith("a/")) {
reminderAmount = Double.parseDouble(part.substring(2));
+ if (reminderAmount <= 0) {
+ throw new IllegalArgumentException("Sorry, inflow amount must be positive.");
+ }
} else if (part.startsWith("d/")) {
reminderDate = part.substring(2);
} else if (part.startsWith("t/")) {
diff --git a/src/main/java/command/EditInflowCommand.java b/src/main/java/command/EditInflowCommand.java
index 08b904e783..42fd153278 100644
--- a/src/main/java/command/EditInflowCommand.java
+++ b/src/main/java/command/EditInflowCommand.java
@@ -10,7 +10,7 @@ public EditInflowCommand(String[] commandParts) {
super(false, commandParts);
}
- public String execute(TransactionManager manager) throws Exception, CategoryNotFoundException {
+ public String execute(TransactionManager manager) throws Exception {
int inflowIndex = -1;
String inflowName = null;
double inflowAmount = 0;
@@ -28,6 +28,9 @@ public String execute(TransactionManager manager) throws Exception, CategoryNotF
inflowName = part.substring(2);
} else if (part.startsWith("a/")) {
inflowAmount = Double.parseDouble(part.substring(2));
+ if (inflowAmount <= 0) {
+ throw new IllegalArgumentException("Sorry, inflow amount must be positive.");
+ }
} else if (part.startsWith("d/")) {
inflowDate = part.substring(2);
} else if (part.startsWith("t/")) {
diff --git a/src/main/java/command/EditOutflowCommand.java b/src/main/java/command/EditOutflowCommand.java
index 5ba3196eb8..b46eb97011 100644
--- a/src/main/java/command/EditOutflowCommand.java
+++ b/src/main/java/command/EditOutflowCommand.java
@@ -10,7 +10,7 @@ public EditOutflowCommand(String[] commandParts) {
super(false, commandParts);
}
- public String execute(TransactionManager manager) throws Exception, CategoryNotFoundException {
+ public String execute(TransactionManager manager) throws Exception {
int outflowIndex = -1;
String outflowName = null;
double outflowAmount = 0.0;
@@ -28,6 +28,9 @@ public String execute(TransactionManager manager) throws Exception, CategoryNotF
outflowName = part.substring(2);
} else if (part.startsWith("a/")) {
outflowAmount = Double.parseDouble(part.substring(2));
+ if (outflowAmount <= 0) {
+ throw new IllegalArgumentException("Sorry, inflow amount must be positive.");
+ }
} else if (part.startsWith("d/")) {
outflowDate = part.substring(2);
} else if (part.startsWith("t/")) {
diff --git a/src/main/java/command/EditReminderCommand.java b/src/main/java/command/EditReminderCommand.java
index c0e798cf9e..3414103ed0 100644
--- a/src/main/java/command/EditReminderCommand.java
+++ b/src/main/java/command/EditReminderCommand.java
@@ -10,7 +10,7 @@ public EditReminderCommand(String[] commandParts) {
super(false, commandParts);
}
- public String execute(TransactionManager manager) throws Exception, CategoryNotFoundException {
+ public String execute(TransactionManager manager) throws Exception {
int reminderIndex = -1;
String reminderName = null;
double reminderAmount = 0.0;
@@ -28,6 +28,9 @@ public String execute(TransactionManager manager) throws Exception, CategoryNotF
reminderName = part.substring(2);
} else if (part.startsWith("a/")) {
reminderAmount = Double.parseDouble(part.substring(2));
+ if (reminderAmount <= 0) {
+ throw new IllegalArgumentException("Sorry, inflow amount must be positive.");
+ }
} else if (part.startsWith("d/")) {
reminderDate = part.substring(2);
} else if (part.startsWith("t/")) {
diff --git a/src/main/java/financeproject/Main.java b/src/main/java/financeproject/Main.java
index 44def93fb1..13b3e995b9 100644
--- a/src/main/java/financeproject/Main.java
+++ b/src/main/java/financeproject/Main.java
@@ -58,9 +58,16 @@ public static void main(String[] args) throws SecurityException {
response = baseCommand.execute(manager);
ui.printMessage(response);
inactivityTimer.resetTimer();
- } catch (IncompletePromptException | IncorrectCommandSyntaxException e) {
+ } catch (IncompletePromptException | IncorrectCommandSyntaxException | IllegalArgumentException e) {
ui.printMessage(e.getMessage());
} catch (Exception e) {
+ StackTraceElement[] stackTrace = e.getStackTrace();
+ if (stackTrace.length > 0) {
+ StackTraceElement stackElement = stackTrace[0];
+ System.out.println("Error in file " + stackElement.getFileName() +
+ " at line " + stackElement.getLineNumber() +
+ ", method " + stackElement.getMethodName());
+ }
ui.printMessage("Uh-oh, something went wrong: " + e.getMessage());
}
From 7846a510e5a71f282ece38ab8c187bfa3555b3f9 Mon Sep 17 00:00:00 2001
From: Dylan Siew
Date: Thu, 11 Apr 2024 23:22:08 +0800
Subject: [PATCH 161/208] PPP
---
docs/team/dylansiew.md | 69 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 69 insertions(+)
create mode 100644 docs/team/dylansiew.md
diff --git a/docs/team/dylansiew.md b/docs/team/dylansiew.md
new file mode 100644
index 0000000000..dda016d8b5
--- /dev/null
+++ b/docs/team/dylansiew.md
@@ -0,0 +1,69 @@
+# Dylan Siew - Project Portfolio Page
+
+## Overview
+Finance tracking application that helps keep track of all things related to finances such as income, spending, expenditure, reminders, gifts, and more.
+
+### Summary of Contributions
+[**Code Contributed**](https://nus-cs2113-ay2324s2.github.io/tp-dashboard/?search=&sort=groupTitle&sortWithin=title&timeframe=commit&mergegroup=&groupSelect=groupByRepos&breakdown=true&checkedFileTypes=docs~functional-code~test-code~other&since=2024-02-23&tabOpen=true&tabType=authorship&tabAuthor=dylansiew&tabRepo=AY2324S2-CS2113-F14-4%2Ftp%5Bmaster%5D&authorshipIsMergeGroup=false&authorshipFileTypes=docs~functional-code~test-code~other&authorshipIsBinaryFileTypeChecked=false&authorshipIsIgnoredFilesChecked=false) by Dylan Siew
+
+#### Enhancements Implemented
+
+1. **Create Base User Class**
+
+ Implemented the foundation for user data handling, enabling personalized user experiences and data management.
+
+2. **Create Authentication Class**
+
+ Developed authentication mechanisms to ensure user data security and privacy, involving password protection and secure user login.
+
+3. **Create Date Handler Class**
+
+ Designed a class to manage and parse date information, essential for scheduling and tracking financial transactions over time.
+
+4. **Create Expenditure Class**
+
+ Established a class to track and manage user expenditures, providing a structured way to record and analyze spending.
+
+5. **Create Base Command Class**
+
+ Crafted the core command class structure to streamline the processing and execution of user commands, enhancing the application's scalability and maintainability.
+
+6. **Create Add Source/Transaction Command Class**
+
+ Devised functionality for users to add income sources and financial transactions, enriching the application's capability to monitor financial flows.
+
+7. **Create Delete Source/Transaction Command Class**
+
+ Formulated a method for users to remove unwanted or incorrect income sources and transactions, maintaining the accuracy and relevance of financial data.
+
+8. **Ensure UI Object Used in Printing of All Statements**
+
+ Refined the application's user interface by standardizing the output mechanism, improving user interaction consistency and clarity.
+
+#### Contributions to User Guide
+
+In the User Guide, I focused on expanding the Q&A section to address common queries and concerns users might have regarding FinTrack. My contributions aimed to clarify the application's capabilities, usage, and security aspects, enhancing user understanding and confidence in using FinTrack:
+
+1. **Customization of Transaction Categories**: I clarified that FinTrack currently does not support custom transaction categories but mentioned the possibility of including this feature in future versions, reflecting the application's commitment to improvement based on user feedback.
+
+2. **Multiple User Accounts**: I addressed the limitation of FinTrack in supporting only single user accounts and suggested workarounds for multiple users wishing to use the application, guiding users towards practical solutions for shared use.
+
+3. **Reporting Errors or Bugs**: I provided guidance on how users can report errors or bugs they encounter, emphasizing the importance of detailed information and reproduction steps. This contribution is crucial for maintaining an open channel of communication with users and facilitating continuous improvement of FinTrack.
+
+4. **Mobile Device Compatibility**: I explained that FinTrack is primarily a desktop application and outlined potential workarounds for accessing it on mobile devices through remote desktop software, offering users flexibility in how they access the application.
+
+5. **Security of Financial Data**: I reassured users about the security of their financial data with FinTrack, emphasizing local data storage and the importance of device security and data backup practices. This response aims to build user trust in the application's data handling.
+
+6. **Data Export Capabilities**: I clarified the current limitations regarding data export to other applications, while suggesting manual data entry as an interim solution, indicating an area for potential development in future versions of FinTrack.
+
+#### Contributions to Developer Guide
+
+1. **Main Application Loop**: I documented the initialization process of the application, emphasizing the sequence of operations from loading data, user authentication, to handling user commands. This section provides insight into the application's lifecycle and user interaction flow.
+
+2. **Command Pattern**: My contribution highlighted how user commands are encapsulated as objects, facilitating the easy addition of new commands. This approach minimizes changes to existing code, showcasing the application's extensibility and maintainability.
+
+3. **Transaction Management**: I elaborated on the implementation of separate classes for managing inflows and outflows, including a unified interface for transaction operations such as addition, editing, and deletion. This part of the guide explains how the application organizes and processes financial data.
+
+4. **User Authentication**: I detailed the authentication process, ensuring that users are securely authenticated before accessing their financial data. This includes mechanisms to track and limit failed login attempts, reinforcing the application's security measures.
+
+5. **Storage Management**: My documentation covered how the application handles the persistent storage of transaction data, allowing for the secure saving and loading of user financial information across sessions. This ensures data reliability and availability.
From bbd399aae375d19495f5c0729707b5e24757cc41 Mon Sep 17 00:00:00 2001
From: ChongXern
Date: Thu, 11 Apr 2024 23:22:33 +0800
Subject: [PATCH 162/208] Remove unnecessary imports
---
src/main/java/command/EditInflowCommand.java | 1 -
src/main/java/command/EditOutflowCommand.java | 1 -
src/main/java/command/EditReminderCommand.java | 1 -
3 files changed, 3 deletions(-)
diff --git a/src/main/java/command/EditInflowCommand.java b/src/main/java/command/EditInflowCommand.java
index 42fd153278..24d8bb6de4 100644
--- a/src/main/java/command/EditInflowCommand.java
+++ b/src/main/java/command/EditInflowCommand.java
@@ -1,6 +1,5 @@
package command;
-import customexceptions.CategoryNotFoundException;
import customexceptions.IncorrectCommandSyntaxException;
import financialtransactions.Inflow;
import financialtransactions.TransactionManager;
diff --git a/src/main/java/command/EditOutflowCommand.java b/src/main/java/command/EditOutflowCommand.java
index b46eb97011..501f2190c5 100644
--- a/src/main/java/command/EditOutflowCommand.java
+++ b/src/main/java/command/EditOutflowCommand.java
@@ -1,6 +1,5 @@
package command;
-import customexceptions.CategoryNotFoundException;
import customexceptions.IncorrectCommandSyntaxException;
import financialtransactions.Outflow;
import financialtransactions.TransactionManager;
diff --git a/src/main/java/command/EditReminderCommand.java b/src/main/java/command/EditReminderCommand.java
index 3414103ed0..b8b0234e7c 100644
--- a/src/main/java/command/EditReminderCommand.java
+++ b/src/main/java/command/EditReminderCommand.java
@@ -1,6 +1,5 @@
package command;
-import customexceptions.CategoryNotFoundException;
import customexceptions.IncorrectCommandSyntaxException;
import financialtransactions.Reminder;
import financialtransactions.TransactionManager;
From 70c77936eff35448e6addaeb2676b831222aa6f1 Mon Sep 17 00:00:00 2001
From: Kishen271828
Date: Fri, 12 Apr 2024 02:04:09 +0800
Subject: [PATCH 163/208] Add Kishen271828 contribution in PPP
---
docs/team/kishen271828.md | 55 +++++++++++++++++++++++++++++++++++++++
1 file changed, 55 insertions(+)
create mode 100644 docs/team/kishen271828.md
diff --git a/docs/team/kishen271828.md b/docs/team/kishen271828.md
new file mode 100644
index 0000000000..ad121e96a6
--- /dev/null
+++ b/docs/team/kishen271828.md
@@ -0,0 +1,55 @@
+# Kishen Gandhi - Project Portfolio Page
+
+## Overview
+FinTrack is a desktop app designed for individuals who want to manage their finances using a Command Line Interface (CLI). FinTrack offers a convenient way for users to track their income, expenses, and budgets through typed commands. With FinTrack, users can easily add income and expense transactions, categorize them, set budgets, and generate reports to gain valuable insights into their financial activities.
+
+### Summary of Contributions
+
+[**Code Contributed**](https://nus-cs2113-ay2324s2.github.io/tp-dashboard/?search=kishen271828&breakdown=true&sort=groupTitle%20dsc&sortWithin=title&since=2024-02-23&timeframe=commit&mergegroup=&groupSelect=groupByRepos&checkedFileTypes=docs~functional-code~test-code~other) by Kishen Gandhi
+
+#### Enhancements Implemented
+
+1. **Add, Delete and Edit functionality for Inflows**
+
+ Implemented add, delete, and edit functionalities for managing inflows in the finance tracker
+
+
+2. **Add, Delete and Edit functionality for Outflows**
+
+ Implemented add, delete, and edit functionalities for managing outflows in the finance tracker
+
+
+3. **View Transaction History feature**
+
+ Initially, this feature was implemented such that users can view their past transactions. This feature was further enhanced by Chong Xern allowing users to visualize the transaction history in the form of a bar chart.
+
+
+4. **Sort Transactions by Time**
+
+ Implemented sorting of transactions by date, ensuring transactions are displayed chronologically
+
+
+5. **Create Parser Class**
+
+ Developed a Parser class to process user commands and execute corresponding actions in the finance tracker
+
+
+6. **Bug fixes**
+
+
+7. **JUnit Test Cases**
+
+#### Contributions to User Guide
+
+- I authored the introduction section of the FinTrack user guide, providing an overview of the application's purpose and features.
+- I authored the Quick Start section of the FinTrack user guide, which includes setup and installation instructions for new users.
+- Explained and documented the following features: Login, `help`, `view-history`, `add-inflow`, `delete-inflow`, `edit-inflow`, `add-outflow`, `delete-outflow`, `edit-outflow`, `quit`
+- Created a command summary for quick reference
+
+#### Contributions to Developer Guide
+
+- Explained the functionality, design considerations and implementation details for the `view-history` feature
+
+#### Contributions to Team-Based Tasks
+
+- Managed releases `v1.0`, `v2.0` on GitHub
\ No newline at end of file
From 0dfe6e18d9d39c64a3f88a4eaa4e29954aa177ea Mon Sep 17 00:00:00 2001
From: chowy
Date: Fri, 12 Apr 2024 08:45:59 +0800
Subject: [PATCH 164/208] Updated PPP for chenhowy
---
docs/team/chenhowy.md | 47 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 47 insertions(+)
create mode 100644 docs/team/chenhowy.md
diff --git a/docs/team/chenhowy.md b/docs/team/chenhowy.md
new file mode 100644
index 0000000000..544c5edc7e
--- /dev/null
+++ b/docs/team/chenhowy.md
@@ -0,0 +1,47 @@
+# Yong Chen How - Project Portfolio Page
+
+## Overview
+Finance tracking application that helps keep track of all things related to finances such as income, spending, expenditure, reminders, gifts, and more.
+
+### Summary of Contributions
+[**Code contributed**](https://nus-cs2113-ay2324s2.github.io/tp-dashboard/?search=&sort=groupTitle&sortWithin=title&timeframe=commit&mergegroup=&groupSelect=groupByRepos&breakdown=true&checkedFileTypes=docs~functional-code~test-code~other&since=2024-02-23&tabOpen=true&tabType=authorship&tabAuthor=chenhowy&tabRepo=AY2324S2-CS2113-F14-4%2Ftp%5Bmaster%5D&authorshipIsMergeGroup=false&authorshipFileTypes=docs~functional-code~test-code&authorshipIsBinaryFileTypeChecked=false&authorshipIsIgnoredFilesChecked=false) by Chen How
+
+#### Enhancements implemented
+1. **Storage class**
+
+ The storage class deals with loading and storing all user data.
+ - Loading user data when app launches.
+ - Creating file directories if they do not exist.
+ - Storing user data after each user action/ user quits.
+ - Also created a create user method to allow the app to handle multiple users. However, this was later unused as it was out of project scope.
+
+
+2. **Created reminder class**
+
+ This class is similar to both inflows and outflows, however the main distinction is that reminders are for transactions that have yet to happen.
+ - This class was extended from both inflows and outflows, which was not written by myself.
+
+
+3. **Generate report**
+
+ There are two forms of generate report: generateReport and generateQuickReport.
+ - generateQuickReport is only used when app is launched and after user has logged in. It gets a quick overview of the spendings in the past 1 month.
+ - generateReport is called when the user wants to check any month that has already passed. It gets a full overview comparing inflows and outflows, so that the user can see their comprehensive spendings.
+
+
+4. **Budget**
+ Budget keeps track of total amount the user sets to spend each month. When logging in, the user is reminded of the budget they have left to spend.
+ - Budget is currently just a variable under Transaction Manger.
+ - It could be more fleshed out as a full class on its own to have more comprehensive features such as having different budgets each month and having separate categories.
+
+5. **Help command**
+ This command generates a simple string which consists of all commands available for the user to use.
+
+#### Contributions to user guide
+Added personal contributions such as commands for budget, generate report and reminder class.
+
+#### Contributions to developer guide
+Added personal contributions such as commands for budget, generate report and reminder class.
+
+#### Contributions to team-based tasks
+Helped with debugging, especially when teammates faced certain issues with their build.
\ No newline at end of file
From a58ba233062db2b7b06980d033fd9d6371f317e3 Mon Sep 17 00:00:00 2001
From: ChongXern
Date: Fri, 12 Apr 2024 13:55:36 +0800
Subject: [PATCH 165/208] Fix issues #126, #104 and #95
---
src/main/java/command/ViewHistoryCommand.java | 12 +++++++++---
.../financialtransactions/TransactionManager.java | 2 +-
2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/src/main/java/command/ViewHistoryCommand.java b/src/main/java/command/ViewHistoryCommand.java
index 6fd558a38f..db72747b92 100644
--- a/src/main/java/command/ViewHistoryCommand.java
+++ b/src/main/java/command/ViewHistoryCommand.java
@@ -9,13 +9,19 @@ public ViewHistoryCommand(String[] commandParts) {
super(false,commandParts);
}
- public String execute(TransactionManager manager) throws Exception{
+ public String execute(TransactionManager manager) throws Exception {
//@@author Kishen271828
- //String numTransactionsString = null;
int numTransactions = 0;
if (commandParts[1].startsWith("n/")) {
String numTransactionsString = commandParts[1].substring(2);
- numTransactions = Integer.parseInt(numTransactionsString);
+ try {
+ numTransactions = Integer.parseInt(numTransactionsString);
+ if (numTransactions <= 0) {
+ throw new IllegalArgumentException("Sorry, please input a positive index.");
+ }
+ } catch (NumberFormatException e) {
+ throw new IncorrectCommandSyntaxException(commandParts[0]);
+ }
} else if (commandParts[1].equals("all")) {
numTransactions = manager.getTransactionListSize();
} else {
diff --git a/src/main/java/financialtransactions/TransactionManager.java b/src/main/java/financialtransactions/TransactionManager.java
index 40a3d4fea1..b6ca9847b4 100644
--- a/src/main/java/financialtransactions/TransactionManager.java
+++ b/src/main/java/financialtransactions/TransactionManager.java
@@ -107,7 +107,7 @@ public Inflow editInflow(int index, Transaction> updatedTransaction) throws Ex
inflows.editTransactionIndex(numOfInflows - index, (Inflow) updatedTransaction);
inflows.sortTransactions();
- return (Inflow) transactionEdited;
+ return transactionEdited;
}
public Outflow editOutflow(int index, Transaction> updatedTransaction) throws Exception {
From 9a3cf9a531f518e07999588901e1351935c68eaf Mon Sep 17 00:00:00 2001
From: chowy
Date: Sat, 13 Apr 2024 08:05:27 +0800
Subject: [PATCH 166/208] Fixed delete-reminder, delete-inflow, delete-outflow
to delete at correct index
---
.../financialtransactions/TransactionManager.java | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/src/main/java/financialtransactions/TransactionManager.java b/src/main/java/financialtransactions/TransactionManager.java
index b6ca9847b4..808ff69ec8 100644
--- a/src/main/java/financialtransactions/TransactionManager.java
+++ b/src/main/java/financialtransactions/TransactionManager.java
@@ -70,31 +70,34 @@ public String removeTransaction(Transaction> transaction) {
public Inflow removeInflow(int index) throws Exception {
int numOfInflows = inflows.getTransactionListSize();
- Inflow transactionRemoved = (Inflow) inflows.getNthTransaction(numOfInflows - index);
+ Inflow transactionRemoved = (Inflow) inflows.getNthTransaction(index);
transactionList.removeTransactionIndex(transactionList.getIndexOfParticularTransaction(transactionRemoved));
transactionList.sortTransactions();
- inflows.removeTransactionIndex(numOfInflows - index);
+ inflows.removeTransactionIndex(index);
inflows.sortTransactions();
return transactionRemoved;
}
public Outflow removeOutflow(int index) throws Exception {
int numOfOutflows = outflows.getTransactionListSize();
- Outflow transactionRemoved = (Outflow) outflows.getNthTransaction(numOfOutflows - index);
+ Outflow transactionRemoved = (Outflow) outflows.getNthTransaction(index);
transactionList.removeTransactionIndex(transactionList.getIndexOfParticularTransaction(transactionRemoved));
transactionList.sortTransactions();
- outflows.removeTransactionIndex(numOfOutflows - index);
+ outflows.removeTransactionIndex(index);
outflows.sortTransactions();
return transactionRemoved;
}
public Reminder removeReminder(int index) throws Exception {
int numOfReminders = reminders.getTransactionListSize();
- Reminder transactionRemoved = (Reminder) reminders.getNthTransaction(numOfReminders - index);
+ Reminder transactionRemoved = (Reminder) reminders.getNthTransaction(index);
transactionList.removeTransactionIndex(transactionList.getIndexOfParticularTransaction(transactionRemoved));
- reminders.removeTransactionIndex(numOfReminders - index);
+ transactionList.sortTransactions();
+
+ reminders.removeTransactionIndex(index);
+ reminders.sortTransactions();
return transactionRemoved;
}
From c89aa9f73950e02e72c14c9d3e01a7e15eb308a4 Mon Sep 17 00:00:00 2001
From: chowy
Date: Sat, 13 Apr 2024 08:27:27 +0800
Subject: [PATCH 167/208] Fixed help command showing incorrect information,
fixed edit reminder not working.
---
src/main/java/command/EditReminderCommand.java | 2 +-
src/main/java/command/HelpCommand.java | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/main/java/command/EditReminderCommand.java b/src/main/java/command/EditReminderCommand.java
index b8b0234e7c..39807e1298 100644
--- a/src/main/java/command/EditReminderCommand.java
+++ b/src/main/java/command/EditReminderCommand.java
@@ -48,7 +48,7 @@ public String execute(TransactionManager manager) throws Exception {
if (!canExecute) {
return "Sorry, reminder not edited.";
}
- manager.editOutflow(reminderIndex, updatedReminder);
+ manager.editReminder(reminderIndex, updatedReminder);
return "Ok. Edited reminder";
}
}
diff --git a/src/main/java/command/HelpCommand.java b/src/main/java/command/HelpCommand.java
index a4fa803030..cd2564ca56 100644
--- a/src/main/java/command/HelpCommand.java
+++ b/src/main/java/command/HelpCommand.java
@@ -19,7 +19,7 @@ public String execute(TransactionManager manager) throws Exception {
baseString += "6) delete-reminder i/INDEX\n";
baseString += "7) edit-inflow i/INDEX n/NAME a/AMOUNT d/DATE t/TIME c/CATEGORY\n";
baseString += "8) edit-outflow i/INDEX n/NAME a/AMOUNT d/DATE t/TIME c/CATEGORY\n";
- baseString += "9) delete-reminder i/INDEX n/NAME a/AMOUNT d/DATE t/TIME c/CATEGORY\n";
+ baseString += "9) edit-reminder i/INDEX n/NAME a/AMOUNT d/DATE t/TIME c/CATEGORY\n";
baseString += "10) set-budget a/AMOUNT\n";
baseString += "11) view-history n/NUM \n";
baseString += "12) generate-report m/MONTH y/YEAR\n";
From a7370c241adeacd68767f617c3c6d705c6cd1e01 Mon Sep 17 00:00:00 2001
From: chowy
Date: Sat, 13 Apr 2024 08:31:12 +0800
Subject: [PATCH 168/208] Fixed generate-report accepting inputs that do not
make sense
---
src/main/java/command/GenerateReportCommand.java | 3 +++
1 file changed, 3 insertions(+)
diff --git a/src/main/java/command/GenerateReportCommand.java b/src/main/java/command/GenerateReportCommand.java
index e10660093a..dfce27ebad 100644
--- a/src/main/java/command/GenerateReportCommand.java
+++ b/src/main/java/command/GenerateReportCommand.java
@@ -57,6 +57,9 @@ public String execute(TransactionManager manager) throws Exception{
}
if (commandParts[2].startsWith("y/")) {
year = Integer.parseInt(commandParts[2].substring(2));
+ if (year <= 0) {
+ return "Year must be a valid year";
+ }
}
return manager.generateFullReport(monthString, month, year);
}
From 7c4a5d989a7df387cf3083b5d7a8b70762319b59 Mon Sep 17 00:00:00 2001
From: chowy
Date: Sat, 13 Apr 2024 08:57:10 +0800
Subject: [PATCH 169/208] Fixed invalid date inputs causing null dateTime
---
src/main/java/command/AddInflowCommand.java | 3 +++
src/main/java/command/AddOutflowCommand.java | 3 +++
src/main/java/command/AddReminderCommand.java | 3 +++
3 files changed, 9 insertions(+)
diff --git a/src/main/java/command/AddInflowCommand.java b/src/main/java/command/AddInflowCommand.java
index c9dcf8eda3..7190f2c86b 100644
--- a/src/main/java/command/AddInflowCommand.java
+++ b/src/main/java/command/AddInflowCommand.java
@@ -58,6 +58,9 @@ public String execute(TransactionManager manager) {
if (!canExecute) {
return "Sorry, inflow not added.";
}
+ if (inflow.getDate().getDateTime() == null) {
+ return "Please enter a valid date or time";
+ }
manager.addTransaction(inflow);
return "Ok. Added inflow";
}
diff --git a/src/main/java/command/AddOutflowCommand.java b/src/main/java/command/AddOutflowCommand.java
index e0d54f9e88..526e38160e 100644
--- a/src/main/java/command/AddOutflowCommand.java
+++ b/src/main/java/command/AddOutflowCommand.java
@@ -58,6 +58,9 @@ public String execute(TransactionManager manager) {
if (!canExecute) {
return "Sorry, outflow not added.";
}
+ if (outflow.getDate().getDateTime() == null) {
+ return "Please enter a valid date or time";
+ }
manager.addTransaction(outflow);
return "Ok. Added outflow";
}
diff --git a/src/main/java/command/AddReminderCommand.java b/src/main/java/command/AddReminderCommand.java
index 0db5478f1f..1f100d82f9 100644
--- a/src/main/java/command/AddReminderCommand.java
+++ b/src/main/java/command/AddReminderCommand.java
@@ -55,6 +55,9 @@ public String execute(TransactionManager manager) {
if (!canExecute) {
return "Sorry, reminder not added.";
}
+ if (reminder.getDate().getDateTime() == null) {
+ return "Please enter a valid date or time";
+ }
manager.addTransaction(reminder);
return "Ok. Added reminder";
}
From cef5ebc1a8f5b4e882494459ca765df87c5faddf Mon Sep 17 00:00:00 2001
From: Dylan Siew