Assignment: The Oregon Department of Education has commissioned a study to deter
ID: 3665368 • Letter: A
Question
Assignment:
The Oregon Department of Education has commissioned a study to determine if Males or
Females score better on a particular test. They also want to study if Community College
or University students score better. Researchers have created a data file (scores.txt),
which contains the scores attained by the student sample. The first column is the
student’s name, the second column is the student’s gender (M for male, and F for
female), the third column indicates Community College (CC) or 4 year (UN), and the last
column specifies the score. A specimen of the file scores.txt is attached as part of this
assignment. You should download this file to a convenient place on your hard drive.
Design Considerations:
1. Your assignment is to prompt the user to enter the filename with the path on disk.
If the file does not exist in the specified location, your program should exit with a
suitable error message.
2. No global variables. All variables must be inside main().
3. The first thing your program should do is output to the screen a copy of the data
read in from the disk file. This is known as “echoing” the input data.
4. Your program should then calculate and display the average score for males,
females, community college students, and university students. Display your
results to two places of decimals, and write your program to automatically list
your four calculated averages one to a line, along with a suitable label for each
result.
5. Finally, your program should calculate and display to two places of decimals the
overall average score for all of the students surveyed. (Note: Mathematically, this
is NOT the average of the four averages you calculated previously).
Score.txt
Bailey M CC 68
Harrison F CC 71
Grant M UN 75
Peterson F UN 69
Hsu M UN 79
Bowles M CC 75
Anderson F UN 64
Nguyen F CC 68
Sharp F CC 75
Jones M UN 75
McMillan F UN 80
Gabriel F UN 62
Explanation / Answer
import java.util.*;
import java.io.*;
import java.text.*;
public class StudentGradebookScores {
public static void main(String[]args) throws IOException {
File inputFile = new File("scores.txt");
Scanner data = new Scanner(inputFile);
DecimalFormat averages = new DecimalFormat("#.#");
int students = data.nextInt();
int assignments = data.nextInt();
double gradebook[][] = new double [students + 1][assignments + 1];
//putting the scores into the array
for (int i=0; i<students; i++) { //rows
for (int j=0; j<assignments; j++) { //coloums
gradebook[i][j] = data.nextDouble();
}
}
//calculating the average assignment score for each student (coloums)
for (int i=0; i<students; i++) {
double studentTotal = 0;
for (int j=0; j<assignments; j++) {
studentTotal = studentTotal + gradebook[i][j];
}
gradebook[i][assignments] = studentTotal/assignments;
}
//calculating the average score of each assigment for all students (rows)
for (int j=0; j<assignments; j++) {
double assignmentTotal = 0;
for (int i=0; i<students; i++) {
assignmentTotal = assignmentTotal + gradebook[i][j];
}
gradebook[students][j] = assignmentTotal/students;
}
//printing the gradebook
System.out.print(" Assignment #: ");
for (int j=0; j<assignments; j++) {
System.out.print((j+1) + " ");
}
System.out.println("Avg");
for (int i=0; i<students; i++) {
System.out.print("Student #" + (i+1) + ": ");
for (int j=0; j<assignments; j++) {
System.out.print(gradebook[i][j] + " ");
}
System.out.println(averages.format(gradebook[i][assignments]));
}
System.out.print("Average ");
for (int j=0; j<assignments; j++) {
System.out.print(averages.format(gradebook[students][j]) + " ");
}
System.out.println();
double overallAvg = 0;
for (int i=0; i<students; i++) {
overallAvg = overallAvg + gradebook[i][assignments];
}
System.out.println(" Overall Average: " + averages.format(overallAvg/students));
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.