Subject - Java Hi - Requesting help here on a tough assignment. The ask is to cr
ID: 662955 • Letter: S
Question
Subject - Java
Hi - Requesting help here on a tough assignment. The ask is to create a java program that will take two arguments: the first is the input file name, the second is the output file name. The input file will have a list of written grades and student names (See attached) and the idea is to compute a weighted average of the score and assign a letter grade for each student in alphabetical order. Simultaneously the program should output the average scores of all the students, the maximum and the minimum for each assignment in a console. Here's the output in the output file:
Anne Latner: B
Ariana B. Smith: A
Bill Gates: F
Emily Gonzales: B
Escobar Morris: C
Jennifer L: B
Maria Jones: D
Thui Bhu: A
and the console output would be the following:
C:>java TestLetterGrader input_data.txt output_data.txt
Letter grade has been calculated for students listed in input file input_data.txt and written to output file output_data.txt
Here is the class averages:
Q1 Q2 Q3 Q4 MidI MidII Final
Average: 82.25 80.38 82.25 83.88 81.38 84.13 78.63
Minimum: 60 54 38 62 62 60 50
Maximum: 100 90 100 100 99 100 95
Press ENTER to continue . . .
I do know how to ask for two inputs from the user via eclipse (IDE) or command line and output strings into the output file and also use a series of system.out.print commands to print to the screen. Figuring out how to calculate the weighted average of the numbers and also assigning the grade is not a problem.
What I don't know are the following:
1 - How to alphabetically rearrange the student's names to display the grade instead of the order in which they are read from the input file.
2 - How to retrieve and show the min and max value for each assignment in the group? i.e. In Q1 column the min is 60 and the max is 100
Below is the image of the input file. Help with some code samples on the two above scenarios if possible will be greatly appreciated. Thanks!
Explanation / Answer
ok...your first question is ..how to read inputs from console from user...
import java.util.Scanner; //importing statement
Scanner sc = new Scanner(System.in); //scanner class decalration
String filename = sc.nextLine(); //reading string from user
int number = sc.nextInt(); //reading integer from user
-----------------------------------------------------------------------------------------------------------------------
second question is rearrange names by alphabetical order
to achieve this we can use compareTo method
sample code
so Now I am using bubble sort using compareTo method....sorting student names stored in an array
for (int i = 0; i < size; i++)
{
for (int j = i + 1; j < size; j++)
{
if (Student_names[i].compareTo(Student_names[j])>0)
{
tempvariable = Student_names[i];
Student_names[i] = Student_names[j];
Student_names[j] = tempvariable;
}
}
}
---------------------------------------------------------------------------------------------------------------
3)
retrieving min and max of each assignment
my suggestion is...first we declare two dimensional array one is to store max and min for each assigment.
while iterating values for each assignment from file we will compare them and store into this 2d array...
int max,min;
while(line.hasNext()){
if(max<line.next()){
max = line.next();
}
if(min>line.next()){
min = line.next();
}
}
maxmin[0][0]=max;
maxmin[0][1]=min;
in this way we can store....2d array i & j counter variables incrementing inside while loop.