batchCodes,
testsDone, positiveResults) to your source code.
2. Invoke the testsDoneInWeek() method to determine the
number of tests that was done in week 2 of month 3.
3. Display an appropriate message with the number of tests done
in this week.
4. Invoke the highestPercentage() method to determine the
month and week with the highest percentage of positive cases.
a. You must first invoke the percentagePositives() method
to generate a double array with the percentages of
positive cases per week.
b. This is one of the arguments needed for invoking the
percentagePositives() method.
5. Display an appropriate message with the indication of which
batch had the highest percentage positive cases.
highestPercentage(String[], double[]) The method receives as parameters the batch codes array as well as the ar
public class TheTestStats {
public static int testsDoneInWeek(String[] batchCodes, int[] testsDone, int week, int month) {
return testsDone[((month - 1) * 4) + week - 1];
}
public static double[] percentagePositives(int[] testsDone, int[] positiveResults) {
double[] percentagePositives = new double[testsDone.length];
for (int i = 0; i < testsDone.length; i++) {
percentagePositives[i] = (double) positiveResults[i] / testsDone[i];
}
return percentagePositives;
}
public static String highestPercentage(String[] batchCodes, double[] percentagePositives) {
int max = 0;
for (int i = 0; i < percentagePositives.length; i++) {
if (percentagePositives[i] > percentagePositives[max]) {
max = i;
}
}
return batchCodes[max];
}
public static void main(String[] args) {
String[] batchCodes = {
"M1W1", "M1W2", "M1W3", "M1W4",
"M2W1", "M2W2", "M2W3", "M2W4",
"M3W1", "M3W2", "M3W3", "M3W4",
"M4W1", "M4W2", "M4W3", "M4W4"};
int[] testsDone = {467, 587, 987, 787, 878, 888, 936, 1002, 1005, 768, 887, 963, 789, 1008, 888, 687};
int[] positiveResults = {23, 87, 88, 99, 87, 105, 222, 138, 333, 258, 408, 444, 259, 236, 408, 258};
System.out.println("Tests that was done in week 2 of month 3: "
+ testsDoneInWeek(batchCodes, testsDone, 2, 3));
System.out.println("Month and week with the highest percentage of positive cases: "
+ highestPercentage(batchCodes, percentagePositives(testsDone, positiveResults)));
}
}
Comments
Leave a comment