Advertisement
Guest User

Untitled

a guest
Aug 12th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. import javax.swing.JFrame;
  2. import java.io.FileNotFoundException;
  3. import java.io.File;
  4. import java.io.PrintWriter;
  5. import java.util.*;
  6.  
  7.  
  8.  
  9. public class StudentViewer
  10. {
  11. public static void main(String[] args) throws FileNotFoundException, NoSuchElementException
  12.  
  13. {
  14. File inputFile;
  15. File outputFile;
  16.  
  17. if (args.length >= 1)
  18. {
  19. inputFile = new File(args[0]);
  20. outputFile = new File(args[1]);
  21. PrintWriter out = new PrintWriter(outputFile);
  22. int lineNumber = 1;
  23.  
  24. Scanner in = new Scanner(inputFile);
  25.  
  26. ArrayList<AppliedStudent> names = new ArrayList<AppliedStudent>();
  27. while(in.hasNext())
  28. try
  29. {
  30. String line = in.next();
  31. Scanner lineScanner = new Scanner(line);
  32. lineScanner.useDelimiter("\\s*,\\s*");
  33.  
  34.  
  35.  
  36.  
  37. String lastname = lineScanner.next();
  38. String firstname = lineScanner.next();
  39. double gpa = lineScanner.nextDouble();
  40. String major = lineScanner.next();
  41.  
  42.  
  43.  
  44. if(major.equals("MAT"))
  45. {
  46. names.add(new AppliedMath(lastname, firstname, gpa, major));
  47. }
  48. if(major.equals("ACO"))
  49. {
  50. String concentration = lineScanner.next();
  51.  
  52. if(concentration.equals("Database") || concentration.equals("Network") || concentration.equals("DigitalMedia"))
  53. names.add(new AppliedComputing(lastname, firstname, gpa, major, concentration));
  54. }
  55.  
  56. else
  57. {
  58. out.println("No such element at line " + lineNumber);
  59. }
  60.  
  61.  
  62. lineNumber++ ;
  63.  
  64. }
  65. catch (InputMismatchException exception)
  66. {
  67. out.println("GPA is not a number at line " + lineNumber);
  68. }
  69.  
  70. Collections.sort(names);
  71. in.close();
  72. out.close();
  73.  
  74.  
  75.  
  76. JFrame frame = new StudentFrame(names);
  77. frame.setTitle("Applied MNS Students");
  78. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  79. frame.setVisible(true);
  80.  
  81.  
  82. }
  83. else
  84. throw new FileNotFoundException("File Not Found");
  85.  
  86. }
  87.  
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement