forked from nus-cs2103-AY2324S2/tp
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
296 additions
and
80 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_BIRTHDAY; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_MONEY_OWED; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; | ||
|
@@ -28,12 +29,14 @@ public class AddCommand extends Command { | |
+ PREFIX_EMAIL + "EMAIL " | ||
+ PREFIX_ADDRESS + "ADDRESS " | ||
+ "[" + PREFIX_BIRTHDAY + "BIRTHDAY]" | ||
+ PREFIX_MONEY_OWED + "AMOUNT_OWED" | ||
+ "[" + PREFIX_TAG + "TAG]...\n" | ||
+ "Example: " + COMMAND_WORD + " " | ||
+ PREFIX_NAME + "John Doe " | ||
+ PREFIX_PHONE + "98765432 " | ||
+ PREFIX_EMAIL + "[email protected] " | ||
+ PREFIX_ADDRESS + "311, Clementi Ave 2, #02-25 " | ||
+ PREFIX_MONEY_OWED + "24.50 " | ||
+ PREFIX_TAG + "friends " | ||
+ PREFIX_TAG + "owesMoney"; | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package seedu.address.model.person; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.commons.util.AppUtil.checkArgument; | ||
|
||
/** | ||
* Represents a Person's money owed in the address book. | ||
* Guarantees: immutable; is valid as declared in {@link #isValidMoney(String)} | ||
*/ | ||
public class MoneyOwed { | ||
|
||
public static final String MESSAGE_CONSTRAINTS = | ||
"Money Owed should be at most 2 decimal places in the following format 'xxx.xx' or '-xxx.xx'. "; | ||
public static final String VALIDATION_REGEX = "^(?:-)?\\d+(\\.\\d{0,2})?"; | ||
|
||
public final Float moneyOwed; | ||
|
||
/** | ||
* Constructs a {@code MoneyOwed}. | ||
* | ||
* @param money A valid amount of money owed. | ||
*/ | ||
public MoneyOwed(String money) { | ||
requireNonNull(money); | ||
checkArgument(isValidMoney(money), MESSAGE_CONSTRAINTS); | ||
moneyOwed = Float.parseFloat(money); | ||
} | ||
|
||
/** | ||
* Returns true if a given string is a valid money amount. | ||
*/ | ||
public static boolean isValidMoney(String test) { | ||
if (test == null) { | ||
return true; | ||
} | ||
return test.matches(VALIDATION_REGEX); | ||
} | ||
|
||
/** | ||
* Returns true if a moneyOwed is negative. | ||
*/ | ||
public boolean isNegativeMoney() { | ||
return (moneyOwed < 0); | ||
} | ||
|
||
/** | ||
* Returns message to display on UI in String. | ||
*/ | ||
public String getMessage() { | ||
if (moneyOwed == 0) { | ||
return String.format("You don't owe each other anything"); | ||
} | ||
if (isNegativeMoney()) { | ||
return String.format("You owe $" + toString().substring(1)); | ||
} else { | ||
return String.format("Owes you $" + this); | ||
} | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.format("%.2f", moneyOwed); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof MoneyOwed)) { | ||
return false; | ||
} | ||
|
||
MoneyOwed otherName = (MoneyOwed) other; | ||
return moneyOwed.equals(otherName.moneyOwed); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return moneyOwed.hashCode(); | ||
} | ||
} |
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.