Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please do the following code using PYTHON. Please don\'t post an answer unless i

ID: 3860119 • Letter: P

Question

Please do the following code using PYTHON. Please don't post an answer unless it is complete and it works. Thanks!

Write a program lists3.py that reads a CSV data file called grades.CSV (sample provided) that contains 4columns: student last name, student first name, midterm score, and final score. The program calculates an examm average for each student and rounds it up to an integer, then it writes the name and the examm average to another csv file called exam Scores.csv (sample provided).

Finally, the program prints to the screen the following stats:

Names and scores of students within 5 points of the maximum score, example: if the maximum score is 98, then all the students scoring >= 93 should be printed

The number of students that scored in the range 0 –59, 60 –69, 70 –79, 80–89, 90 –100 (to keep track of the ranges, you should set up a list of counters of size 5; when you process a number within the first range, you update location 0, within second range, location 1, etc)

For example, for the provided input file, the program should print the following 13 lines:

topscorers (max score = 97):

Herrera, Adrian Q., 93

Kline, Celeste P., 94

Lee, Pearl J., 96

Salinas, Taylor Z., 95

Whitfield, Stella W., 97

grade ranges:

7 students with grades >= 90

10 students with grades >= 80

31 students with grades >= 70

24 students with grades >= 60

28 students with grades < 60

LastName,FirstName, Midterm Grade, Final Grade Alford, Maggy B.,57,100 Allison, venus S.,87,49 Bernard, Ashely Q.,73, 55 Black, Claire G.,81, 62 Blair, Lyle U.,93,58 Bonner, Lacy R.,50, 67 Brennan, Colton P., 63, 89 Bryant, Samantha A.,42,98 Buckley, Chancellor C.,42,61 Cabrera, Thor R.,34, 69 Cain, Rina o., 34,75 Christian, Salvador W.,79, 49 Cole, zachary L.,66, 75 Conrad, Kathleen G., 68, 60 Cotton, Levi V.,30, 52 Crawford, Charissa P., 85,47 Day, Ursula F. , 53,53 Dejesus, Moana I., 62, 91 Dennis, Heidi o.,71,74 Dickerson,Aubrey V., 98,71 Dillard, Damon Z.,82,94 Dillon, Olivia J.,37,78 Duran, September Y.,60, 90 England, Gay V.,56,55 Ford, Allegra S. , 69,72 Garza, Omar C.,47,50 Gilbert, Julian P., 65, 93 Glass, Joshua v.,72, 61 Gonzales, Martha R., 67,75 Griffith, Rudyard Y.,38,55 Guerra, Alyssa K,72,75 Guthrie, Kristen D., 44,78 Hale, Veda Y., 64,89 Hampton, Emery U.,58,76 Hancock, Gray G.,44,60 Haney, Nola U., 71,77 Harvey, Dante V.,90,71 Herrera, Adrian Q.,93,93 Hicks, Zeus M., 84,71 Hyde, Jeremy Q.,56, 54 Jacobson, Brock J.,53,95 James, Rachel C.,37,92

Explanation / Answer

import java.io.File;

import java.io.IOException;

import java.text.DecimalFormat;

import java.util.*;

import java.util.stream.IntStream;

public class GradeBook

{

    private List<double[]> students;

    private static final DecimalFormat FMT = new DecimalFormat("#.#");

    public GradeBook(Scanner input) {

        this.students = new ArrayList<double[]>();

        while (input.hasNextLine())

              {

            double[] student = Arrays.stream(input.nextLine().trim().split("\s+"))

                  .mapToDouble(Double::parseDouble)

                  .toArray();

            students.add(student);

        }

    }

    public double getScore(int student, int assignment) {

        return this.students.get(student)[assignment];

    }

    public double averageForStudent(int student) {

        return Arrays.stream(this.students.get(student))

                     .average()

                     .getAsDouble();

    }

    public double averageForAssignment(int assignment) {

        return this.students.stream()

                   .mapToDouble((assignments) -> assignments[assignment])

                   .average()

                   .getAsDouble();

    }

    public double average() {

        return IntStream.range(0, this.students.size())

                        .mapToDouble((s) -> this.averageForStudent(s))

                        .average()

                        .getAsDouble();

    }

    public String toString() {

        StringBuilder out = new StringBuilder();

        int numAssignments = this.students.stream()

                                 .mapToInt((assignments) -> assignments.length)

                                 .max()

                                 .getAsInt();

        out.append(" Assignment #: ");

        for (int a = 0; a < numAssignments; a++) {

           out.append(a + 1).append(' ');

        }

        out.append("Avg ");

           for (int s = 0; s < this.students.size(); s++) {

            out.append("Student #").append(s + 1).append(": ");

            for (int a = 0; a < numAssignments; a++) {

                out.append(FMT.format(this.getScore(s, a))).append(' ');

            }

            out.append(FMT.format(this.averageForStudent(s))).append(' ');

        }

        out.append("Average ");

        for (int a = 0; a < numAssignments; a++) {

            out.append(FMT.format(this.averageForAssignment(a))).append(' ');

        }

        out.append(' ');

        return out.toString();

    }

    public static void main(String[] args) throws IOException {

        try (Scanner input = args.length > 0 ? new Scanner(new File(args[0])) :

                                               new Scanner(System.in)) {

            GradeBook book = new GradeBook(input);

            System.out.println(book);

            System.out.printf("Overall Average: %s ",

                              FMT.format(book.average()));

        }

    }

}