Skip to content
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

Changed constraints for subject #146

Merged
merged 1 commit into from
Apr 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/main/java/seedu/address/model/student/Subject.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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.
Expand All @@ -34,7 +38,7 @@ public static boolean isValidSubject(String test) {

@Override
public String toString() {
return value;
return this.value;
}

@Override
Expand Down
Loading