forked from nus-cs2113-AY2324S2/tp
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from Kishen271828/master
Delete transaction implemented properly, Edit transaction functionality added
- Loading branch information
Showing
15 changed files
with
285 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package command; | ||
|
||
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("i/")) { | ||
inflowIndex = part.substring(2); | ||
} | ||
} | ||
assert inflowIndex != null; | ||
manager.removeInflow(Integer.parseInt(inflowIndex)); | ||
return "Ok. Inflow deleted"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package command; | ||
|
||
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("i/")) { | ||
outflowIndex = part.substring(2); | ||
} | ||
} | ||
assert outflowIndex != null; | ||
manager.removeOutflow(Integer.parseInt(outflowIndex)); | ||
return "Ok. Outflow deleted"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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("r/")) { | ||
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"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.