diff --git a/src/main/java/seedu/address/model/module/ModularCredit.java b/src/main/java/seedu/address/model/module/ModularCredit.java new file mode 100644 index 00000000000..e3bb8acc0ea --- /dev/null +++ b/src/main/java/seedu/address/model/module/ModularCredit.java @@ -0,0 +1,55 @@ +package seedu.address.model.module; + +import static java.util.Objects.requireNonNull; +import static seedu.address.commons.util.AppUtil.checkArgument; + +public class ModularCredit { + public static final String MESSAGE_CONSTRAINTS = "Modular credits should be a non-negative integer."; + + public static final String VALIDATION_REGEX = "^[\\p{Digit}]+$"; + + private int modularCredit; + + /** + * Constructs a {@code ModularCredit}. + * + * @param modularCredit A valid modular credit. + */ + public ModularCredit(String modularCredit) { + requireNonNull(modularCredit); + checkArgument(isValidModularCredit(modularCredit), MESSAGE_CONSTRAINTS); + this.modularCredit = Integer.parseInt(modularCredit); + } + + /** + * Returns if a given string is a valid email. + */ + public static boolean isValidModularCredit(String test) { + return test.matches(VALIDATION_REGEX); + } + + @Override + public String toString() { + return String.valueOf(modularCredit); + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + + // instanceof handles nulls + if (!(other instanceof ModularCredit)) { + return false; + } + + ModularCredit otherModularCredit = (ModularCredit) other; + return modularCredit == otherModularCredit.modularCredit; + } + + @Override + public int hashCode() { + return modularCredit; + } +} diff --git a/src/main/java/seedu/address/model/module/Module.java b/src/main/java/seedu/address/model/module/Module.java index 5587387146c..32f97a9e0a5 100644 --- a/src/main/java/seedu/address/model/module/Module.java +++ b/src/main/java/seedu/address/model/module/Module.java @@ -20,12 +20,13 @@ public class Module { private final Year yearTaken; private final Semester semesterTaken; private final Grade grade; + private final ModularCredit modularCredit; /** * Every field must be present and not null. */ public Module(ModuleCode moduleCode, Year yearTaken, Semester semesterTaken, Grade grade, ModuleName name, - Description description, Set lecturers) { + Description description, Set lecturers, ModularCredit modularCredit) { requireAllNonNull(name, moduleCode, description, lecturers, yearTaken, semesterTaken, grade); this.moduleName = name; this.moduleCode = moduleCode; @@ -34,6 +35,7 @@ public Module(ModuleCode moduleCode, Year yearTaken, Semester semesterTaken, Gr this.yearTaken = yearTaken; this.semesterTaken = semesterTaken; this.grade = grade; + this.modularCredit = modularCredit; } public Module(ModuleCode moduleCode, Year year, Semester semester, Grade grade) { requireAllNonNull(moduleCode, year, semester, grade); @@ -45,13 +47,13 @@ public Module(ModuleCode moduleCode, Year year, Semester semester, Grade grade) this.moduleName = null; this.description = null; this.lecturers = null; + this.modularCredit = null; } public ModuleName getName() { return moduleName; } - public ModuleCode getModuleCode() { return moduleCode; } @@ -76,6 +78,10 @@ public Grade getGrade() { return grade; } + public ModularCredit getModularCredit() { + return modularCredit; + } + /** * Checks if two modules are the same module. * @param otherModule the other module to check.