forked from nus-cs2103-AY2324S2/tp
-
Notifications
You must be signed in to change notification settings - Fork 3
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
Add Grade Parameter to Person #42
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b41a27f
Update use cases in Developer Guide
joelgoh1 81f7d02
Correcting for PR comments
joelgoh1 ea1af37
Add grade parameter to person
joelgoh1 0e01d9b
Merge remote-tracking branch 'upstream/master'
joelgoh1 14c2f26
Merge branch 'AddGradeParameter'
joelgoh1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,82 @@ | ||
package seedu.address.model.grade; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.commons.util.AppUtil.checkArgument; | ||
|
||
import java.util.Objects; | ||
/** | ||
* Represents a Person's Grade in the address book. | ||
* Guarantees: immutable; is valid as declared in {@link #isValidGrade(String)} | ||
*/ | ||
public class Grade { | ||
|
||
public static final String MESSAGE_CONSTRAINTS = "Grades should be of the format Test: Grade " | ||
+ "and adhere to the following constraints:\n" | ||
+ "1. The Test name should not be empty" | ||
+ "2. This is followed by a ': ' and then a grade. \n" | ||
+ "The grade must:\n" | ||
+ " - represent the percentage gotten in the test rounded to the nearest whole number\n" | ||
+ " - be between [0, 100]\n"; | ||
|
||
/* | ||
* The first character of the test name must not be a whitespace, | ||
* otherwise " " (a blank string) becomes a valid input. | ||
* Grade should be an integer ranging from 0-100, representing the percentage. | ||
*/ | ||
public static final String TEST_NAME_VALIDATION_REGEX = ".+?"; | ||
public static final String GRADE_VALIDATION_REGEX = "(100|[1-9]?[0-9])$"; | ||
|
||
public static final String VALIDATION_REGEX = TEST_NAME_VALIDATION_REGEX + ":\\s*" + GRADE_VALIDATION_REGEX; | ||
|
||
public final String testAndGrade; | ||
public final String testName; | ||
public final String grade; | ||
|
||
/** | ||
* Constructs an {@code Grade}. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
* | ||
* @param testAndGrade A valid testAndGrade. | ||
*/ | ||
public Grade(String testAndGrade) { | ||
requireNonNull(testAndGrade); | ||
checkArgument(isValidGrade(testAndGrade.trim()), MESSAGE_CONSTRAINTS); | ||
String[] parts = testAndGrade.split(":", 2); | ||
this.testName = parts[0].trim(); | ||
this.grade = parts[1].trim(); | ||
this.testAndGrade = testAndGrade; | ||
} | ||
|
||
/** | ||
* Returns true if a given string is a valid grade. | ||
*/ | ||
public static boolean isValidGrade(String test) { | ||
return test.matches(VALIDATION_REGEX); | ||
} | ||
|
||
|
||
@Override | ||
public String toString() { | ||
return testName + ": " + grade; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof Grade)) { | ||
return false; | ||
} | ||
|
||
Grade otherGrade = (Grade) other; | ||
return testName.equals(otherGrade.testName) && grade.equals(otherGrade.grade); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(testName, grade); | ||
} | ||
|
||
} |
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 |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
|
||
import seedu.address.model.AddressBook; | ||
import seedu.address.model.ReadOnlyAddressBook; | ||
import seedu.address.model.grade.Grade; | ||
import seedu.address.model.person.Address; | ||
import seedu.address.model.person.Email; | ||
import seedu.address.model.person.Name; | ||
|
@@ -21,22 +22,22 @@ | |
return new Person[] { | ||
new Person(new Name("Alex Yeoh"), new Phone("87438807"), new Email("[email protected]"), | ||
new Address("Blk 30 Geylang Street 29, #06-40"), | ||
getTagSet("friends")), | ||
getTagSet("friends"), getGradeSet("ca1: 90")), | ||
new Person(new Name("Bernice Yu"), new Phone("99272758"), new Email("[email protected]"), | ||
new Address("Blk 30 Lorong 3 Serangoon Gardens, #07-18"), | ||
getTagSet("colleagues", "friends")), | ||
getTagSet("colleagues", "friends"), getGradeSet("ca1: 50", "ca2: 80")), | ||
new Person(new Name("Charlotte Oliveiro"), new Phone("93210283"), new Email("[email protected]"), | ||
new Address("Blk 11 Ang Mo Kio Street 74, #11-04"), | ||
getTagSet("neighbours")), | ||
getTagSet("neighbours"), getGradeSet("eoy: 70")), | ||
new Person(new Name("David Li"), new Phone("91031282"), new Email("[email protected]"), | ||
new Address("Blk 436 Serangoon Gardens Street 26, #16-43"), | ||
getTagSet("family")), | ||
getTagSet("family"), getGradeSet("midterms: 0")), | ||
new Person(new Name("Irfan Ibrahim"), new Phone("92492021"), new Email("[email protected]"), | ||
new Address("Blk 47 Tampines Street 20, #17-35"), | ||
getTagSet("classmates")), | ||
getTagSet("classmates"), getGradeSet("finals: 100")), | ||
new Person(new Name("Roy Balakrishnan"), new Phone("92624417"), new Email("[email protected]"), | ||
new Address("Blk 45 Aljunied Street 85, #11-31"), | ||
getTagSet("colleagues")) | ||
getTagSet("colleagues"), getGradeSet("ca2: 39")) | ||
}; | ||
} | ||
|
||
|
@@ -57,4 +58,13 @@ | |
.collect(Collectors.toSet()); | ||
} | ||
|
||
/** | ||
* Returns a grade set containing the list of strings given. | ||
*/ | ||
public static Set<Grade> getGradeSet(String... strings) { | ||
return Arrays.stream(strings) | ||
.map(Grade::new) | ||
.collect(Collectors.toSet()); | ||
} | ||
|
||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Styling) Extra line here can be removed