Guest User

Untitled

a guest
Jul 17th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.38 KB | None | 0 0
  1.  
  2. import java.io.*;
  3. import java.util.*;
  4.  
  5. //imports
  6. public class CreateFinalGrade {
  7.  
  8. private Scanner input;
  9. private Formatter output;
  10. private GradeRecord[] records;
  11. CreateFinalGrade(){
  12.  
  13. }
  14. // This method opens an input file, whose name is given in the parameter, File.
  15. // The method also initializes the instance variable: records, and its array
  16. // length to hold all the records. The length, denoting the total number of
  17. // records, is given in the first line of the input file.
  18. public void openInputFile( String File ) {
  19. input = new Scanner(File);
  20.  
  21. int arraylength = input.nextInt();
  22. records = new GradeRecord[arraylength];
  23. }
  24.  
  25. // The method closes the input file
  26. public void closeInputFile() {
  27. input.close();
  28. }
  29.  
  30. // This method reads all records from the input file to an array of
  31. // GradeRecord objects.
  32. public void readRecords() {
  33. //Scanner scanner = new Scanner(input);
  34. //input.useDelimiter(" ");
  35. for (int i=0 ; i<records.length;i++){
  36. records[i].setFirstName(input.next());
  37. records[i].setLastName(input.next());
  38. records[i].setExam1(input.nextInt());
  39. records[i].setExam2(input.nextInt());
  40. records[i].setExam3(input.nextInt());
  41. records[i].setExam4(input.nextInt());
  42. input.nextLine();
  43. }
  44. }
  45.  
  46. // This method processes each record to generate the values of emailID,
  47. // average, and finalGrade.
  48. public void processFinalGrade() {
  49. for(int i =0;i<records.length;i++){
  50. records[i].setAverage( (records[i].getExam1() + records[i].getExam2() +records[i].getExam3() + records[i].getExam4())/4);
  51. records[i]. genFinalGrade();
  52. }
  53. }
  54.  
  55. // This method opens an output file for storing updated student records.
  56. public void openOutputFile( String File ) throws IOException {
  57. output = new Formatter(new FileWriter(File));
  58.  
  59. }
  60.  
  61. // This method close the output file.
  62. public void closeOutputFile() {
  63. output.close();
  64. }
  65.  
  66. // This method write all the updated records in the same order to
  67. // the output file.
  68. public void writeRecords() {
  69. for(int i = 0;i<records.length;i++)
  70. 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());
  71. }
  72.  
  73. // define any methods or constructors, if necessary.
  74. }
Add Comment
Please, Sign In to add comment