Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java help: How would you write a java program, using Scanner.in, that creates a

ID: 3634829 • Letter: J

Question

Java help: How would you write a java program, using Scanner.in, that creates a file containing a table showing the student ID numbers and averages of all the students in a course in ascending order by ID number. The input to the program is a file containing student records. Each student record consists of a student’s first name, a student’s last name, a student’s ID number, and the student’s average. Each of the fields of the record is separated by a newline character and there is one newline character separating one student’s record from the next record in the file. Each student’s ID number has the following form CXX-XXXXX. C is the letter B, M, or P and the X’s are digits. You may assume that the data was validated before it was put in the file. You may assume that there will not be more than one hundred student records in the input file. Your program must allow the user to enter the names of both the input file and the output file. Create a system of parallel arrays to store the data needed from the file. One array should store the student’s ID numbers and one array should store the student’s averages. The arrays should be related by the subscripts. The first student’s ID number is in the student ID array at subscript 0 and the student’s average is the averages array at subscript 0.

public class gpa
{
public static void main(String[] args)throws Exception
{
DecimalFormat num=new DecimalFormat("#######.00"); // Create format for name num (courseName)
DecimalFormat numgpa=new DecimalFormat("##.00"); // Create format for name numgpa (gpa)


// variable names

double gp=0.0; // grade point
double totalgp=0.0; // total grade point
double n=0.0; //number of courses
double gpa=0.0; //greade point average
String str; // to hold answer input to prompt
String name;
String firstName;
String lastName;
String inGrade; //input grade
String courseName; //course name
int courseSection; //section number of course
char repeat; //to hold yes 'Y' or no 'N' answer
char letGrade; //input letter grade
int idNumber=0; //student number
int i=0; //number of courses input
int h=0; //number of student name in file


// declare scan & associate with actual data file
File scan = new File ("inputgpa.txt");

// Initialize scanner to read from file
Scanner input = new scanner(scan);


// Open file <strong class="highlight">and</strong> continue if there is more data in file
while (input.hasNext())
{
for(h=0; h<name.length; h++)
{
//Read name from file
name = input.nextLine();

// Initialize Scanner to read from DOS window.
Scanner input = new Scanner(System.in);



idNumber = input.nextInt();

//Output name
System.out.println(" BCCC "+"Grade Report For ");//1st row
System.out.println(" "+name); //2nd row
System.out.println(" "+idNumber); //3rd row

//Input number of courses

n = input.nextInt();

//Start count loop to read all courses & their letter grades
for(i=0; i<=n; i++)
{
//write prompt for user input course name

courseName = input.next();

//input section number
courseSection = input.nextInt();

//input section number

letGrade = input.next().charAt(0);

//compute gp
switch(letGrade)
{
case 'A': gp=4; break;
case 'B': gp=3; break;
case 'C': gp=2; break;
case 'D': gp=1; break;
case 'F': gp=0; break;
default: System.out.println("Invalid course grade");
} //end Switch loop

// Compute to find <strong class="highlight">the</strong> total grade points.
totalgp+= gp;

//Output layout on <strong class="highlight">the</strong> DOS window
System.out.println(courseName+"."+courseSection+" "+letGrade+" "+gp);

}//End of 2nd For loop

//compute gpa
gpa = totalgp / n;

//output layout & gpa to DOS window
System.out.println("--------------------------------------");
System.out.println(" GPA: "+ gpa);
System.out.println(); //Prints a blank line

}//End of 1st For loop
}//End of While loop

}//closemain method
}//close class gpa

Explanation / Answer

import java.io.File; import java.text.DecimalFormat; import java.util.Scanner; public class gpa { public static void main(String[] args)throws Exception { DecimalFormat num=new DecimalFormat("#######.00"); // Create format for name num (courseName) DecimalFormat numgpa=new DecimalFormat("##.00"); // Create format for name numgpa (gpa) // variable names double gp=0.0; // grade point double totalgp=0.0; // total grade point double n=0.0; //number of courses double gpa=0.0; //greade point average String str; // to hold answer input to prompt String name; String firstName; String lastName; String inGrade; //input grade String courseName; //course name int courseSection; //section number of course char repeat; //to hold yes 'Y' or no 'N' answer char letGrade; //input letter grade int idNumber=0; //student number int i=0; //number of courses input int h=0; //number of student name in file // declare scan & associate with actual data file File scan = new File ("inputgpa.txt"); // Initialize scanner to read from file Scanner input = new Scanner(scan); // Open file and continue if there is more data in file while (input.hasNext()) { name = input.nextLine(); for(h=0; h
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote