From a3d94121ec5aa59f371bb4510f417deeaaedc9a8 Mon Sep 17 00:00:00 2001 From: Chia Rena Date: Sun, 14 Apr 2024 13:57:09 +0800 Subject: [PATCH] Changed constraints for subject --- src/main/java/seedu/address/model/student/Subject.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/seedu/address/model/student/Subject.java b/src/main/java/seedu/address/model/student/Subject.java index b758d9fd8f6..693767fa99e 100644 --- a/src/main/java/seedu/address/model/student/Subject.java +++ b/src/main/java/seedu/address/model/student/Subject.java @@ -11,7 +11,7 @@ public class Subject { public static final String MESSAGE_CONSTRAINTS = "Subjects can only take alphanumeric values and spaces, and it should not be blank"; - public static final String VALIDATION_REGEX = "^[A-Z][a-zA-Z ]*$"; + public static final String VALIDATION_REGEX = "^[A-Za-z][a-zA-Z ]*$"; public final String value; @@ -22,8 +22,12 @@ public class Subject { */ public Subject(String subject) { requireNonNull(subject); + if (subject.trim().isEmpty()) { + throw new IllegalArgumentException(MESSAGE_CONSTRAINTS); + } + String formattedSubject = subject.substring(0, 1).toUpperCase() + subject.substring(1).toLowerCase(); checkArgument(isValidSubject(subject), MESSAGE_CONSTRAINTS); - value = subject; + this.value = formattedSubject; } /** * Returns true if a given string is a valid subject. @@ -34,7 +38,7 @@ public static boolean isValidSubject(String test) { @Override public String toString() { - return value; + return this.value; } @Override