Skip to content

Commit

Permalink
Merge pull request AY2324S1-CS2103T-T13-0#92 from rocketninja7/model
Browse files Browse the repository at this point in the history
Add modular credit
  • Loading branch information
ji-just-ji authored Oct 12, 2023
2 parents 45b6dc4 + 44167c2 commit bcf0ea7
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 2 deletions.
55 changes: 55 additions & 0 deletions src/main/java/seedu/address/model/module/ModularCredit.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
10 changes: 8 additions & 2 deletions src/main/java/seedu/address/model/module/Module.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Lecturer> lecturers) {
Description description, Set<Lecturer> lecturers, ModularCredit modularCredit) {
requireAllNonNull(name, moduleCode, description, lecturers, yearTaken, semesterTaken, grade);
this.moduleName = name;
this.moduleCode = moduleCode;
Expand All @@ -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);
Expand All @@ -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;
}
Expand All @@ -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.
Expand Down

0 comments on commit bcf0ea7

Please sign in to comment.