I am seeking a review of a previous project I completed in my first term at university. The submission was graded 18/20 however the feedback was minimal and gave no suggestions regarding further improvements.
The specification prohibited the use of any non-primitive data types.
Concise problem specification:
Students take 6 modules in Stage 1. Each module has two components - Exam and Coursework and each module can have a different mark for each. The returned mark for a module is calculated as follows:
computed module mark = ((coursework mark * coursework weighting) + (examination mark * (100 - coursework weighting))) / 100
If the exam mark and coursework mark are greater than or equal to 35 then the returned mark is the computed module mark. However, if either (or both) the exam or coursework mark is less than 35 then the returned mark is the minimum(35, computed module mark).
All marks are rounded to the nearest whole number.
The student's performance on a given module can then be recorded as one of:
- Pass, if the module mark is at least 40
- Compensatable Fail, if the module mark is less than 40 but at least 35
- Fail, otherwise
Once all the module marks have been determined, a Stage average may be computed. This is found by averaging the returned module marks. The Stage result can then be computed as:
- Pass, if all modules are recorded as a Pass
- Pass By Compensation, if the Stage average is at least 40, no module is recorded as a Fail, and there are one or two modules totalling at most 40 credits recorded as a Compensatable Fail.
- Fail, otherwise
The submission is required to produce a clear formatted output showing the marks of each module in addition to the overall stage result. A graph should also be generated to reflect these results.
Sample output log:
Module 1 - Coursework Weighting: 50 - Exam Mark: 80 - Coursework Mark: 75 Module 2 - Coursework Weighting: 50 - Exam Mark: 35 - Coursework Mark: 60 Module 3 - Coursework Weighting: 50 - Exam Mark: 70 - Coursework Mark: 25 Module 4 - Coursework Weighting: 50 - Exam Mark: 70 - Coursework Mark: 40 Module 5 - Coursework Weighting: 50 - Exam Mark: 80 - Coursework Mark: 50 Module 6 - Coursework Weighting: 50 - Exam Mark: 15 - Coursework Mark: 70 Stage result: Fail Module 1: 77 Module 2: 47 Module 3: 35 Module 4: 55 Module 5: 65 Module 6: 35
Mark Calculator:
public class MarkCalculator {
/***
*
* Computes a students module marks based on the formula provided by the School Of Computer Science (SOCS). <p>
* Method accepts a 2 dimensional array which takes the following structure: <p>
* {{Coursework weighting, Coursework Mark, Exam Mark},..} <p>
* Method returns a 1 dimensional array which takes the structure: <p>
* {Module mark, Module mark,..}
*
* @param studentData
* @return moduleMarks
*/
public static int[] computeMarks(int[][] studentData) {
// Necessary variable declarations:
// moduleMarks - Array of integers to store the module marks achieved by the student
// computedModuleMark - Variable storing the computed module mark : Rounding to the nearest integer
int[] moduleMarks = new int[6];
int computedModuleMark = 0;
// Iterate through and resolve data stored in the 2D array
for (int x = 0; x < studentData.length; x++) {
int weighting = studentData[x][0];
int coursework = studentData[x][1];
int exam = studentData[x][2];
// Computing module mark based on formula provided (+0.5 to force rounding to nearest whole)
computedModuleMark = (int) ((((coursework * weighting) + (exam * (100 - weighting))) + 0.5) / 100);
// Check both exam and coursework meet requirements
// Store the necessary mark in the moduleMarks array at the corresponding index
if (exam >= 35 && coursework >= 35) {
moduleMarks[x] = computedModuleMark;
} else if (exam < 35 || coursework < 35) {
moduleMarks[x] = Math.min(35, computedModuleMark);
}
}
// DEBUG : DISPLAY ALL MODULE MARKS
// for(int p: moduleMarks){ System.out.println(p); }
return moduleMarks;
}
/***
*
* Computes the students stage result and returns a statement based on their performance.
* Method takes a 1 dimensional array of integers, representing a students module marks, and produces
* a stage result based on the criteria provided by the School Of Computer Science (SOCS). <p>
* Students may achieve one of the following: Pass, Compensatable Pass or Fail. <p>
* The method will return one of the above.
*
* @param moduleMarks
* @return "Pass" || "Compensatable Pass" || "Fail"
*/
public static String computeResult(int[] moduleMarks) {
// Initialise variables representing each attainable result
int pass = 0;
int compensatableFail = 0;
int fail = 0;
// Initialise variable (0) - Storing total marks achieved by way of compensatableFails
int compensatableFailTotal = 0;
// Determine status of each module result and increment the appropriate result
for (int mark : moduleMarks) {
if (mark >= 40) {
pass += 1;
} else if (mark < 40 && mark >= 35) {
compensatableFail += 1;
// Update total marks achieved by way of compensatable fail
compensatableFailTotal += mark;
} else {
fail += 1;
}
}
// DEBUG : DISPLAY MODULE RESULTS
// System.out.println("Pass: " + pass);
// System.out.println("Compensatable Fail: " + compensatableFail);
// System.out.println("Fail: " + fail);
// Compute stage average
int stageTotal = 0;
for (int mark : moduleMarks) {
stageTotal += mark;
}
int stageAverage = stageTotal / moduleMarks.length;
// DEBUG : DISPLAY STAGE AVERAGE
// System.out.println("\nStage Average: " + stageAverage);
// Determine and return stage result
if (pass == 6) {
return "Pass";
} else if (stageAverage >= 40 && fail == 0 && compensatableFail <= 2 && compensatableFailTotal <= 40) {
return "Compensatable Pass";
} else {
return "Fail";
}
}
}
Summary:
import java.util.Scanner;
public class Summary {
public static void main(String[] args) {
// DEBUG : TEST DATA
// int[][] data = {{50,20,20},{50,30,30},{50,40,40},{50,50,50},{50,60,60},{50,70,70}};
// Populate array with user input
int[][] data = inputData();
// Produce 1 dimensional array of module marks
int[] moduleMarks = MarkCalculator.computeMarks(data);
// Constructor for graph object
StudentChart graph = new StudentChart(data);
// Produce graph and print summary
graph.draw(moduleMarks);
}
/***
*
* Method provides functionality to accept student data from the user. Method will only accept inputs
* in the form of integers.No parameters are required. The method will return a 2 dimensional
* array of integers taking the following structure: <p>
* {{Coursework weighting, Coursework Mark, Exam Mark},..}
*
* @return
*/
public static int[][] inputData() {
// Initialise a new scanner object
Scanner sc = new Scanner(System.in);
// Initialise empty 2D array of length [6][3]
// Array Structure : {{Coursework weighting, Coursework Mark, Exam Mark},..}
int[][] moduleMarks = new int[6][3];
// Populate each element of array with numerical input from user (INTEGER)
for (int x = 0; x < 6; x++) {
System.out.println("Module " + (x + 1));
System.out.print("Coursework Weighting: ");
moduleMarks[x][0] = sc.nextInt();
System.out.print("Exam Mark: ");
moduleMarks[x][1] = sc.nextInt();
System.out.print("Coursework Mark: ");
moduleMarks[x][2] = sc.nextInt();
System.out.println();
}
// DEBUG : DISPLAY ALL ELEMENTS OF 2D ARRAY
// for(int[] x : moduleMarks){ for(int y : x){ System.out.println(y); }}
// Close scanner and return array
sc.close();
return moduleMarks;
}
}
An implementation of the Bar
class was provided to us as a graphics library, this was used by another class I wrote to construct the following graph. (The graph did not require labelling and was simply constructed by manipulating shapes on a canvas)
I am looking for feedback regarding the design of my solution - Anything which could be improved in the future or would not be encouraged when programming in the industry.
I'm using Java version 1.8.0_60.