Create a class called Student which stores
• the name of the student
• the grade of the student
• Write a main method that asks the user for the name of theinput file and the name of the output file. Main should open theinput file for reading . It should read in the first and last nameof each student into the Student’s name field. It should read thegrade into the grade field.
• Calculate the average of all students’ grades.
• Open the output file, for writing, and print all the students’names on one line and the average on the next line.
• Average should only have 1 digit after the decimal
• “Average†should be left justified in a field of 15characters. The average # should be right justified in a field of10 spaces
Sample input:
Minnie Mouse 98.7
Bob Builder 65.8
Mickey Mouse 95.1
Popeye SailorMan 78.6
Output:
Minnie Mouse, Bob Builder, Mickey Mouse, PopeyeSailorMan
Average:Â Â Â Â Â Â 84.5
How can I fix my code to get the sameoutput
public class Student {
public static void main(String[] args)throws IOException{
Scanner k=new Scanner(System.in);
String name;
float grade;
float Average=(float) 0.0;
float sum=(float) 0.0;
 Â
System.out.println(\"Enter input file name:\");
String input=k.nextLine();
System.out.println(\"Enter output file name:\");
String output=k.nextLine();
 Â
PrintWriter pw = new PrintWriter(\"students.txt\");
pw.print(\"Minnie Mouse 98.7\nBob Builder 65.8\nMickey Mouse95.1\nPopeye SailorMan 78.6\n\");
pw.close();
PrintWriter pw2 = new PrintWriter(\"students2.txt\");
pw2.print(\"Donald Duck 77.77\nTweety Bird 55.555\nCharlie Brown95.231\n\");
pw2.close();
/* End of creating the input file */
while(k.hasNext())
{
name=k.next();
grade=k.nextFloat();
Average+=grade;
sum++;
System.out.printf(\"name, \", name);
}
grade=Average/sum;
System.out.printf(\"\n%-15s%10.1f\",\"Average\", grade);Â Â
/* test output file */
Scanner testOutput = new Scanner(new File(\"average.txt\"));
while(testOutput.hasNext())
System.out.println(testOutput.nextLine());
/* end of test output file */
}
}
 Â