Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- //imports
- public class CreateFinalGrade {
- private Scanner input;
- private Formatter output;
- private GradeRecord[] records;
- CreateFinalGrade(){
- }
- // This method opens an input file, whose name is given in the parameter, File.
- // The method also initializes the instance variable: records, and its array
- // length to hold all the records. The length, denoting the total number of
- // records, is given in the first line of the input file.
- public void openInputFile( String File ) {
- input = new Scanner(File);
- int arraylength = input.nextInt();
- records = new GradeRecord[arraylength];
- }
- // The method closes the input file
- public void closeInputFile() {
- input.close();
- }
- // This method reads all records from the input file to an array of
- // GradeRecord objects.
- public void readRecords() {
- //Scanner scanner = new Scanner(input);
- //input.useDelimiter(" ");
- for (int i=0 ; i<records.length;i++){
- records[i].setFirstName(input.next());
- records[i].setLastName(input.next());
- records[i].setExam1(input.nextInt());
- records[i].setExam2(input.nextInt());
- records[i].setExam3(input.nextInt());
- records[i].setExam4(input.nextInt());
- input.nextLine();
- }
- }
- // This method processes each record to generate the values of emailID,
- // average, and finalGrade.
- public void processFinalGrade() {
- for(int i =0;i<records.length;i++){
- records[i].setAverage( (records[i].getExam1() + records[i].getExam2() +records[i].getExam3() + records[i].getExam4())/4);
- records[i]. genFinalGrade();
- }
- }
- // This method opens an output file for storing updated student records.
- public void openOutputFile( String File ) throws IOException {
- output = new Formatter(new FileWriter(File));
- }
- // This method close the output file.
- public void closeOutputFile() {
- output.close();
- }
- // This method write all the updated records in the same order to
- // the output file.
- public void writeRecords() {
- for(int i = 0;i<records.length;i++)
- output.format("%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%c\n",records[i].getFirstName(),records[i].getLastName(),records[i].getEmailID(),records[i].getExam1(),records[i].getExam2(),records[i].getExam3(),records[i].getExam4(),records[i].getAverage(),records[i].getFinalGrade());
- }
- // define any methods or constructors, if necessary.
- }
Add Comment
Please, Sign In to add comment