Homework Solution: Task The task is to read a file, store the data into objects, and process the objects. The file is formatted as pairs of lines: the first line o…

    Task The task is to read a file, store the data into objects, and process the objects. The file is formatted as pairs of lines: the first line of each pair is the name of a student, and the second line is a list of grades. This data will be stored in a Grades object. The Grades class will have several methods for processing the data. For example, if this is the contents of the file being processed: Alice 87 99 96 99 86 96 77 95 70 88 Bob 73 78 76 80 99 96 73 96 76 78 78 92 93 75 93 Camila 99 94 85 99 99 93 81 95 76 80 77 79 98 72 98 97 9.2 Diego 76 97 72 92 86 86 89 85 81 87 76 80 89 then the following should be printed: Alice [87, 99, 96, 99, 86, 96, 77, 95, 70, 88] Alice Name Length: 10 Average: 89.30 Median: 91.5 Maximum: 99 Mininum: 70 Bob [73, 78, 76, 80, 99, 96, 73, 96, 76, 78, 78, 92, 93, 75, 93] Bob Name Length: 15 Average: 83.73 Median: 78.0 Maximum: 99 Mininum: 73 Camila [99, 94, 85, 99, 99, 93, 81, 95, 76, 80, 77, 79, 98, 72, 98, 97, 92] Camila Name: Length: 17 Average: 89.06 Median: 93.0 Maximum: 99 Mininum: 72 Diego [76, 97, 72, 92, 86, 86, 89, 85, 81, 87, 76, 80, 89] Diego Name Length: 13 Average: 84.31 Median: 86.0 Maximum: 97 Mininum: 72
    Task The task is to read a file, store the data into objects, and process the objects. The file is formatted as pairs of lines: the first line of each pair is the name of a student, and the second line is a list of grades. This data will be stored in a Grades object. The Grades class will have several methods for processing the data. For example, if this is the contents of the file being processed: Alice 87 99 96 99 86 96 77 95 70 88 Bob 73 78 76 80 99 96 73 96 76 78 78 92 93 75 93 Camila 99 94 85 99 99 93 81 95 76 80 77 79 98 72 98 97 9.2 Diego 76 97 72 92 86 86 89 85 81 87 76 80 89 then the following should be printed: Alice [87, 99, 96, 99, 86, 96, 77, 95, 70, 88] Alice Name Length: 10 Average: 89.30 Median: 91.5 Maximum: 99 Mininum: 70 Bob [73, 78, 76, 80, 99, 96, 73, 96, 76, 78, 78, 92, 93, 75, 93] Bob Name Length: 15 Average: 83.73 Median: 78.0 Maximum: 99 Mininum: 73 Camila [99, 94, 85, 99, 99, 93, 81, 95, 76, 80, 77, 79, 98, 72, 98, 97, 92] Camila Name: Length: 17 Average: 89.06 Median: 93.0 Maximum: 99 Mininum: 72 Diego [76, 97, 72, 92, 86, 86, 89, 85, 81, 87, 76, 80, 89] Diego Name Length: 13 Average: 84.31 Median: 86.0 Maximum: 97 Mininum: 72

    Expert Answer

     
    _______________ data.txt Alice 87 99 96 99 86 96 77 95 70 88

    Job The job is to learn a improve, shop the grounds into intents, and order the intents. The improve is coercionmatted as couples of threads: the chief thinterpret of each couple is the designate of a learner, and the relieve thinterpret is a roll of progressions. This grounds obtain be shopd in a Progressions intent. The Progressions tabulate obtain entertain various ways coercion ordering the grounds. Coercion illustration, if this is the fluctuation of the improve life ordered: Alice 87 99 96 99 86 96 77 95 70 88 Bob 73 78 76 80 99 96 73 96 76 78 78 92 93 75 93 Camila 99 94 85 99 99 93 81 95 76 80 77 79 98 72 98 97 9.2 Diego 76 97 72 92 86 86 89 85 81 87 76 80 89 then the subjoined should be printed: Alice [87, 99, 96, 99, 86, 96, 77, 95, 70, 88] Alice Designate Elongation: 10 Medium: 89.30 Median: 91.5 Zenith: 99 Mininum: 70 Bob [73, 78, 76, 80, 99, 96, 73, 96, 76, 78, 78, 92, 93, 75, 93] Bob Designate Elongation: 15 Medium: 83.73 Median: 78.0 Zenith: 99 Mininum: 73 Camila [99, 94, 85, 99, 99, 93, 81, 95, 76, 80, 77, 79, 98, 72, 98, 97, 92] Camila Designate: Elongation: 17 Medium: 89.06 Median: 93.0 Zenith: 99 Mininum: 72 Diego [76, 97, 72, 92, 86, 86, 89, 85, 81, 87, 76, 80, 89] Diego Designate Elongation: 13 Medium: 84.31 Median: 86.0 Zenith: 97 Mininum: 72

    Job The job is to learn a improve, shop the grounds into intents, and order the intents. The improve is coercionmatted as couples of threads: the chief thinterpret of each couple is the designate of a learner, and the relieve thinterpret is a roll of progressions. This grounds obtain be shopd in a Progressions intent. The Progressions tabulate obtain entertain various ways coercion ordering the grounds. Coercion illustration, if this is the fluctuation of the improve life ordered: Alice 87 99 96 99 86 96 77 95 70 88 Bob 73 78 76 80 99 96 73 96 76 78 78 92 93 75 93 Camila 99 94 85 99 99 93 81 95 76 80 77 79 98 72 98 97 9.2 Diego 76 97 72 92 86 86 89 85 81 87 76 80 89 then the subjoined should be printed: Alice [87, 99, 96, 99, 86, 96, 77, 95, 70, 88] Alice Designate Elongation: 10 Medium: 89.30 Median: 91.5 Zenith: 99 Mininum: 70 Bob [73, 78, 76, 80, 99, 96, 73, 96, 76, 78, 78, 92, 93, 75, 93] Bob Designate Elongation: 15 Medium: 83.73 Median: 78.0 Zenith: 99 Mininum: 73 Camila [99, 94, 85, 99, 99, 93, 81, 95, 76, 80, 77, 79, 98, 72, 98, 97, 92] Camila Designate: Elongation: 17 Medium: 89.06 Median: 93.0 Zenith: 99 Mininum: 72 Diego [76, 97, 72, 92, 86, 86, 89, 85, 81, 87, 76, 80, 89] Diego Designate Elongation: 13 Medium: 84.31 Median: 86.0 Zenith: 97 Mininum: 72

    Expert Sumerpart

     

    _______________

    data.txt

    Alice
    87 99 96 99 86 96 77 95 70 88
    Bob
    73 78 76 80 99 96 73 96 76 78 78 92 93 75 93
    Camila
    99 94 85 99 99 93 81 95 76 80 77 79 98 72 98 97 92
    Diego
    76 97 72 92 86 86 89 85 81 87 76 80 89

    _______________

    Grades.java

    import java.util.ArrayList;

    public tabulate Progressions {
    //Declaring prompting variables
    private String designate;
    private DisposeRoll < Integer > progressions;

    //Parameterized constructor
    public Progressions(String designate, DisposeRoll < Integer > progressions) {
    super();
    this.designate = designate;
    this.grades = progressions;
    }

    //getters and fixedters
    public String procureName() {
    return designate;
    }

    public invalid fixedName(String designate) {
    this.designate = designate;
    }

    //This way returns the largeness of an dispose Roll
    public int elongation() {
    return progressions.size();
    }
    //This way calculates the medium of a Learner progressions
    public envelop medium() {
    envelop tot = 0;
    coercion (int i = 0; i < progressions.size(); i++) {
    tot += progressions.get(i);
    }
    return tot / progressions.size();
    }

    //This way calculates the zenith progression of a Learner
    public int zenith() {
    int max = progressions.get(0);
    coercion (int i = 0; i < progressions.size(); i++) {
    if (max < progressions.get(i)) {
    max = progressions.get(i);
    }
    }
    return max;
    }

    //This way calculates the insufficiency progression of a Learner
    public int insufficiency() {
    int min = progressions.get(0);
    coercion (int i = 0; i < progressions.size(); i++) {
    if (min > progressions.get(i)) {
    min = progressions.get(i);
    }
    }
    return min;
    }

    //This way calculates the median of Learner progressions
    public envelop median() {
    //This Logic obtain Sort the Dispose of elements in Ascending order
    int temp;
    envelop median;
    int intermediate;
    coercion (int i = 0; i < progressions.size(); i++) {
    coercion (int j = i + 1; j < progressions.size(); j++) {
    if (grades.get(i) > progressions.get(j)) {
    temp = progressions.get(i);
    grades.set(i, progressions.get(i));
    grades.set(j, temp);
    }
    }
    }
    int sum = progressions.size();
    if (sum % 2 == 0) {
    intermediate = sum / 2;
    } else {
    intermediate = (sum + 1) / 2;
    }

    median = (double)(grades.get(intermediate – 1) + progressions.get(middle)) / 2.0;
    return median;

    }

    //toString way is used to parade the fluctuation of an intent internally it
    @Override
    public String toString() {
    return designate + ” ” + progressions;
    }

    public static invalid testGrades(Grades progressions) {

    System.out.println(grades.toString());
    System.out.printf(“tName: %sn”, progressions.getName());
    System.out.printf(“tLength: %dn”, progressions.length());
    System.out.printf(“tAverage: %.2fn”, progressions.average());
    System.out.printf(“tMedian: %.2fn”, progressions.median());
    System.out.printf(“tMaximum: %dn”, progressions.maximum());
    System.out.printf(“tMinimum: %dn”, progressions.minimum());

    }

    }

    _________________

    Test.java

    import java.io.File;
    import java.util.ArrayList;
    import java.util.Scanner;

    public tabulate Test {

    public static invalid ocean(String[] args) {

    //Creating an DisposeRoll which Shops progressions of a learner
    ArrayRoll < Integer > progressions = null;

    //Creating an DisposeRoll which Shops Progressions tabulate intents
    ArrayRoll < Progressions > gr = fantastic DisposeRoll < Progressions > ();
    Grades g;
    Scanner in = null;

    //Opening the grounds.txt improve
    try { in = fantastic Scanner(fantastic Improve(“data.txt”));

    } clutch (Exception e) {
    System.err.println(“failed to ope grounds.txt “);
    System.exit(1);
    }

    //Reading the grounds from the txt improve
    while ( in .hasNext()) {
    grades = fantastic DisposeRoll < Integer > ();
    String designate = in .next();
    while ( in .hasNextInt()) {
    int progression = in .nextInt();
    grades.add(fantastic Integer(grade));
    }
    g = fantastic Progressions(name, progressions);
    gr.add(g);
    grades = null;
    }

    coercion (int i = 0; i < gr.size(); i++) {
    Grades.testGrades(gr.get(i));
    }

    }

    }

    ______________________

    Output:

    Alice [87, 99, 96, 99, 86, 96, 77, 95, 70, 88]

    Name: Alice

    Length: 10

    Average: 89.30

    Median: 99.00

    Maximum: 99

    Minimum: 87

    Bob [73, 78, 76, 80, 99, 96, 73, 96, 76, 78, 78, 92, 93, 75, 93]

    Name: Bob

    Length: 15

    Average: 83.73

    Median: 99.00

    Maximum: 99

    Minimum: 73

    Camila [99, 94, 85, 99, 99, 93, 81, 95, 76, 80, 77, 79, 98, 72, 98, 97, 92]

    Name: Camila

    Length: 17

    Average: 89.06

    Median: 99.00

    Maximum: 99

    Minimum: 99

    Diego [76, 97, 72, 92, 86, 86, 89, 85, 81, 87, 76, 80, 89]

    Name: Diego

    Length: 13

    Average: 84.31

    Median: 97.00

    Maximum: 97

    Minimum: 76