//all imports : import java.awt.BorderLayout; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.util.*; import javax.swing.JButton; import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTextArea; import javax.swing.JTextField; public class Main extends JFrame { private JButton read = new JButton("Read File"), // read button accept = new JButton("Accept New Student"), // Accept new student button printAccepted = new JButton("Print Accepted Students"), // print accepted students button printReject = new JButton("Print Rejected Students"), // Print rejected students button save = new JButton("Save To File"), // Save to file button exit = new JButton("Exit");// Exit button private JTextArea text = new JTextArea();// text area private JFileChooser file, file2;// file chooser private BufferedReader in;// buffer reader private LinkedList list = new LinkedList();// list if type linkedList private ArrayList faculty = new ArrayList();// array list for the faculties private float tawjihiRate; private float highSchoolRate; private float placementRate; private ArrayList accepted = new ArrayList();// ArrayList for accepter students private ArrayList rejected = new ArrayList();// ArrayList for rejected students public Main() {// Constructor using fields JPanel p1 = new JPanel(new GridLayout(6, 1));// JPanel for adding buttons on it p1.add(read);//add read button to panel p1.add(accept);//add accept button to panel p1.add(printAccepted);//add printAccepted button to panel p1.add(printReject);//add printReject button to panel p1.add(save);//add save button to panel p1.add(exit);//add exit button to panel add(p1, BorderLayout.WEST);//make the panel at west add(text, BorderLayout.CENTER); //make textArea at the center exit.addActionListener(new ActionListener() {//Exit button action public void actionPerformed(ActionEvent arg0) { System.exit(0); } }); read.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { file = new JFileChooser(); file.setDialogTitle("File in Computer"); file.setAcceptAllFileFilterUsed(true); file.setCurrentDirectory(new File("C:\\Users\\soFTech\\Desktop")); open(); } }); printAccepted.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { for (int i = 0; i < accepted.size(); i++) { text.append(accepted.get(i) + "\n"); } } }); printReject.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { for (int i = 0; i < rejected.size(); i++) { text.append(rejected.get(i) + "\n"); } } }); accept.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { JFrame frame = new JFrame("Accept New Student"); JTextField name = new JTextField(), taw = new JTextField(), placment = new JTextField(), highschool = new JTextField(); JPanel p1 = new JPanel(new GridLayout(4, 2)); p1.add(new JLabel("Name")); p1.add(name); p1.add(new JLabel("Tawjihi Grade")); p1.add(taw); p1.add(new JLabel("Placement grade")); p1.add(placment); p1.add(new JLabel("High School Grade")); p1.add(highschool); JPanel p2 = new JPanel(new GridLayout(1, 2)); JButton add = new JButton("Add"), cancel = new JButton("Cancle"); p2.add(add); p2.add(cancel); frame.add(p2, BorderLayout.SOUTH); frame.add(p1, BorderLayout.CENTER); frame.setSize(getPreferredSize()); frame.setVisible(true); add.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { try { Student temp = new Student(name.getText(), Float.parseFloat(taw.getText()), Float.parseFloat(highschool.getText()), Float.parseFloat(placment.getText())); frame.setVisible(false); float tempTaw = tawjihiRate * temp.getTawjihiGrade(); float tempPla = placementRate * temp.getPlacmentTestGrade(); float tempHigh = highSchoolRate * temp.getHighSchoolGrade(); temp.setFinalGrade(tempTaw + tempPla + tempHigh); int count = 0; for (int i = 0; i < faculty.size(); i++) { if (compaire((int) faculty.get(i).min, (int) faculty.get(i).max, temp.getFinalGrade())) { accepted.add(temp.getName() + " " + faculty.get(i).name); break; } else { count++; } if (count == faculty.size()) { rejected.add(temp.getName() + " Rejected"); } } } catch (Exception e) { } } }); cancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { frame.setVisible(false); } }); } }); } public static void main(String[] args) { Main frame = new Main(); frame.setTitle("Project 1"); frame.setVisible(true); frame.setDefaultCloseOperation(EXIT_ON_CLOSE); frame.setSize(600, 500); frame.setResizable(false); frame.setLocationRelativeTo(null); } private void open() { if (file.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { open(file.getSelectedFile()); } } private void open1() { if (file.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { open1(file.getSelectedFile()); } } private void open(File file) { try { in = new BufferedReader(new FileReader(file));// open it to read it // again String str = ""; while ((str = in.readLine()) != null) { String[] temp = str.split(":"); String name = temp[0]; float tawjihi = Integer.parseInt(temp[1]); float highSchool = Integer.parseInt(temp[2]); float placement = Integer.parseInt(temp[3]); list.addLast(new Student(name, tawjihi, highSchool, placement)); } text.append("hi"); file2 = new JFileChooser(); file2.setDialogTitle("File in Computer"); file2.setAcceptAllFileFilterUsed(true); file2.setCurrentDirectory(new File("C:\\Users\\soFTech\\Desktop")); open1(); } catch (Exception e) { JOptionPane.showMessageDialog(this, "Cannot open file", "Problem", 0); } } private void open1(File file) { try { in = new BufferedReader(new FileReader(file));// open it to read it // again String str = ""; tawjihiRate = Float.parseFloat(in.readLine()); highSchoolRate = Float.parseFloat(in.readLine()); placementRate = Float.parseFloat(in.readLine()); int numOfFaculties = Integer.parseInt(in.readLine()); for (int i = 0; i < numOfFaculties; i++) { str = in.readLine(); String[] temp = str.split(":"); String name = temp[0]; String[] range = temp[1].split("-"); float max = Float.parseFloat(range[1]); float min = Float.parseFloat(range[0]); faculty.add(new Faculty(name, max, min)); } for (int i = 0; i < faculty.size(); i++) { text.append(faculty.get(i).toString() + "\n"); } Node curr = list.first; while (curr != null) { float tempTaw = tawjihiRate * curr.element.getTawjihiGrade(); float tempPla = placementRate * curr.element.getPlacmentTestGrade(); float tempHigh = highSchoolRate * curr.element.getHighSchoolGrade(); curr.element.setFinalGrade(tempTaw + tempPla + tempHigh); curr = curr.next; } Node curr1 = list.first; while (curr1 != null) { int count = 0; System.out.println(curr1.element.toString()); for (int i = 0; i < faculty.size(); i++) { if (compaire((int) faculty.get(i).min, (int) faculty.get(i).max, curr1.element.getFinalGrade())) { accepted.add(curr1.element.getName() + " " + faculty.get(i).name); break; } else { count++; } if (count == faculty.size()) { rejected.add(curr1.element.getName() + " Rejected"); } } curr1 = curr1.next; } } catch (Exception e) { JOptionPane.showMessageDialog(this, "Cannot open file", "Problem", 0); } } private boolean compaire(int min, int max, double finalGrade) { if ((int) finalGrade >= min && (int) finalGrade <= max) return true; else return false; } }