From b18a3fde925550f5c310307dd95d5890cccb957e Mon Sep 17 00:00:00 2001 From: nixonwidjaja Date: Fri, 13 Oct 2023 00:30:15 +0800 Subject: [PATCH] Fix bugs --- .../logic/parser/ClaimCommandParser.java | 1 + .../seedu/address/model/person/Birthday.java | 19 +++++++++++-------- .../seedu/address/model/person/Money.java | 11 ++++------- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/main/java/seedu/address/logic/parser/ClaimCommandParser.java b/src/main/java/seedu/address/logic/parser/ClaimCommandParser.java index cbb1b77f43a..7104523a016 100644 --- a/src/main/java/seedu/address/logic/parser/ClaimCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/ClaimCommandParser.java @@ -29,6 +29,7 @@ public class ClaimCommandParser implements Parser { public ClaimCommand parse(String args) throws ParseException { requireNonNull(args); ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_CLAIM_AMOUNT); + argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_CLAIM_AMOUNT); Index index; Claim claim; diff --git a/src/main/java/seedu/address/model/person/Birthday.java b/src/main/java/seedu/address/model/person/Birthday.java index e3046502db9..4eea830d552 100644 --- a/src/main/java/seedu/address/model/person/Birthday.java +++ b/src/main/java/seedu/address/model/person/Birthday.java @@ -1,17 +1,20 @@ package seedu.address.model.person; import static java.util.Objects.requireNonNull; +import static seedu.address.commons.util.AppUtil.checkArgument; import java.time.DateTimeException; import java.time.LocalDate; import java.time.format.DateTimeFormatter; +import java.time.temporal.ChronoUnit; /** * Represents a Person's dob. */ public class Birthday { public static final String MESSAGE_CONSTRAINTS = - "Invalid date of birth. Please provide date of birth with format: YYYY-MM-DD"; + "Invalid date of birth. Please provide date of birth with format: YYYY-MM-DD.\n" + + "An employee must be at least 13 years old."; public final String dob; @@ -23,12 +26,8 @@ public class Birthday { public Birthday(String dateStr) { requireNonNull(dateStr); dateStr = dateStr.trim(); - try { - LocalDate.parse(dateStr); - dob = dateStr; - } catch (DateTimeException e) { - throw new IllegalArgumentException(MESSAGE_CONSTRAINTS); - } + checkArgument(isValidDob(dateStr), MESSAGE_CONSTRAINTS); + dob = dateStr; } /** @@ -37,7 +36,11 @@ public Birthday(String dateStr) { public static boolean isValidDob(String test) { String dateStr = test.trim(); try { - LocalDate.parse(dateStr); + LocalDate birthday = LocalDate.parse(dateStr); + LocalDate legalBirthday = LocalDate.now().minusYears(13); + if (legalBirthday.until(birthday, ChronoUnit.DAYS) > 0) { + return false; + } } catch (DateTimeException e) { return false; } diff --git a/src/main/java/seedu/address/model/person/Money.java b/src/main/java/seedu/address/model/person/Money.java index 691a70b204f..31756f940d0 100644 --- a/src/main/java/seedu/address/model/person/Money.java +++ b/src/main/java/seedu/address/model/person/Money.java @@ -21,13 +21,7 @@ public class Money { */ public Money(String numStr) { requireNonNull(numStr); - checkArgument(numStr.length() < 14, MESSAGE_CONSTRAINTS); - try { - Long num = Long.valueOf(numStr); - checkArgument(num >= 0 && num <= MAX_VALUE, MESSAGE_CONSTRAINTS); - } catch (NumberFormatException e) { - throw new IllegalArgumentException(MESSAGE_CONSTRAINTS); - } + checkArgument(isValidMoney(numStr), MESSAGE_CONSTRAINTS); amount = numStr; } @@ -35,6 +29,9 @@ public Money(String numStr) { * Returns true if a given string is a valid dollar amount. */ public static boolean isValidMoney(String test) { + if (test.length() >= 14) { + return false; + } try { Long num = Long.valueOf(test); return num >= 0 && num <= MAX_VALUE;