Java Question. Can someone write this code?
Instructions
This program will read in test data for students(you should download the input file "PairGrades.txt" shown below) Your job is to produce an output file "average.txt" which displays the student's name once in uppercase and then a list of the grades, 4 underscores, the average for the grades, and an empty line. After all the students' information is listed, you should display the student with the highest average. One sentence should be displayed indicating which student scored the highest average.
The challenge will be getting the output file to look EXACTLY like below. You will need to display the average with exactly one digit after the decimal (use printf %.1f )
You will need to keep track of the previous and next student's name so you can group the scores together.
Example Input - PairGrades.txt file
Anna 85.5 98.5 Anna 67.4 ANNA 78.5 23.4 Carl 99.4 78.5 carl 45.2 Farzana 87.5 77.8 45.2 FARZANA 90.2 Farzana 23.1
Example Output - Average.txt file
Here is a sample run of the program.
ANNA 85.5 98.5 67.4 78.5 23.4 ____ avg = 70.7% CARL 99.4 78.5 45.2 ____ avg = 74.4% FARZANA 87.5 77.8 45.2 90.2 23.1 ____ avg = 64.8% 3 students were analyzed. CARL scored the highest average: 74.4%
import java.io.*;
import java.util.*;
public class Demo252{
public static void main(String[] args){
String[] name = new
String[20];
double[][] marks = new
double[20][10];
int[] count = new
int[20];
for (int i = 0; i<20;
i++)
count[i] = 0;
try {
FileInputStream fin = new FileInputStream("PairGrades.txt");
FileOutputStream fout = new FileOutputStream("Average.txt");
PrintWriter pw = new PrintWriter(fout);
Scanner fc = new Scanner(fin);
int n
= 0;
while(fc.hasNextLine()){
String line = fc.nextLine();
String[] list = line.split(" ");
int found = 0;
for (int i = 0; i<n; i++){
if (name[i].equalsIgnoreCase(list[0])){
found = 1;
for (int j = 1; j<list.length; j++){
marks[i][count[i]] = Double.parseDouble(list[j]);
count[i]++;
}
}
}
if (found == 0){
name[n] = list[0].toUpperCase();
for (int j = 1; j<list.length; j++){
marks[n][count[n]] = Double.parseDouble(list[j]);
count[n]++;
}
n++;
}
}
fc.close();
double
max = 0;
int
maxi = 0;
for
(int i = 0; i<n; i++){
pw.println(name[i]);
double sum = 0;
for (int j = 0; j<count[i]; j++){
pw.printf("%.1f\n",marks[i][j]);
sum = sum + marks[i][j];
}
pw.println("---");
double avg = sum/count[i];
pw.printf("avg = %.1f%s\n", avg,"%");
pw.println("\n");
if (avg > max){
max = avg;
maxi = i;
}
}
pw.println(n + " students were analyzed");
pw.printf("%s scored highest average:
%.1f%s\n",name[maxi],max,"%");
pw.close();
}
catch(Exception e){
e.printStackTrace();
}
}
}
Java Question. Can someone write this code? Instructions This program will read in test data for...
use JOptionPane to display output Can someone please help write a program in Java using loops, not HashMap Test 1 Grades After the class complete the first exam, I saved all of the grades in a text file called test1.txt. Your job is to do some analysis on the grades for me. Input: There will not be any input for this program. This is called a batch program because there will be no user interaction other than to run the program....
in java by using the loop Write a program that finds all students who score the highest and lowest average marks of the first two homework in CS (I). Your program should read the data from a file called "hw2.dat" and displays the output to another file called “hw2.out” and on the screen. The first line of the input file contains the number of students, N. The next N lines contain information about the students. Each data line contains student...
using java Program: Please read the complete prompt before going into coding. Write a program that handles the gradebook for the instructor. You must use a 2D array when storing the gradebook. The student ID as well as all grades should be of type int. To make the test process easy, generate the grade with random numbers. For this purpose, create a method that asks the user to enter how many students there are in the classroom. Then, in each...
Write a Java program that reads a file until the end of the file is encountered. The file consists of an unknown number of students' last names and their corresponding test scores. The scores should be integer values and be within the range of 0 to 100. The first line of the file is the number of tests taken by each student. You may assume the data on the file is valid. The program should display the student's name, average...
C++ Redo PROG8, a previous program using functions and/or arrays. Complete as many levels as you can. Level 1: (20 points) Write FUNCTIONS for each of the following: a) Validate #students, #scores. b) Compute letter grade based on average. c) Display student letter grade. d) Display course average. Level 2: (15 points) Use ARRAYS for each of the following. e) Read a student's scores into array. f) Calculate the student's average based on scores in array. g) Display the student's...
Write a complete C++ program that reads students names and their test scores from an input text file. The program should output each student’s name followed by the test scores and the relevant grade in an output text file. It should also find and display on screen the highest/lowest test score and the name of the students having the highest/lowest test score, average and variance of all test scores. Student data obtained from the input text file should be stored...
[JAVA/chapter 7] Assignment: Write a program to process scores for a set of students. Arrays and methods must be used for this program. Process: •Read the number of students in a class. Make sure that the user enters 1 or more students. •Create an array with the number of students entered by the user. •Then, read the name and the test score for each student. •Calculate the best or highest score. •Then, Calculate letter grades based on the following criteria:...
In C++ Assignment 8 - Test Scores Be sure to read through Chapter 10 before starting this assignment. Your job is to write a program to process test scores for a class. Input Data You will input a test grade (integer value) for each student in a class. Validation Tests are graded on a 100 point scale with a 5 point bonus question. So a valid grade should be 0 through 105, inclusive. Processing Your program should work for any...
Must be written in JAVA Code Write a program that will read in a file of student academic credit data and create a list of students on academic warning. The list of students on warning will be written to a file. Each line of the input file will contain the student name (a single String with no spaces), the number of semester hours earned (an integer), the total quality points earned (a double). The following shows part of a typical...
(C++ programming) Need help with homework. Write a program that can be used to gather statistical data about the number of hours per week college students play video games. The program should perform the following steps: 1). Read data from the input file into a dynamically allocated array. The first number in the input file, n, represents the number of students that were surveyed. First read this number then use it to dynamically allocate an array of n integers. On...