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: 3634826 • 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.

Here's my code: (If you can, can you replace the <strong class="highlight">java</strong>.text.*)

import <strong class="highlight">java</strong>.text.*; // format output
import <strong class="highlight">java</strong>.util.*; // Scanner class
import <strong class="highlight">java</strong>.io.*; //Needed for File classes


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 <strong class="highlight">the</strong> prompt
String name; // <strong class="highlight"><vb_highlight>student</strong></vb_highlight> name in file
String firstName; // <strong class="highlight"><vb_highlight>student</strong></vb_highlight> first name
String lastName; // <strong class="highlight"><vb_highlight>student</strong></vb_highlight> last name
String inGrade; //input grade
String courseName; //course name
int courseSection; //section number of <strong class="highlight">the</strong> course
char repeat; //to hold yes 'Y' or no 'N' answer
char letGrade; //input letter grade
int idNumber=0; //student <strong class="highlight">ID</strong> number
int i=0; //number of courses input
int h=0; //number of <strong class="highlight"><vb_highlight>student</strong></vb_highlight> name in <strong class="highlight">the</strong> 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);

//Dispay <strong class="highlight">the</strong> <strong class="highlight"><vb_highlight>student</strong></vb_highlight> name to DOS window
System.out.print(" <strong class="highlight"><vb_highlight>Student</strong></vb_highlight> name is: "+ name);

//Input <strong class="highlight">the</strong> <strong class="highlight"><vb_highlight>student</strong></vb_highlight> <strong class="highlight">ID</strong> number
System.out.print("Enter"+name+"'s"+" <strong class="highlight"><vb_highlight>student</strong></vb_highlight> <strong class="highlight">ID</strong> Number: ");
idNumber = input.nextInt();

//Output name & <strong class="highlight">id</strong> to DOS window
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
System.out.print("Enter <strong class="highlight">the</strong> 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
System.out.print("Enter <strong class="highlight">the</strong> number of courses: ");
courseName = input.next();

//input section number of <strong class="highlight">the</strong> course
System.out.print("Enter <strong class="highlight">the</strong> section number of this course: ");
courseSection = input.nextInt();

//input section number of <strong class="highlight">the</strong> course
System.out.print("Enter <strong class="highlight">the</strong> letter grade of this course: ");
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

Please Rate:Thanks

import <strong class="highlight">java</strong>.text.*; // format output
import <strong class="highlight">java</strong>.util.*; // Scanner class
import <strong class="highlight">java</strong>.io.*; //Needed for File classes


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 <strong class="highlight">the</strong> prompt
String name; // <strong class="highlight"><vb_highlight>student</strong></vb_highlight> name in file
String firstName; // <strong class="highlight"><vb_highlight>student</strong></vb_highlight> first name
String lastName; // <strong class="highlight"><vb_highlight>student</strong></vb_highlight> last name
String inGrade; //input grade
String courseName; //course name
int courseSection; //section number of <strong class="highlight">the</strong> course
char repeat; //to hold yes 'Y' or no 'N' answer
char letGrade; //input letter grade
int idNumber=0; //student <strong class="highlight">ID</strong> number
int i=0; //number of courses input
int h=0; //number of <strong class="highlight"><vb_highlight>student</strong></vb_highlight> name in <strong class="highlight">the</strong> 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);

//Dispay <strong class="highlight">the</strong> <strong class="highlight"><vb_highlight>student</strong></vb_highlight> name to DOS window
System.out.print(" <strong class="highlight"><vb_highlight>Student</strong></vb_highlight> name is: "+ name);

//Input <strong class="highlight">the</strong> <strong class="highlight"><vb_highlight>student</strong></vb_highlight> <strong class="highlight">ID</strong> number
System.out.print("Enter"+name+"'s"+" <strong class="highlight"><vb_highlight>student</strong></vb_highlight> <strong class="highlight">ID</strong> Number: ");
idNumber = input.nextInt();

//Output name & <strong class="highlight">id</strong> to DOS window
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
System.out.print("Enter <strong class="highlight">the</strong> 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
System.out.print("Enter <strong class="highlight">the</strong> number of courses: ");
courseName = input.next();

//input section number of <strong class="highlight">the</strong> course
System.out.print("Enter <strong class="highlight">the</strong> section number of this course: ");
courseSection = input.nextInt();

//input section number of <strong class="highlight">the</strong> course
System.out.print("Enter <strong class="highlight">the</strong> letter grade of this course: ");
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

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