Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.JFrame;
- import java.io.FileNotFoundException;
- import java.io.File;
- import java.io.PrintWriter;
- import java.util.*;
- public class StudentViewer
- {
- public static void main(String[] args) throws FileNotFoundException, NoSuchElementException
- {
- File inputFile;
- File outputFile;
- if (args.length >= 1)
- {
- inputFile = new File(args[0]);
- outputFile = new File(args[1]);
- PrintWriter out = new PrintWriter(outputFile);
- int lineNumber = 1;
- Scanner in = new Scanner(inputFile);
- ArrayList<AppliedStudent> names = new ArrayList<AppliedStudent>();
- while(in.hasNext())
- try
- {
- String line = in.next();
- Scanner lineScanner = new Scanner(line);
- lineScanner.useDelimiter("\\s*,\\s*");
- String lastname = lineScanner.next();
- String firstname = lineScanner.next();
- double gpa = lineScanner.nextDouble();
- String major = lineScanner.next();
- if(major.equals("MAT"))
- {
- names.add(new AppliedMath(lastname, firstname, gpa, major));
- }
- if(major.equals("ACO"))
- {
- String concentration = lineScanner.next();
- if(concentration.equals("Database") || concentration.equals("Network") || concentration.equals("DigitalMedia"))
- names.add(new AppliedComputing(lastname, firstname, gpa, major, concentration));
- }
- else
- {
- out.println("No such element at line " + lineNumber);
- }
- lineNumber++ ;
- }
- catch (InputMismatchException exception)
- {
- out.println("GPA is not a number at line " + lineNumber);
- }
- Collections.sort(names);
- in.close();
- out.close();
- JFrame frame = new StudentFrame(names);
- frame.setTitle("Applied MNS Students");
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setVisible(true);
- }
- else
- throw new FileNotFoundException("File Not Found");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement