forked from nus-cs2103-AY2425S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 7
Add fee #141
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
Merged
Merged
Add fee #141
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fa0cfa1
In progress
192285d
Merge conflict
50b8238
Merge branch 'master' of https://github.com/obrona/tp into origin-master
853515d
Make more changes to add Fee
a611af7
Fix the test cases
b252d67
Fix test cases
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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
import static java.util.Objects.requireNonNull; | ||
import static seedu.edulog.logic.parser.CliSyntax.PREFIX_ADDRESS; | ||
import static seedu.edulog.logic.parser.CliSyntax.PREFIX_EMAIL; | ||
import static seedu.edulog.logic.parser.CliSyntax.PREFIX_FEE; | ||
import static seedu.edulog.logic.parser.CliSyntax.PREFIX_NAME; | ||
import static seedu.edulog.logic.parser.CliSyntax.PREFIX_PHONE; | ||
import static seedu.edulog.logic.parser.CliSyntax.PREFIX_TAG; | ||
|
@@ -33,7 +34,8 @@ public class AddCommand extends Command { | |
+ PREFIX_EMAIL + "[email protected] " | ||
+ PREFIX_ADDRESS + "311, Clementi Ave 2, #02-25 " | ||
+ PREFIX_TAG + "friends " | ||
+ PREFIX_TAG + "owesMoney"; | ||
+ PREFIX_TAG + "owesMoney " | ||
+ PREFIX_FEE + "100"; | ||
|
||
public static final String MESSAGE_SUCCESS = "New student added: %1$s"; | ||
public static final String MESSAGE_DUPLICATE_STUDENT = "This student already exists in the edulog book"; | ||
|
This file contains hidden or 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 |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
import static java.util.Objects.requireNonNull; | ||
import static seedu.edulog.logic.parser.CliSyntax.PREFIX_ADDRESS; | ||
import static seedu.edulog.logic.parser.CliSyntax.PREFIX_EMAIL; | ||
import static seedu.edulog.logic.parser.CliSyntax.PREFIX_FEE; | ||
import static seedu.edulog.logic.parser.CliSyntax.PREFIX_NAME; | ||
import static seedu.edulog.logic.parser.CliSyntax.PREFIX_PHONE; | ||
import static seedu.edulog.logic.parser.CliSyntax.PREFIX_TAG; | ||
|
@@ -23,6 +24,7 @@ | |
import seedu.edulog.model.Model; | ||
import seedu.edulog.model.student.Address; | ||
import seedu.edulog.model.student.Email; | ||
import seedu.edulog.model.student.Fee; | ||
import seedu.edulog.model.student.Name; | ||
import seedu.edulog.model.student.Phone; | ||
import seedu.edulog.model.student.Student; | ||
|
@@ -46,7 +48,8 @@ | |
+ "[" + PREFIX_TAG + "TAG]...\n" | ||
+ "Example: " + COMMAND_WORD + " 1 " | ||
+ PREFIX_PHONE + "91234567 " | ||
+ PREFIX_EMAIL + "[email protected]"; | ||
+ PREFIX_EMAIL + "[email protected] " | ||
+ PREFIX_FEE + "1000"; | ||
|
||
public static final String MESSAGE_EDIT_STUDENT_SUCCESS = "Edited Student: %1$s"; | ||
public static final String MESSAGE_NOT_EDITED = "At least one field to edit must be provided."; | ||
|
@@ -100,8 +103,17 @@ | |
Email updatedEmail = editStudentDescriptor.getEmail().orElse(studentToEdit.getEmail()); | ||
Address updatedAddress = editStudentDescriptor.getAddress().orElse(studentToEdit.getAddress()); | ||
Set<Tag> updatedTags = editStudentDescriptor.getTags().orElse(studentToEdit.getTags()); | ||
Fee fee = editStudentDescriptor.getFee().orElse(studentToEdit.getFee()); | ||
|
||
Student result = new Student(updatedName, updatedPhone, updatedEmail, updatedAddress, | ||
updatedTags, fee); | ||
if (studentToEdit.getHasPaid()) { | ||
result.mark(); | ||
} else { | ||
result.unmark(); | ||
} | ||
|
||
return new Student(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedTags); | ||
return result; | ||
} | ||
|
||
@Override | ||
|
@@ -138,6 +150,7 @@ | |
private Email email; | ||
private Address address; | ||
private Set<Tag> tags; | ||
private Fee fee; | ||
|
||
public EditStudentDescriptor() {} | ||
|
||
|
@@ -151,13 +164,14 @@ | |
setEmail(toCopy.email); | ||
setAddress(toCopy.address); | ||
setTags(toCopy.tags); | ||
setFee(toCopy.fee); | ||
} | ||
|
||
/** | ||
* Returns true if at least one field is edited. | ||
*/ | ||
public boolean isAnyFieldEdited() { | ||
return CollectionUtil.isAnyNonNull(name, phone, email, address, tags); | ||
return CollectionUtil.isAnyNonNull(name, phone, email, address, tags, fee); | ||
} | ||
|
||
public void setName(Name name) { | ||
|
@@ -209,6 +223,14 @@ | |
return (tags != null) ? Optional.of(Collections.unmodifiableSet(tags)) : Optional.empty(); | ||
} | ||
|
||
public void setFee(Fee fee) { | ||
this.fee = fee; | ||
} | ||
|
||
public Optional<Fee> getFee() { | ||
return Optional.ofNullable(fee); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
|
@@ -225,7 +247,8 @@ | |
&& Objects.equals(phone, otherEditStudentDescriptor.phone) | ||
&& Objects.equals(email, otherEditStudentDescriptor.email) | ||
&& Objects.equals(address, otherEditStudentDescriptor.address) | ||
&& Objects.equals(tags, otherEditStudentDescriptor.tags); | ||
&& Objects.equals(tags, otherEditStudentDescriptor.tags) | ||
&& Objects.equals(fee, otherEditStudentDescriptor.fee); | ||
} | ||
|
||
@Override | ||
|
@@ -236,6 +259,7 @@ | |
.add("email", email) | ||
.add("edulog", address) | ||
.add("tags", tags) | ||
.add("fee", fee) | ||
.toString(); | ||
} | ||
} | ||
|
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,57 @@ | ||
package seedu.edulog.model.student; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
/** | ||
* Represents a student tuition fee | ||
*/ | ||
public class Fee { | ||
public static final String MESSAGE_CONSTRAINTS = "Fee should only contain digits."; | ||
public static final String VALIDATION_REGEX = "^\\d+$"; | ||
|
||
public final int value; | ||
|
||
|
||
public Fee(String fee) { | ||
this.value = Integer.parseInt(fee); | ||
} | ||
|
||
public Fee(int fee) { | ||
this.value = fee; | ||
} | ||
|
||
/** | ||
* Return true if test is a valid string to parse | ||
*/ | ||
public static boolean isValidFee(String test) { | ||
requireNonNull(test); | ||
return test.matches(VALIDATION_REGEX); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return Integer.toString(value); | ||
} | ||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
if (!(other instanceof Fee)) { | ||
return false; | ||
} | ||
|
||
Fee otherFee = (Fee) other; | ||
return otherFee.value == this.value; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return value; | ||
} | ||
|
||
public String getFormattedString() { | ||
return toString(); | ||
} | ||
} |
This file contains hidden or 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 |
---|---|---|
|
@@ -25,9 +25,11 @@ | |
private final seedu.edulog.model.student.Address address; | ||
private final Set<Tag> tags = new HashSet<>(); | ||
private boolean hasPaid = false; | ||
private final Fee fee; | ||
|
||
/** | ||
* Every field must be present and not null except isPresent. | ||
* Every field must be present and not null except isPresent. I suggest | ||
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. please deprecate this constructor |
||
* we keep this constructor so that we do not break all the test cases | ||
*/ | ||
public Student(Name name, Phone phone, Email email, Address address, Set<Tag> tags) { | ||
requireAllNonNull(name, phone, email, address, tags); | ||
|
@@ -37,6 +39,22 @@ | |
this.address = address; | ||
this.tags.addAll(tags); | ||
this.hasPaid = false; | ||
this.fee = new Fee(100); | ||
|
||
} | ||
|
||
/** | ||
* New constructor with Fee | ||
*/ | ||
public Student(Name name, Phone phone, Email email, Address address, Set<Tag> tags, Fee fee) { | ||
requireAllNonNull(name, phone, email, address, tags); | ||
this.name = name; | ||
this.phone = phone; | ||
this.email = email; | ||
this.address = address; | ||
this.tags.addAll(tags); | ||
this.fee = fee; | ||
this.hasPaid = false; | ||
} | ||
|
||
public Name getName() { | ||
|
@@ -72,6 +90,10 @@ | |
return hasPaid; | ||
} | ||
|
||
public Fee getFee() { | ||
return fee; | ||
} | ||
|
||
/** | ||
* Marks the student as paid. | ||
*/ | ||
|
@@ -120,7 +142,8 @@ | |
&& email.equals(otherStudent.email) | ||
&& address.equals(otherStudent.address) | ||
&& tags.equals(otherStudent.tags) | ||
&& hasPaid == otherStudent.hasPaid; | ||
&& hasPaid == otherStudent.hasPaid | ||
&& fee.equals(otherStudent.fee); | ||
} | ||
|
||
@Override | ||
|
@@ -138,6 +161,7 @@ | |
.add("edulog", address) | ||
.add("tags", tags) | ||
.add("hasPaid", hasPaid) | ||
.add("fee", fee) | ||
.toString(); | ||
} | ||
|
||
|
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.
please add this to previous line