Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement commands and encapsulate fields in Purchase object #137

Merged
merged 28 commits into from Oct 19, 2019

Conversation

gohsnn
Copy link

@gohsnn gohsnn commented Oct 17, 2019

Things done:

  • commands added: add-paid, delete-paid, edit-install, list

  • encapsulation of fields in Purchase object

  • reorganise methods in files

@gohsnn gohsnn added this to the v1.3 milestone Oct 17, 2019
@gohsnn gohsnn changed the title Implement add-paid, delete-paid and edit-install commands Implement commands and encapsulate fields in Purchase object Oct 17, 2019
* Stores the details to edit the installment with. Each non-empty field value will replace the
* corresponding field value of the installment.
*/
public static class EditInstallmentDescriptor {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can consider abstracting this class out? might be neater.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alright noted! thanks :)

@gohsnn gohsnn self-assigned this Oct 18, 2019
EditInstallmentCommand.MESSAGE_USAGE), pe);
}

EditInstallmentCommand.EditInstallmentDescriptor editInstallmentDescriptor =
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can consider importing the nested class straight to improve readability.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

noted, thanks for the tip!

@@ -51,8 +53,12 @@ public void resetData(PurchaseList purchaseList) {
//=========== Getter Methods ==================================================================================

public Purchase getPurchase(int purchaseIndex) {
Index index = Index.fromOneBased(purchaseIndex);
return allPurchases.get(index.getZeroBased());
try {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the try / catch statement is not needed here, a guard conditional might be better.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why would this be so?


public double getMonthlyLimit() {
return monthlyLimit;
public ArrayList<Purchase> getPurchaseList() {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps return a List instead? Not much issue here actually, but I think its good to return the interface instead of concrete class instead.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ArrayLists used were changed to ObservableLists to accomodate ListFinancesCommand

@@ -132,7 +99,7 @@ public void addSinglePurchase(Purchase purchase) {
*
* @param itemNumber of payment to be deleted
*/
public Purchase deleteSinglePurchase(int itemNumber) {
public Purchase deleteSinglePurchase(int itemNumber) throws PurchaseNotFoundException {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Runtime exception no need to declare in method signature, but I am not too sure on which is better. There is an argument that it may be confusing to differentiate between checked exceptions, and can also clutter logic. But I am not too sure how valid these opinions are.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alright thanks for the tip!

@@ -97,7 +121,7 @@ public Purchase deletePurchase(int purchaseIndex) {
public double totalSpending() {
double total = 0;
for (Purchase purchase : allPurchases) {
total += purchase.getMoneySpent();
total += purchase.getMoneySpent().getPurchaseAmount();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return purchase.stream().reduce(0, (prev, next) -> prev + next.getMoneySpent().getPurchaseAmount() works too

@gohsnn gohsnn merged commit 065dfce into AY1920S1-CS2103T-T10-1:master Oct 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants