Skip to content

Commit

Permalink
Merge pull request #88 from Cleon2/feature_income
Browse files Browse the repository at this point in the history
Add Income
  • Loading branch information
shishirbychapur authored Oct 16, 2023
2 parents 044eab8 + 41536f1 commit 307153c
Show file tree
Hide file tree
Showing 26 changed files with 299 additions and 77 deletions.
10 changes: 5 additions & 5 deletions docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ Parameter constraints:
- Horoscope should be a non-empty string.

Example:
`NewD name/Cleon age/22 gender/F height/1.76 horoscope/Taurus income/3000`
`newD name/Cleon age/22 gender/F height/1.76 horoscope/Taurus income/3000`

Expected output: `New date has been successfully added!`

Output if error:
Please follow the required format to add a new date (New date /name Adam /age 123 /gender F /horoscope Cancer)

### Edit existing dates
Format: `EditD INDEX METRIC/NEW ARG`
Format: `editD INDEX METRIC/NEW ARG`

Parameter constraints:
- The index must be a positive integer, and be within the range of the recorded dates
Expand All @@ -98,9 +98,9 @@ Parameter constraints:
- User can edit up to n number of metrics in one command line, where n refers to the number of metrics available

Example:
- `EditD 3 name/Cleon` (editing 1 metric)
- `EditD 3 name/Cleon horoscope/Cancer` (editing 2 metrics)
- `EditD 3 horoscope/Cancer name/Cleon` (sequence doesn't matter)
- `editD 3 name/Cleon` (editing 1 metric)
- `editD 3 name/Cleon horoscope/Cancer` (editing 2 metrics)
- `editD 3 horoscope/Cancer name/Cleon` (sequence doesn't matter)

Expected Output: `The date information has been successfully updated!`

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/seedu/lovebook/logic/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public static String format(Date date) {
.append(date.getGender())
.append("; Height: ")
.append(date.getHeight())
.append("; Income: ")
.append(date.getIncome())
.append("; Tags: ");
date.getTags().forEach(builder::append);
return builder.toString();
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/seedu/lovebook/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static seedu.lovebook.logic.parser.CliSyntax.PREFIX_AGE;
import static seedu.lovebook.logic.parser.CliSyntax.PREFIX_GENDER;
import static seedu.lovebook.logic.parser.CliSyntax.PREFIX_HEIGHT;
import static seedu.lovebook.logic.parser.CliSyntax.PREFIX_INCOME;
import static seedu.lovebook.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.lovebook.logic.parser.CliSyntax.PREFIX_TAG;

Expand All @@ -26,12 +27,14 @@ public class AddCommand extends Command {
+ PREFIX_AGE + "AGE "
+ PREFIX_GENDER + "GENDER "
+ PREFIX_HEIGHT + "HEIGHT "
+ PREFIX_INCOME + "INCOME "
+ "[" + PREFIX_TAG + "TAG]...\n"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_NAME + "John Doe "
+ PREFIX_AGE + "21 "
+ PREFIX_GENDER + "M "
+ PREFIX_HEIGHT + "23124 "
+ PREFIX_INCOME + "3000 "
+ PREFIX_TAG + "friends "
+ PREFIX_TAG + "owesMoney";

Expand Down
18 changes: 17 additions & 1 deletion src/main/java/seedu/lovebook/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static seedu.lovebook.logic.parser.CliSyntax.PREFIX_AGE;
import static seedu.lovebook.logic.parser.CliSyntax.PREFIX_GENDER;
import static seedu.lovebook.logic.parser.CliSyntax.PREFIX_HEIGHT;
import static seedu.lovebook.logic.parser.CliSyntax.PREFIX_INCOME;
import static seedu.lovebook.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.lovebook.logic.parser.CliSyntax.PREFIX_TAG;
import static seedu.lovebook.model.Model.PREDICATE_SHOW_ALL_PERSONS;
Expand All @@ -25,6 +26,7 @@
import seedu.lovebook.model.person.Date;
import seedu.lovebook.model.person.Gender;
import seedu.lovebook.model.person.Height;
import seedu.lovebook.model.person.Income;
import seedu.lovebook.model.person.Name;
import seedu.lovebook.model.tag.Tag;

Expand All @@ -43,6 +45,7 @@ public class EditCommand extends Command {
+ "[" + PREFIX_AGE + "AGE] "
+ "[" + PREFIX_GENDER + "GENDER] "
+ "[" + PREFIX_HEIGHT + "HEIGHT] "
+ "[" + PREFIX_INCOME + "INCOME] "
+ "[" + PREFIX_TAG + "TAG]...\n"
+ "Example: " + COMMAND_WORD + " 1 "
+ PREFIX_AGE + "91234567 "
Expand Down Expand Up @@ -99,9 +102,10 @@ private static Date createEditedPerson(Date dateToEdit, EditPersonDescriptor edi
Age updatedAge = editPersonDescriptor.getAge().orElse(dateToEdit.getAge());
Gender updatedGender = editPersonDescriptor.getGender().orElse(dateToEdit.getGender());
Height updatedHeight = editPersonDescriptor.getHeight().orElse(dateToEdit.getHeight());
Income updatedIncome = editPersonDescriptor.getIncome().orElse(dateToEdit.getIncome());
Set<Tag> updatedTags = editPersonDescriptor.getTags().orElse(dateToEdit.getTags());

return new Date(updatedName, updatedAge, updatedGender, updatedHeight, updatedTags);
return new Date(updatedName, updatedAge, updatedGender, updatedHeight, updatedIncome, updatedTags);
}

@Override
Expand Down Expand Up @@ -137,6 +141,7 @@ public static class EditPersonDescriptor {
private Age age;
private Gender gender;
private Height height;
private Income income;
private Set<Tag> tags;

public EditPersonDescriptor() {}
Expand All @@ -150,6 +155,7 @@ public EditPersonDescriptor(EditPersonDescriptor toCopy) {
setAge(toCopy.age);
setGender(toCopy.gender);
setHeight(toCopy.height);
setIncome(toCopy.income);
setTags(toCopy.tags);
}

Expand Down Expand Up @@ -188,10 +194,18 @@ public void setHeight(Height height) {
this.height = height;
}

public void setIncome(Income income) {
this.income = income;
}

public Optional<Height> getHeight() {
return Optional.ofNullable(height);
}

public Optional<Income> getIncome() {
return Optional.ofNullable(income);
}

/**
* Sets {@code tags} to this object's {@code tags}.
* A defensive copy of {@code tags} is used internally.
Expand Down Expand Up @@ -225,6 +239,7 @@ public boolean equals(Object other) {
&& Objects.equals(age, otherEditPersonDescriptor.age)
&& Objects.equals(gender, otherEditPersonDescriptor.gender)
&& Objects.equals(height, otherEditPersonDescriptor.height)
&& Objects.equals(income, otherEditPersonDescriptor.income)
&& Objects.equals(tags, otherEditPersonDescriptor.tags);
}

Expand All @@ -235,6 +250,7 @@ public String toString() {
.add("age", age)
.add("gender", gender)
.add("height", height)
.add("income", income)
.add("tags", tags)
.toString();
}
Expand Down
13 changes: 9 additions & 4 deletions src/main/java/seedu/lovebook/logic/parser/AddCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static seedu.lovebook.logic.parser.CliSyntax.PREFIX_AGE;
import static seedu.lovebook.logic.parser.CliSyntax.PREFIX_GENDER;
import static seedu.lovebook.logic.parser.CliSyntax.PREFIX_HEIGHT;
import static seedu.lovebook.logic.parser.CliSyntax.PREFIX_INCOME;
import static seedu.lovebook.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.lovebook.logic.parser.CliSyntax.PREFIX_TAG;

Expand All @@ -16,9 +17,11 @@
import seedu.lovebook.model.person.Date;
import seedu.lovebook.model.person.Gender;
import seedu.lovebook.model.person.Height;
import seedu.lovebook.model.person.Income;
import seedu.lovebook.model.person.Name;
import seedu.lovebook.model.tag.Tag;


/**
* Parses input arguments and creates a new AddCommand object
*/
Expand All @@ -31,21 +34,23 @@ public class AddCommandParser implements Parser<AddCommand> {
*/
public AddCommand parse(String args) throws ParseException {
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_AGE, PREFIX_GENDER, PREFIX_HEIGHT, PREFIX_TAG);
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_AGE, PREFIX_GENDER, PREFIX_HEIGHT, PREFIX_INCOME,
PREFIX_TAG);

if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_HEIGHT, PREFIX_AGE, PREFIX_GENDER)
if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_HEIGHT, PREFIX_AGE, PREFIX_GENDER, PREFIX_INCOME)
|| !argMultimap.getPreamble().isEmpty()) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE));
}

argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_AGE, PREFIX_GENDER, PREFIX_HEIGHT);
argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_AGE, PREFIX_GENDER, PREFIX_HEIGHT, PREFIX_INCOME);
Name name = ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get());
Age age = ParserUtil.parseAge(argMultimap.getValue(PREFIX_AGE).get());
Gender gender = ParserUtil.parseGender(argMultimap.getValue(PREFIX_GENDER).get());
Height height = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_HEIGHT).get());
Income income = ParserUtil.parseIncome(argMultimap.getValue(PREFIX_INCOME).get());
Set<Tag> tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG));

Date date = new Date(name, age, gender, height, tagList);
Date date = new Date(name, age, gender, height, income, tagList);

return new AddCommand(date);
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/seedu/lovebook/logic/parser/CliSyntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public class CliSyntax {
public static final Prefix PREFIX_AGE = new Prefix("age/");
public static final Prefix PREFIX_GENDER = new Prefix("gender/");
public static final Prefix PREFIX_HEIGHT = new Prefix("a/");

public static final Prefix PREFIX_INCOME = new Prefix("income/");
public static final Prefix PREFIX_TAG = new Prefix("t/");

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static seedu.lovebook.logic.parser.CliSyntax.PREFIX_AGE;
import static seedu.lovebook.logic.parser.CliSyntax.PREFIX_GENDER;
import static seedu.lovebook.logic.parser.CliSyntax.PREFIX_HEIGHT;
import static seedu.lovebook.logic.parser.CliSyntax.PREFIX_INCOME;
import static seedu.lovebook.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.lovebook.logic.parser.CliSyntax.PREFIX_TAG;

Expand Down Expand Up @@ -32,7 +33,8 @@ public class EditCommandParser implements Parser<EditCommand> {
public EditCommand parse(String args) throws ParseException {
requireNonNull(args);
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_AGE, PREFIX_GENDER, PREFIX_HEIGHT, PREFIX_TAG);
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_AGE, PREFIX_GENDER, PREFIX_HEIGHT, PREFIX_INCOME,
PREFIX_TAG);

Index index;

Expand All @@ -42,7 +44,7 @@ public EditCommand parse(String args) throws ParseException {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE), pe);
}

argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_AGE, PREFIX_GENDER, PREFIX_HEIGHT);
argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_AGE, PREFIX_GENDER, PREFIX_HEIGHT, PREFIX_INCOME);

EditPersonDescriptor editPersonDescriptor = new EditPersonDescriptor();

Expand All @@ -58,6 +60,9 @@ public EditCommand parse(String args) throws ParseException {
if (argMultimap.getValue(PREFIX_HEIGHT).isPresent()) {
editPersonDescriptor.setHeight(ParserUtil.parseAddress(argMultimap.getValue(PREFIX_HEIGHT).get()));
}
if (argMultimap.getValue(PREFIX_INCOME).isPresent()) {
editPersonDescriptor.setIncome(ParserUtil.parseIncome(argMultimap.getValue(PREFIX_INCOME).get()));
}
parseTagsForEdit(argMultimap.getAllValues(PREFIX_TAG)).ifPresent(editPersonDescriptor::setTags);

if (!editPersonDescriptor.isAnyFieldEdited()) {
Expand Down
33 changes: 25 additions & 8 deletions src/main/java/seedu/lovebook/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import seedu.lovebook.model.person.Age;
import seedu.lovebook.model.person.Gender;
import seedu.lovebook.model.person.Height;
import seedu.lovebook.model.person.Income;
import seedu.lovebook.model.person.Name;
import seedu.lovebook.model.tag.Tag;

Expand Down Expand Up @@ -65,6 +66,21 @@ public static Age parseAge(String age) throws ParseException {
return new Age(trimmedAge);
}

/**
* Parses a {@code String gender} into an {@code Gender}.
* Leading and trailing whitespaces will be trimmed.
*
* @throws ParseException if the given {@code gender} is invalid.
*/
public static Gender parseGender(String gender) throws ParseException {
requireNonNull(gender);
String trimmedGender = gender.trim();
if (!Gender.isValidGender(trimmedGender)) {
throw new ParseException(Gender.MESSAGE_CONSTRAINTS);
}
return new Gender(trimmedGender);
}

/**
* Parses a {@code String lovebook} into an {@code Height}.
* Leading and trailing whitespaces will be trimmed.
Expand All @@ -81,20 +97,21 @@ public static Height parseAddress(String height) throws ParseException {
}

/**
* Parses a {@code String gender} into an {@code Gender}.
* Parses a {@code String income} into an {@code Income}.
* Leading and trailing whitespaces will be trimmed.
*
* @throws ParseException if the given {@code gender} is invalid.
* @throws ParseException if the given {@code lovebook} is invalid.
*/
public static Gender parseGender(String gender) throws ParseException {
requireNonNull(gender);
String trimmedGender = gender.trim();
if (!Gender.isValidGender(trimmedGender)) {
throw new ParseException(Gender.MESSAGE_CONSTRAINTS);
public static Income parseIncome(String income) throws ParseException {
requireNonNull(income);
String trimmedIncome = income.trim();
if (!Height.isValidHeight(trimmedIncome)) {
throw new ParseException(Income.MESSAGE_CONSTRAINTS);
}
return new Gender(trimmedGender);
return new Income(income);
}


/**
* Parses a {@code String tag} into a {@code Tag}.
* Leading and trailing whitespaces will be trimmed.
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/seedu/lovebook/model/person/Date.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,20 @@ public class Date {

// Data fields
private final Height height;

private final Income income;
private final Set<Tag> tags = new HashSet<>();

/**
* Every field must be present and not null.
*/
public Date(Name name, Age age, Gender gender, Height height, Set<Tag> tags) {
public Date(Name name, Age age, Gender gender, Height height, Income income, Set<Tag> tags) {
requireAllNonNull(name, age, gender, height, tags);
this.name = name;
this.age = age;
this.gender = gender;
this.height = height;
this.income = income;
this.tags.addAll(tags);
}

Expand All @@ -45,6 +48,7 @@ public Date() {
this.age = null;
this.gender = null;
this.height = null;
this.income = null;
}

public Name getName() {
Expand All @@ -63,6 +67,10 @@ public Height getHeight() {
return height;
}

public Income getIncome() {
return income;
}

/**
* Returns an immutable tag set, which throws {@code UnsupportedOperationException}
* if modification is attempted.
Expand Down Expand Up @@ -104,13 +112,14 @@ public boolean equals(Object other) {
&& age.equals(otherDate.age)
&& gender.equals(otherDate.gender)
&& height.equals(otherDate.height)
&& income.equals(otherDate.income)
&& tags.equals(otherDate.tags);
}

@Override
public int hashCode() {
// use this method for custom fields hashing instead of implementing your own
return Objects.hash(name, age, gender, height, tags);
return Objects.hash(name, age, gender, height, income, tags);
}

@Override
Expand All @@ -120,6 +129,7 @@ public String toString() {
.add("age", age)
.add("gender", gender)
.add("height", height)
.add("income", income)
.add("tags", tags)
.toString();
}
Expand Down
Loading

0 comments on commit 307153c

Please sign in to comment.