Skip to content

Commit

Permalink
Merge pull request #146 from cadencjk/add-owed-warning
Browse files Browse the repository at this point in the history
Add warning for students who owe money in ScheduleList
  • Loading branch information
cadencjk authored Oct 16, 2022
2 parents 9f7a251 + ec5b6ac commit c58d92b
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/main/java/seedu/address/model/person/Money.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,23 @@ public Money() {

/**
* Validates whether amount is valid.
*
* @param amount the value to be validated
* @return true if a given integer is non-negative
*/
public static boolean isValidMoney(Integer amount) {
return amount >= 0;
}

/**
* Validates whether amount is more than zero.
*
* @return true if amount is positive
*/
public boolean isGreaterThanZero() {
return value > 0;
}

@Override
public String toString() {
return value.toString();
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/seedu/address/model/person/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,15 @@ public boolean isSamePerson(Person otherPerson) {
&& otherPerson.getPhone().equals(getPhone());
}

/**
* Determines whether the person is owing money.
*
* @return true if the person is owing money
*/
public boolean isOwingMoney() {
return moneyOwed.isGreaterThanZero();
}

/**
* Returns true if both persons have the same identity and data fields.
* This defines a stronger notion of equality between two persons.
Expand Down
18 changes: 17 additions & 1 deletion src/main/java/seedu/address/ui/ScheduleCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
public class ScheduleCard extends UiPart<Region> {

private static final String FXML = "ScheduleListCard.fxml";
private static final String COLOUR_OF_DEBTOR = "-fx-text-fill: #FF0000;";

/**
* Note: Certain keywords such as "location" and "resources" are reserved keywords in JavaFX.
Expand Down Expand Up @@ -42,12 +43,27 @@ public ScheduleCard(Person person, int displayedIndex) {
super(FXML);
this.person = person;
id.setText(displayedIndex + ". ");
name.setText(person.getName().fullName);
setWarningIfOwed(person);
phone.setText(person.getPhone().value);
address.setText(person.getAddress().value);
classTime.setText(person.getAClass().toTimeString());
}

/**
* Sets off warning indication if the person owes money.
*
* @param person to check whether he/she is a debtor
*/
private void setWarningIfOwed(Person person) {
if (person.isOwingMoney()) {
String nameWithAmount = person.getName().fullName + " - To collect $" + person.getMoneyOwed().value;
name.setText(nameWithAmount);
name.setStyle(COLOUR_OF_DEBTOR);
} else {
name.setText(person.getName().fullName);
}
}

@Override
public boolean equals(Object other) {
// short circuit if same object
Expand Down
9 changes: 9 additions & 0 deletions src/test/java/seedu/address/model/person/MoneyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,13 @@ public void isValidMoneyTest() {
assertTrue(Money.isValidMoney(1234)); // multiple digits positive number
assertTrue(Money.isValidMoney(0)); // zero
}

@Test
public void isGreaterThanZeroTest() {
Money moneyWithZeroAmount = new Money(0);
assertFalse(moneyWithZeroAmount.isGreaterThanZero());

Money moneyWithPositiveAmount = new Money(50);
assertTrue(moneyWithPositiveAmount.isGreaterThanZero());
}
}
10 changes: 10 additions & 0 deletions src/test/java/seedu/address/model/person/PersonTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_HUSBAND;
import static seedu.address.testutil.Assert.assertThrows;
import static seedu.address.testutil.TypicalPersons.ALICE;
import static seedu.address.testutil.TypicalPersons.AVA;
import static seedu.address.testutil.TypicalPersons.BOB;

import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -101,4 +102,13 @@ public void execute_setClassSuccess() {
assertEquals(person.getAClass().classDateTime, "");
}

@Test
public void owesMoneyTest() {
Person debtor = AVA;
assertTrue(debtor.isOwingMoney());

Person nonDebtor = new PersonBuilder(AVA).withMoneyOwed(0).build();
assertFalse(nonDebtor.isOwingMoney());
}

}

0 comments on commit c58d92b

Please sign in to comment.