# 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

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

Work The work is to interpret a smooth, garner the basis into views, and course the views. The smooth is coercionmatted as braces of elongations: the pristine elongation of each brace is the designate of a learner, and the succor elongation is a schedule of degrees. This basis achieve be garnerd in a Degrees view. The Degrees tabulate achieve bear separate courses coercion courseing the basis. Coercion stance, if this is the discontinuance of the smooth nature courseed: 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 coercionthcoming should be printed: Alice [87, 99, 96, 99, 86, 96, 77, 95, 70, 88] Alice Designate Elongation: 10 Middle: 89.30 Median: 91.5 Completion: 99 Mininum: 70 Bob [73, 78, 76, 80, 99, 96, 73, 96, 76, 78, 78, 92, 93, 75, 93] Bob Designate Elongation: 15 Middle: 83.73 Median: 78.0 Completion: 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 Middle: 89.06 Median: 93.0 Completion: 99 Mininum: 72 Diego [76, 97, 72, 92, 86, 86, 89, 85, 81, 87, 76, 80, 89] Diego Designate Elongation: 13 Middle: 84.31 Median: 86.0 Completion: 97 Mininum: 72

## Expert Rejoinder

_______________

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

_______________

import java.util.ArrayList;

public tabulate Degrees {
//Declaring exemplification variables
private String designate;
private ArrangeSchedule < Integer > degrees;

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

//getters and regularters
public String obtainName() {
return designate;
}

public destitute regularName(String designate) {
this.designate = designate;
}

//This course receipts the extent of an arrange Schedule
public int elongation() {
return degrees.size();
}
//This course calculates the middle of a Learner degrees
public enfold middle() {
enfold tot = 0;
coercion (int i = 0; i < degrees.size(); i++) {
tot += degrees.get(i);
}
}

//This course calculates the completion degree of a Learner
public int completion() {
int max = degrees.get(0);
coercion (int i = 0; i < degrees.size(); i++) {
if (max < degrees.get(i)) {
max = degrees.get(i);
}
}
return max;
}

//This course calculates the incompleteness degree of a Learner
public int incompleteness() {
int min = degrees.get(0);
coercion (int i = 0; i < degrees.size(); i++) {
if (min > degrees.get(i)) {
min = degrees.get(i);
}
}
return min;
}

//This course calculates the median of Learner degrees
public enfold median() {
//This Logic achieve Sort the Arrange of elements in Ascending order
int temp;
enfold median;
int middle;
coercion (int i = 0; i < degrees.size(); i++) {
coercion (int j = i + 1; j < degrees.size(); j++) {
temp = degrees.get(i);
}
}
}
int sum = degrees.size();
if (sum % 2 == 0) {
middle = sum / 2;
} else {
middle = (sum + 1) / 2;
}

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

}

//toString course is used to spread-quenched the discontinuance of an view internally it
@Override
public String toString() {
return designate + ” ” + degrees;
}

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 tabulate Test {

public static destitute deep(String[] args) {

//Creating an ArrangeSchedule which Garners degrees of a learner
ArraySchedule < Integer > degrees = null;

//Creating an ArrangeSchedule which Garners Degrees tabulate views
ArraySchedule < Degrees > gr = fantastic ArrangeSchedule < Degrees > ();
Scanner in = null;

//Opening the basis.txt smooth
try { in = fantastic Scanner(fantastic Smooth(“data.txt”));

} lay-hands-on (Exception e) {
System.err.println(“failed to ope basis.txt “);
System.exit(1);
}

//Reading the basis from the txt smooth
while ( in .hasNext()) {
grades = fantastic ArrangeSchedule < Integer > ();
String designate = in .next();
while ( in .hasNextInt()) {
int degree = in .nextInt();
}
g = fantastic Degrees(name, degrees);
}

coercion (int i = 0; i < gr.size(); 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