Answer to Question #293197 in Java | JSP | JSF for Pre

Question #293197

During the time of the Coronavirus pandemic, the Lancet Laboratories had to do many COVID‐19 tests.



The details of these test is captures on a weekly basis for 4 months and stored in 3 parallel arrays as can be seen



below. 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};



Follow the UML class diagram (Table 1.1) and description table (Table 1.2) and complete the TheTestStats application.



TheTestStats



+ main(String[]): void



+ testsDoneInWeek(String[], int[], int, int): int



+ percentagePositives(int[], int[]): double[]



+ highestPercentage(String[], double[]): String

1
Expert's answer
2022-02-02T13:22:10-0500
public class TheTestStats {

    public static int testsDoneInWeek(String[] batchCodes, int[] testsDone, int week, int month) {
        return testsDone[month - 1 + 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};
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS