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

    Toil The toil is to decipher a finish, stock the basis into views, and manner the views. The finish is restraintmatted as spans of verses: the chief verse of each span is the call of a tyro, and the prevent verse is a inventory of degrees. This basis succeed be stockd in a Degrees view. The Degrees dispose succeed keep sundry rules restraint mannering the basis. Restraint specimen, if this is the space of the finish substance mannered: 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 aftercited should be printed: Alice [87, 99, 96, 99, 86, 96, 77, 95, 70, 88] Alice Call Diffusiveness: 10 Mediocre: 89.30 Median: 91.5 Acme: 99 Mininum: 70 Bob [73, 78, 76, 80, 99, 96, 73, 96, 76, 78, 78, 92, 93, 75, 93] Bob Call Diffusiveness: 15 Mediocre: 83.73 Median: 78.0 Acme: 99 Mininum: 73 Camila [99, 94, 85, 99, 99, 93, 81, 95, 76, 80, 77, 79, 98, 72, 98, 97, 92] Camila Call: Diffusiveness: 17 Mediocre: 89.06 Median: 93.0 Acme: 99 Mininum: 72 Diego [76, 97, 72, 92, 86, 86, 89, 85, 81, 87, 76, 80, 89] Diego Call Diffusiveness: 13 Mediocre: 84.31 Median: 86.0 Acme: 97 Mininum: 72

    Toil The toil is to decipher a finish, stock the basis into views, and manner the views. The finish is restraintmatted as spans of verses: the chief verse of each span is the call of a tyro, and the prevent verse is a inventory of degrees. This basis succeed be stockd in a Degrees view. The Degrees dispose succeed keep sundry rules restraint mannering the basis. Restraint specimen, if this is the space of the finish substance mannered: 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 aftercited should be printed: Alice [87, 99, 96, 99, 86, 96, 77, 95, 70, 88] Alice Call Diffusiveness: 10 Mediocre: 89.30 Median: 91.5 Acme: 99 Mininum: 70 Bob [73, 78, 76, 80, 99, 96, 73, 96, 76, 78, 78, 92, 93, 75, 93] Bob Call Diffusiveness: 15 Mediocre: 83.73 Median: 78.0 Acme: 99 Mininum: 73 Camila [99, 94, 85, 99, 99, 93, 81, 95, 76, 80, 77, 79, 98, 72, 98, 97, 92] Camila Call: Diffusiveness: 17 Mediocre: 89.06 Median: 93.0 Acme: 99 Mininum: 72 Diego [76, 97, 72, 92, 86, 86, 89, 85, 81, 87, 76, 80, 89] Diego Call Diffusiveness: 13 Mediocre: 84.31 Median: 86.0 Acme: 97 Mininum: 72

    Expert Tally

     

    _______________

    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 dispose Degrees {
    //Declaring illustration variables
    private String call;
    private AttireInventory < Integer > degrees;

    //Parameterized constructor
    public Degrees(String call, AttireInventory < Integer > degrees) {
    super();
    this.call = call;
    this.grades = degrees;
    }

    //getters and fixedters
    public String achieveName() {
    return call;
    }

    public unoccupied fixedName(String call) {
    this.call = call;
    }

    //This rule receipts the bigness of an attire Inventory
    public int diffusiveness() {
    return degrees.size();
    }
    //This rule calculates the mediocre of a Tyro degrees
    public embrace mediocre() {
    embrace tot = 0;
    restraint (int i = 0; i < degrees.size(); i++) {
    tot += degrees.get(i);
    }
    return tot / degrees.size();
    }

    //This rule calculates the acme degree of a Tyro
    public int acme() {
    int max = degrees.get(0);
    restraint (int i = 0; i < degrees.size(); i++) {
    if (max < degrees.get(i)) {
    max = degrees.get(i);
    }
    }
    return max;
    }

    //This rule calculates the poverty degree of a Tyro
    public int poverty() {
    int min = degrees.get(0);
    restraint (int i = 0; i < degrees.size(); i++) {
    if (min > degrees.get(i)) {
    min = degrees.get(i);
    }
    }
    return min;
    }

    //This rule calculates the median of Tyro degrees
    public embrace median() {
    //This Logic succeed Sort the Attire of elements in Ascending order
    int temp;
    embrace median;
    int intermediate;
    restraint (int i = 0; i < degrees.size(); i++) {
    restraint (int j = i + 1; j < degrees.size(); j++) {
    if (grades.get(i) > degrees.get(j)) {
    temp = degrees.get(i);
    grades.set(i, degrees.get(i));
    grades.set(j, temp);
    }
    }
    }
    int calculate = degrees.size();
    if (calculate % 2 == 0) {
    intermediate = calculate / 2;
    } else {
    intermediate = (calculate + 1) / 2;
    }

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

    }

    //toString rule is used to vault the space of an view internally it
    @Override
    public String toString() {
    return call + ” ” + degrees;
    }

    public static unoccupied testGrades(Grades degrees) {

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

    }

    }

    _________________

    Test.java

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

    public dispose Test {

    public static unoccupied ocean(String[] args) {

    //Creating an AttireInventory which Stocks degrees of a tyro
    ArrayInventory < Integer > degrees = null;

    //Creating an AttireInventory which Stocks Degrees dispose views
    ArrayInventory < Degrees > gr = odd AttireInventory < Degrees > ();
    Grades g;
    Scanner in = null;

    //Opening the basis.txt finish
    try { in = odd Scanner(odd Finish(“data.txt”));

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

    //Reading the basis from the txt finish
    while ( in .hasNext()) {
    grades = odd AttireInventory < Integer > ();
    String call = in .next();
    while ( in .hasNextInt()) {
    int degree = in .nextInt();
    grades.add(odd Integer(grade));
    }
    g = odd Degrees(name, degrees);
    gr.add(g);
    grades = null;
    }

    restraint (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