Skip to content

Commit

Permalink
Update CalculateCAP command
Browse files Browse the repository at this point in the history
  • Loading branch information
yyyaohhh committed Oct 24, 2023
1 parent 6cb1f9c commit 690f646
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ public class CalculateCapCommand extends Command {
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);

int modularCredits = model.totalModularCredits();

Float gradePointsByUnits = model.totalGradePointsByUnits();

Float calculatedCapValue = gradePointsByUnits / modularCredits;
Float calculatedCapValue = model.CAP();

return new CommandResult(String.format(MESSAGE_CALCULATION_SUCCESS, calculatedCapValue));
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/seedu/address/model/AddressBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ public int totalModularCredits() {
/**
* Calculates and returns the total grade points weighted by modular credits of all modules in the collection.
*
* @return The total grade points weighted by modular credits of all modules in the collection as a float.
* @return The total grade points weighted by modular credits of all modules in the collection as a floating-point number.
*/
public Float totalGradePointsByUnits() {
return modules.gradePointsWithUnits();
public Float totalGradePointsWithUnits() {
return modules.findGradePointsWithUnits();
}

//// util methods
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/seedu/address/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ public interface Model {
int totalModularCredits();

/**
* Calculates and returns the total grade points weighted by modular credits of all modules.
* Calculates and returns the Cumulative Average Point (CAP) for a collection of semesters.
*
* @return The total grade points weighted by modular credits as a floating-point number.
* @return The CAP (Cumulative Average Point) as a floating-point number based on the cumulative performance of multiple semesters.
*/
Float totalGradePointsByUnits();
Float CAP();

/** Returns an unmodifiable view of the filtered person list */
ObservableList<ModulePlanSemester> getFilteredModuleList();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ public int totalModularCredits() {
}

@Override
public Float totalGradePointsByUnits() {
return modulePlan.totalGradePointsByUnits();
public Float CAP() {
return modulePlan.CAP();
}

//=========== Filtered Person List Accessors =============================================================
Expand Down
27 changes: 23 additions & 4 deletions src/main/java/seedu/address/model/module/UniqueModuleList.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,20 +136,39 @@ public int modularCredits() {
}

/**
* Calculates the total grade points weighted by the modular credits of all modules in the internal list.
* Calculates and returns the Cumulative Average Point (CAP) based on the grades and modular credits of all modules in the internal list.
*
* @return The total grade points weighted by modular credits as a floating-point number.
* @return The CAP (Cumulative Average Point) as a floating-point number, or 0.0 if there are no valid grades.
*/
public Float gradePointsWithUnits() {
public Float findGradePointsWithUnits() {
Module[] mods = new Module[internalList.size()];
mods = internalList.toArray(mods);
float gradePoints = 0;
for (int i = 0; i < internalList.size(); i++) {
gradePoints += mods[i].getGrade().gradePoint() * mods[i].getModularCredit().hashCode();
if (mods[i].getGrade().gradePoint() != null) {
gradePoints += mods[i].getGrade().gradePoint() * mods[i].getModularCredit().hashCode();
}
}
return gradePoints;
}

/**
* Calculates and returns the total modular credits of modules with valid grades in the internal list.
*
* @return The total modular credits of modules with valid grades as a floating-point number.
*/
public float findMCsForCAP() {
Module[] mods = new Module[internalList.size()];
mods = internalList.toArray(mods);
float MCs = 0;
for (int i = 0; i < internalList.size(); i++) {
if (mods[i].getGrade().gradePoint() != null) {
MCs += mods[i].getModularCredit().hashCode();
}
}
return MCs;
}

/**
* Returns the backing list as an unmodifiable {@code ObservableList}.
*/
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/seedu/address/model/moduleplan/ModulePlan.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,12 @@ public int totalModularCredits() {
}

/**
* Calculates and returns the total grade points weighted by modular credits of all modules in the collection.
* Calculates and returns the Cumulative Average Point (CAP) for a collection of semesters.
*
* @return The total grade points weighted by modular credits of all modules in the collection as a float.
* @return The CAP (Cumulative Average Point) as a floating-point number based on the cumulative performance of multiple semesters.
*/
public Float totalGradePointsByUnits() {
return semesters.gradePointsWithUnits();
public Float CAP() {
return semesters.CAP();
}

//// util methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,19 @@ public int totalModularCredits() {
/**
* Calculates and returns the total grade points weighted by modular credits of all modules in the collection.
*
* @return The total grade points weighted by modular credits of all modules in the collection as a float.
* @return The total grade points weighted by modular credits of all modules in the collection as a floating-point number.
*/
public Float totalGradePointsByUnits() {
return modules.gradePointsWithUnits();
public Float totalGradePointsWithUnits() {
return modules.findGradePointsWithUnits();
}

/**
* Calculates and returns the total modular credits of modules with valid grades in the collection.
*
* @return The total modular credits of modules with valid grades as a floating-point number.
*/
public Float totalValidMCs() {
return modules.findMCsForCAP();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public class ModulePlanSemesterList implements Iterable<ModulePlanSemester> {

/// semester functions


/**
* Replaces the contents of this list with {@code semesters}.
* {@code semesters} must not contain duplicate semesters.
Expand Down Expand Up @@ -101,7 +100,6 @@ public void removeSemester(ModulePlanSemester semester) {

}


//// modules functions

/**
Expand Down Expand Up @@ -177,8 +175,6 @@ public void removeModule(Module toRemove) {

}



/**
* Finds and returns the module with the specified module code.
*
Expand Down Expand Up @@ -210,19 +206,23 @@ public int modularCredits() {
}

/**
* Calculates the total grade points weighted by the modular credits of all modules in the internal list.
* Calculates and returns the overall Cumulative Average Point (CAP) for a collection of modules.
*
* @return The total grade points weighted by modular credits as a floating-point number.
* @return The overall CAP (Cumulative Average Point) as a floating-point number.
*/
public Float gradePointsWithUnits() {
public Float CAP() {
float gradePoints = 0;
float MCs = 0;
for (int i = 0; i < internalList.size(); i++) {
gradePoints += internalList.get(i).totalGradePointsByUnits();
gradePoints += internalList.get(i).totalGradePointsWithUnits();
MCs += internalList.get(i).totalValidMCs();
}
return gradePoints;
}


if (MCs == 0) {
return 0f;
}
return gradePoints / MCs;
}

/**
* Returns the backing list as an unmodifiable {@code ObservableList}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public int totalModularCredits() {
}

@Override
public Float totalGradePointsByUnits() {
public Float CAP() {
throw new AssertionError("This method should not be called.");
}

Expand Down

0 comments on commit 690f646

Please sign in to comment.