diff --git a/.project b/.project
index 6addb9c..693be40 100644
--- a/.project
+++ b/.project
@@ -14,4 +14,15 @@
org.eclipse.jdt.core.javanature
+
+
+ 1712506907498
+
+ 30
+
+ org.eclipse.core.resources.regexFilterMatcher
+ node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__
+
+
+
diff --git a/Delete.java b/Delete.java
index 9efa73f..7fcec19 100644
--- a/Delete.java
+++ b/Delete.java
@@ -7,167 +7,143 @@
import java.util.*;
import static javax.swing.JOptionPane.showMessageDialog;
-public class Delete extends JFrame implements ActionListener
-{
+public class Delete extends JFrame implements ActionListener {
private JLabel usnL;
private JTextField usnT;
- private JButton delete,back;
-
- Container con=null;
- String usn="";
+ private JButton delete, back;
- Delete()
- {
+ Container con = null;
+
+ Delete() {
super("Delete Record");
con = getContentPane();
con.setLayout(null);
- Color lightBlue = new Color(0,255,255);
+ Color lightBlue = new Color(0, 255, 255);
con.setBackground(lightBlue);
- con.setSize(300,300);
+ con.setSize(300, 300);
con.setLayout(null);
con.setVisible(true);
Font font = new Font("Verdana", Font.BOLD, 16);
- Color blue = new Color(30,144,255);
- usnL=new JLabel("Enter USN of record to be deleted");
- usnL.setBounds(400, 50, 700,150);
+ Color blue = new Color(30, 144, 255);
+ usnL = new JLabel("Enter USN of record to be deleted");
+ usnL.setBounds(400, 50, 700, 150);
usnL.setFont(font);
usnL.setForeground(Color.BLACK);
- usnT=new JTextField(200);
- usnT.setBounds(725,100,250,50);
+ usnT = new JTextField(200);
+ usnT.setBounds(725, 100, 250, 50);
usnT.setFont(font);
usnT.setForeground(Color.BLACK);
delete = new JButton("Delete");
- delete.setBounds(400,600,150,40);
- delete.addActionListener(this);
+ delete.setBounds(400, 600, 150, 40);
+ delete.addActionListener(this);
delete.setFont(font);
- Color pul = new Color(0,0,255);
- Border bored = BorderFactory.createLineBorder(pul,5);
+ Color pul = new Color(0, 0, 255);
+ Border bored = BorderFactory.createLineBorder(pul, 5);
delete.setBorder(bored);
delete.setForeground(Color.WHITE);
delete.setBackground(blue);
back = new JButton("Go Back");
- back.setBounds(600,600,150,40);
- back.addActionListener(this);
+ back.setBounds(600, 600, 150, 40);
+ back.addActionListener(this);
back.setFont(font);
back.setBorder(bored);
back.setForeground(Color.WHITE);
back.setBackground(blue);
-
con.add(usnL);
- con.add(usnT);
+ con.add(usnT);
con.add(delete);
con.add(back);
}
- public void actionPerformed(ActionEvent ae)
- {
- if(ae.getSource()==delete)
- {
- try{
+ public void actionPerformed(ActionEvent ae) {
+ if (ae.getSource() == delete) {
+ try {
String usn = usnT.getText();
- String usn1="",r;
- int count=0;
- File file = new File("student.txt"); //student
- BufferedReader br = new BufferedReader(new FileReader(file));
-
- File file1 = new File("journal.txt"); //journal
- BufferedReader br1 = new BufferedReader(new FileReader(file1));
-
- File temp = new File("temp.txt"); //student temp
- Boolean createNewFile = temp.createNewFile();
- BufferedWriter pw = new BufferedWriter(new FileWriter(temp));
-
- File temp1 = new File("temp1.txt"); //journal temp
- Boolean createNewFile1 = temp.createNewFile();
- BufferedWriter pw1 = new BufferedWriter(new FileWriter(temp1));
- while((r= br.readLine()) !=null)
- {
- String[] result = r.split("\\|");
- usn1=result[1];
- if(usn1.equals(usn))
- {
- count=1;
+ boolean found = false;
+ File studentFile = new File("student.csv");
+ File tempStudentFile = new File("temp.csv");
+
+ BufferedReader studentReader = new BufferedReader(new FileReader(studentFile));
+ BufferedWriter studentWriter = new BufferedWriter(new FileWriter(tempStudentFile));
+
+ String studentLine;
+ while ((studentLine = studentReader.readLine()) != null) {
+ String[] parts = studentLine.split(",");
+ if (parts.length > 1 && parts[1].equals(usn)) {
+ found = true;
continue;
}
- else
- {
- pw.write(r);
- pw.write("\n");
- }
+ studentWriter.write(studentLine);
+ studentWriter.newLine();
}
- while((r= br1.readLine()) !=null)
- {
- String[] result = r.split("\\|");
- usn1=result[0];
- if(usn1.equals(usn))
- {
+ studentReader.close();
+ studentWriter.close();
+
+ if (found) {
+ studentFile.delete();
+ tempStudentFile.renameTo(studentFile);
+ }
+
+ File journalFile = new File("journal.csv");
+ File tempJournalFile = new File("temp.csv");
+
+ BufferedReader journalReader = new BufferedReader(new FileReader(journalFile));
+ BufferedWriter journalWriter = new BufferedWriter(new FileWriter(tempJournalFile));
+
+ String journalLine;
+ while ((journalLine = journalReader.readLine()) != null) {
+ String[] parts = journalLine.split(",");
+ if (parts.length > 0 && parts[0].equals(usn)) {
continue;
}
- else
- {
- pw1.write(r);
- pw1.write("\n");
- }
+ journalWriter.write(journalLine);
+ journalWriter.newLine();
}
- if(count == 0)
- showMessageDialog(null, "Invalid USN");
- else
+ journalReader.close();
+ journalWriter.close();
+
+ if (found) {
+ journalFile.delete();
+ tempJournalFile.renameTo(journalFile);
showMessageDialog(null, "Record Deleted!");
+ } else {
+ showMessageDialog(null, "Record with provided USN not found!");
+ }
- pw.flush();
- pw.close();
- br.close();
- pw1.close();
- br1.close();
-
- file.delete();
- temp.renameTo(file);
- file1.delete();
- temp1.renameTo(file1);
-
- }
- catch(Exception e)
- {
+ } catch (Exception e) {
e.printStackTrace();
}
this.dispose();
- Home h=new Home();
- h.setSize(2300,790);
+ Home h = new Home();
+ h.setSize(2300, 790);
h.setVisible(true);
}
- if(ae.getSource()==back)
- {
- try
- {
+ if (ae.getSource() == back) {
+ try {
this.dispose();
- Home h=new Home();
- h.setSize(2300,790);
+ Home h = new Home();
+ h.setSize(2300, 790);
h.setVisible(true);
- }
- catch(Exception e)
- {
+ } catch (Exception e) {
e.printStackTrace();
}
}
}
-
-
-
- public static void main(String args[])
- {
- Delete del=new Delete();
- del.setSize(2300,790);
- del.setVisible(true);
- }
+
+ public static void main(String args[]) {
+ Delete del = new Delete();
+ del.setSize(2300, 790);
+ del.setVisible(true);
+ }
}
diff --git a/Display.java b/Display.java
index 7959dd1..a6efe53 100644
--- a/Display.java
+++ b/Display.java
@@ -1,142 +1,119 @@
import java.awt.*;
import javax.swing.*;
import javax.swing.border.Border;
-
import java.awt.event.*;
import java.io.*;
import java.util.*;
-import static javax.swing.JOptionPane.showMessageDialog;
-public class Display extends JFrame implements ActionListener
-{
-
- private JLabel displayheading;
+public class Display extends JFrame implements ActionListener {
+
+ private JLabel displayHeading;
private JTextArea output;
- private JButton display,back;
-
- Container con=null;
+ private JButton display, back;
- Display()
- {
+ Container con = null;
+ Display() {
super("Display Record");
con = getContentPane();
con.setLayout(null);
- Color lightBlue = new Color(0,255,255);
+ Color lightBlue = new Color(0, 255, 255);
con.setBackground(lightBlue);
- con.setSize(300,300);
+ con.setSize(300, 300);
con.setLayout(null);
con.setVisible(true);
- Color blue = new Color(30,144,255);
+ Color blue = new Color(30, 144, 255);
Font font = new Font("Verdana", Font.BOLD, 16);
- displayheading=new JLabel("The records are:");
- displayheading.setBounds(200, 2, 700,150);
- displayheading.setFont(font);
- displayheading.setForeground(Color.BLACK);
+ displayHeading = new JLabel("The records are:");
+ displayHeading.setBounds(200, 2, 700, 150);
+ displayHeading.setFont(font);
+ displayHeading.setForeground(Color.BLACK);
- output=new JTextArea();
- output.setBounds(20, 150, 1200,400);
+ output = new JTextArea();
output.setFont(font);
output.setForeground(Color.BLACK);
output.setEditable(false);
+ output.setLineWrap(true); // Wrap lines
+ output.setWrapStyleWord(true); // Wrap at word boundaries
+
+ JScrollPane scrollPane = new JScrollPane(output); // Add scroll bar
+ scrollPane.setBounds(20, 150, 1400, 400);
+ scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
display = new JButton("Display");
- display.setBounds(400,600,150,40);
- display.addActionListener(this);
+ display.setBounds(400, 600, 150, 40);
+ display.addActionListener(this);
display.setFont(font);
- Color pul = new Color(0,0,255);
- Border bored = BorderFactory.createLineBorder(pul,5);
+ Color pul = new Color(0, 0, 255);
+ Border bored = BorderFactory.createLineBorder(pul, 5);
display.setBorder(bored);
display.setForeground(Color.WHITE);
display.setBackground(blue);
back = new JButton("Go Back");
- back.setBounds(600,600,150,40);
- back.addActionListener(this);
+ back.setBounds(600, 600, 150, 40);
+ back.addActionListener(this);
back.setFont(font);
back.setBorder(bored);
back.setForeground(Color.WHITE);
back.setBackground(blue);
- con.add(displayheading);
- con.add(output);
+ con.add(displayHeading);
+ con.add(scrollPane); // Add scroll pane instead of output directly
con.add(display);
con.add(back);
-
}
- public void actionPerformed(ActionEvent ae)
- {
- if(ae.getSource()==display)
- {
- try
- {
- String name = "", usn ="", sem = "", branch = "", cgpa= "", nob="", company="",ctc="",comments="", r;
-
- File temp = new File("temp.txt");
- Boolean createNewFile1 = temp.createNewFile();
- BufferedWriter pw = new BufferedWriter(new FileWriter("temp.txt"));
- String b = "NAME\t|USN\t|SEM\t|BRANCH\t|CGPA\t|NOB\t|COMPANY\t|CTC\t|COMMENTS";
- pw.write(b);
- pw.write("\n");
-
- BufferedReader br = new BufferedReader(new FileReader("student.txt"));
- while((r= br.readLine()) !=null)
- {
- String[] result = r.split("\\|");
- name=result[0];
- usn=result[1];
- sem= result[2];
- branch=result[3];
- cgpa=result[4];
- nob=result[5];
- company=result[6];
- ctc=result[7];
- comments=result[8];
- if(name.equals("999"))
- break;
- String bb = name + "\t|" + usn + "\t|" + sem + "\t|" + branch + "\t|" + cgpa + "\t|" + nob + "\t|" + company + "\t|" + ctc + "\t|" + comments;
- pw.write(bb);
+ public void actionPerformed(ActionEvent ae) {
+ if (ae.getSource() == display) {
+ try {
+ BufferedWriter pw = new BufferedWriter(new FileWriter("temp.csv"));
+ String header = "NAME,USN,SEM,BRANCH,CGPA,NOB,COMPANY,CTC,COMMENTS";
+ pw.write(header);
+ pw.write("\n" + "------------------------------------------------------------------------------------------------------------------------------------------------------------" + "\n");
+
+ BufferedReader br = new BufferedReader(new FileReader("student.csv"));
+ String line;
+ while ((line = br.readLine()) != null) {
+ pw.write(line);
pw.write("\n");
- }
+ }
br.close();
pw.close();
- File file = new File("temp.txt");
+
+ File file = new File("temp.csv");
BufferedReader br1 = new BufferedReader(new FileReader(file));
- output.read(br1,null);
- br1.close();
+ StringBuilder displayText = new StringBuilder();
+ while ((line = br1.readLine()) != null) {
+ displayText.append(String.format("%-40s%n", line.replace(",", "\t")));
+ }
+ output.setText(displayText.toString());
+ br1.close();
output.requestFocus();
- file.delete();
- }
- catch(Exception e)
- {
+ file.delete();
+ } catch (Exception e) {
e.printStackTrace();
}
}
- if(ae.getSource()==back)
- {
- try
- {
+ if (ae.getSource() == back) {
+ try {
this.dispose();
- Home h=new Home();
- h.setSize(2300,790);
+ Home h = new Home();
+ h.setSize(2600, 790);
h.setVisible(true);
- }
- catch(Exception e)
- {
+ } catch (Exception e) {
e.printStackTrace();
}
}
}
- public static void main(String args[])
- {
- Display dis=new Display();
- dis.setSize(2300,790);
- dis.setVisible(true);
- }
+ public static void main(String args[]) {
+ Display dis = new Display();
+ dis.setSize(2600, 790);
+ dis.setVisible(true);
+ }
}
diff --git a/Eligible.java b/Eligible.java
index 25de75e..6e28a2a 100644
--- a/Eligible.java
+++ b/Eligible.java
@@ -7,69 +7,66 @@
import java.util.*;
import static javax.swing.JOptionPane.showMessageDialog;
-public class Eligible extends JFrame implements ActionListener
-{
-
- private JLabel eligibleheading,eligibleheading1,eligibleheading2,eligibleheading3;
+public class Eligible extends JFrame implements ActionListener {
+
+ private JLabel eligibleheading, eligibleheading1, eligibleheading2, eligibleheading3;
private JTextArea output;
- private JButton display,back;
-
- Container con=null;
+ private JButton display, back;
+
+ Container con = null;
- Eligible()
- {
+ Eligible() {
super("Placement Eligibility");
con = getContentPane();
con.setLayout(null);
- Color lightBlue = new Color(0,255,255);
+ Color lightBlue = new Color(0, 255, 255);
con.setBackground(lightBlue);
- con.setSize(300,300);
+ con.setSize(300, 300);
con.setLayout(null);
con.setVisible(true);
Font font = new Font("Verdana", Font.BOLD, 16);
- Color blue = new Color(30,144,255);
- eligibleheading=new JLabel("PLACEMENT ELIGIBILITY");
- eligibleheading.setBounds(550, 5, 700,20);
+ Color blue = new Color(30, 144, 255);
+ eligibleheading = new JLabel("PLACEMENT ELIGIBILITY");
+ eligibleheading.setBounds(550, 5, 700, 20);
eligibleheading.setFont(font);
eligibleheading.setForeground(Color.BLACK);
- eligibleheading1=new JLabel("PLATINUM PACKAGE: CGPA>=8 AND NO BACKLOGS ALLOWED");
- eligibleheading1.setBounds(200, 50, 700,20);
+ eligibleheading1 = new JLabel("PLATINUM PACKAGE: CGPA>=8 AND NO BACKLOGS ALLOWED");
+ eligibleheading1.setBounds(200, 50, 700, 20);
eligibleheading1.setFont(font);
eligibleheading1.setForeground(Color.BLACK);
- eligibleheading2=new JLabel("GOLD PACKAGE: CGPA>=7 AND NO BACKLOGS ALLOWED");
- eligibleheading2.setBounds(200, 75, 700,20);
+ eligibleheading2 = new JLabel("GOLD PACKAGE: CGPA>=7 AND NO BACKLOGS ALLOWED");
+ eligibleheading2.setBounds(200, 75, 700, 20);
eligibleheading2.setFont(font);
eligibleheading2.setForeground(Color.BLACK);
- eligibleheading3=new JLabel("SILVER PACKAGE: CGPA>=6");
- eligibleheading3.setBounds(200, 100, 700,20);
+ eligibleheading3 = new JLabel("SILVER PACKAGE: CGPA>=6");
+ eligibleheading3.setBounds(200, 100, 700, 20);
eligibleheading3.setFont(font);
eligibleheading3.setForeground(Color.BLACK);
-
- output=new JTextArea();
- output.setBounds(100, 150, 1150,450);
+ output = new JTextArea();
+ output.setBounds(100, 150, 1300, 450);
output.setFont(font);
output.setForeground(Color.BLACK);
output.setEditable(false);
display = new JButton("Display");
- display.setBounds(400,600,150,40);
- display.addActionListener(this);
+ display.setBounds(400, 600, 150, 40);
+ display.addActionListener(this);
display.setFont(font);
- Color pul = new Color(0,0,255);
- Border bored = BorderFactory.createLineBorder(pul,5);
+ Color pul = new Color(0, 0, 255);
+ Border bored = BorderFactory.createLineBorder(pul, 5);
display.setBorder(bored);
display.setForeground(Color.WHITE);
display.setBackground(blue);
back = new JButton("Go Back");
- back.setBounds(600,600,150,40);
- back.addActionListener(this);
+ back.setBounds(600, 600, 150, 40);
+ back.addActionListener(this);
back.setFont(font);
back.setBorder(bored);
back.setForeground(Color.WHITE);
@@ -79,103 +76,69 @@ public class Eligible extends JFrame implements ActionListener
con.add(eligibleheading1);
con.add(eligibleheading2);
con.add(eligibleheading3);
- con.add(output);
+ con.add(output);
con.add(display);
con.add(back);
-
}
- public void actionPerformed(ActionEvent ae)
- {
- if(ae.getSource()==display)
- {
- try
- {
-
- System.out.println("Eligibilty Checked and Displayed");
- String name, cgpa1, nob1, r,b,e="";
- double cgpa, nob;
-
- File temp = new File("temp.txt");
- Boolean createNewFile1 = temp.createNewFile();
- BufferedWriter pw = new BufferedWriter(new FileWriter(temp));
-
- BufferedReader br = new BufferedReader(new FileReader("student.txt"));
- while((r = br.readLine()) != null )
- {
- String[] result = r.split("\\|");
- name=result[0];
- cgpa1=result[4];
- nob1=result[5];
- cgpa = Double.parseDouble(cgpa1);
- nob = Double.parseDouble(nob1);
- if(cgpa!=999)
- {
- if(cgpa >= 8.0 && nob == 0)
- {
- b = name + " : " + "Candidate Eligible For Platinum,Gold, Silver Packages";
- e="Eligible companies: Google (24LPA), Amazon (19LPA), Adobe (11LPA), Flipkart (18LPA), Ebay (6LPA), Infosys (4LPA)";
- pw.write(b+"\n");
- pw.write(e+"\n\n");
-
- }
- else if(cgpa >= 7.0 && nob == 0)
- {
- b = name + " : " + "Candidate Eligible For Gold and Silver Packages";
- e="Eligible companies: ANZ (11LPA), Capgemini (8LPA), Cognizant (6LPA), Wipro (4LPA)";
- pw.write(b+"\n");
- pw.write(e+"\n\n");
- }
- else if(cgpa >= 6.0)
- {
- b = name + " : " + "Candidate Eligible For only Silver Package";
- e="Eligible companies: Cognizant (6LPA), Wipro (4LPA)";
- pw.write(b+"\n");
- pw.write(e+"\n\n");
- }
- else
- {
- b = name + " : " + "Sorry!! Candidate Not Eligible";
- pw.write(b+"\n\n");
- }
- }
+ public void actionPerformed(ActionEvent ae) {
+ if (ae.getSource() == display) {
+ try {
+ String line;
+ StringBuilder sb = new StringBuilder();
+
+ BufferedReader br = new BufferedReader(new FileReader("student.csv"));
+ while ((line = br.readLine()) != null) {
+ String[] parts = line.split(",");
+ if (parts.length >= 7) {
+ String name = parts[0];
+ double cgpa = Double.parseDouble(parts[4]);
+ double nob = Double.parseDouble(parts[5]);
+ if (cgpa >= 8.0 && nob == 0) {
+ sb.append(formatCompany(name, "Platinum",
+ "Google (24LPA), Amazon (19LPA), Adobe (11LPA), Flipkart (18LPA), Ebay (6LPA), Infosys (4LPA)"));
+ } else if (cgpa >= 7.0 && nob == 0) {
+ sb.append(formatCompany(name, "Gold",
+ "ANZ (11LPA), Capgemini (8LPA), Cognizant (6LPA), Wipro (4LPA)"));
+ } else if (cgpa >= 6.0) {
+ sb.append(formatCompany(name, "Silver", "Cognizant (6LPA), Wipro (4LPA)"));
+ } else {
+ sb.append(formatCompany(name, "Not Eligible", ""));
+ }
+
+ }
+
}
br.close();
- pw.close();
- File file = new File("temp.txt");
- BufferedReader br1 = new BufferedReader(new FileReader(file));
- output.read(br1,null);
- br1.close();
- output.requestFocus();
- file.delete();
- }
- catch(Exception e)
- {
+
+ output.setText(sb.toString());
+ } catch (Exception e) {
e.printStackTrace();
}
+
}
- if(ae.getSource()==back)
- {
- try
- {
+ if (ae.getSource() == back) {
+ try {
this.dispose();
- Home h=new Home();
- h.setSize(2300,790);
+ Home h = new Home();
+ h.setSize(2300, 790);
h.setVisible(true);
- }
- catch(Exception e)
- {
+ } catch (Exception e) {
e.printStackTrace();
}
}
}
- public static void main(String args[])
- {
- Eligible eli=new Eligible();
- eli.setSize(2300,790);
- eli.setVisible(true);
- }
+ private String formatCompany(String name, String packageName, String companies) {
+ return String.format("%-20s | %-20s | %-50s%n", "Name", "Package", "Eligible Companies") +
+ "------------------------------------------------------------------\n"
+ + String.format("%-20s | %-20s | %s%n", name, packageName, companies);
+ }
-}
\ No newline at end of file
+ public static void main(String args[]) {
+ Eligible eli = new Eligible();
+ eli.setSize(2300, 790);
+ eli.setVisible(true);
+ }
+}
diff --git a/Gautham_PMS_report.pdf b/Gautham_PMS_report.pdf
deleted file mode 100644
index cef777f..0000000
Binary files a/Gautham_PMS_report.pdf and /dev/null differ
diff --git a/Home.java b/Home.java
index 46482c4..57ada56 100644
--- a/Home.java
+++ b/Home.java
@@ -112,8 +112,6 @@ public class Home extends JFrame implements ActionListener
background = new JLabel("",img,JLabel.CENTER);
background.setBounds(0,0,1200,850);
add(background);
-
-
}
diff --git a/Insert.java b/Insert.java
index 3b11160..71515c1 100644
--- a/Insert.java
+++ b/Insert.java
@@ -1,489 +1,243 @@
+import static javax.swing.JOptionPane.showMessageDialog;
+
import java.awt.*;
import javax.swing.*;
import javax.swing.border.Border;
-
import java.awt.event.*;
import java.io.*;
import java.util.*;
-import static javax.swing.JOptionPane.showMessageDialog;
-public class Insert extends JFrame implements ActionListener
-{
- private JLabel insertHeading,nameL,usnL,semL,branchL,cgpaL,nobL,companyL,ctcL,commentsL;
- private JTextField nameT,usnT,cgpaT,nobT,ctcT,commentsT;
- JComboBox companyT,branchT,semT;;
- private JButton insert,back;
- String[] companies= {"Amazon","Flipcart","Ebay","SAP_LABS","Capgemini","Cognizant","Infosys","Wipro"};
- String[] branches= {"CSE","ISE","EEE","ECE","MEC","TEC","AIML"};
- String[] sems= {"01","02","03","04","05","06","07","08"};
- //JComboBox combobox=new JComboBox(companies);
+public class Insert extends JFrame implements ActionListener {
+ private JLabel insertHeading, nameL, usnL, semL, branchL, cgpaL, nobL, companyL, commentsL;
+ private JTextField nameT, usnT, cgpaT, nobT, commentsT;
+ private JComboBox companyT, branchT, semT;
+ private JButton insert, back;
+ private String[] companies = {"Google","Amazon", "Flipcart", "Ebay", "SAP_LABS", "Capgemini", "Cognizant", "Infosys", "Wipro"};
+ private String[] branches = {"CSE", "ISE", "EEE", "ECE", "MEC", "TEC", "AIML"};
+ private String[] sems = {"01", "02", "03", "04", "05", "06", "07", "08"};
- Container con=null;
- String name="", usn1="", sem="", branch="", cgpa="", nob="",company="",ctc="",comments="";
+ Container con = null;
- Insert()
- {
+ Insert() {
super("Insert Record");
con = getContentPane();
con.setLayout(null);
- Color lightBlue = new Color(0,255,255);
+ Color lightBlue = new Color(0, 255, 255);
con.setBackground(lightBlue);
- con.setSize(300,300);
+ con.setSize(300, 300);
con.setLayout(null);
con.setVisible(true);
insertHeading = new JLabel("INSERT STUDENT DETAILS");
- insertHeading.setBounds(550,-50, 400,150);
+ insertHeading.setBounds(550, -50, 400, 150);
con.add(insertHeading);
- //con.add(combobox);
- Color blue = new Color(30,144,255);
+ Color blue = new Color(30, 144, 255);
Font font = new Font("Verdana", Font.BOLD, 16);
insertHeading.setFont(font);
insertHeading.setForeground(Color.BLACK);
- nameL=new JLabel("Enter Name:");
- nameL.setBounds(350,70,150,40);
+ nameL = new JLabel("Enter Name:");
+ nameL.setBounds(350, 70, 150, 40);
nameL.setFont(font);
nameL.setForeground(Color.BLACK);
- nameT=new JTextField(200);
- nameT.setBounds(725,70,250,30);
+ nameT = new JTextField(200);
+ nameT.setBounds(725, 70, 250, 30);
nameT.setFont(font);
nameT.setForeground(Color.BLACK);
- usnL=new JLabel("Enter USN:");
- usnL.setBounds(350,130,150,40);
+ usnL = new JLabel("Enter USN:");
+ usnL.setBounds(350, 130, 150, 40);
usnL.setFont(font);
usnL.setForeground(Color.BLACK);
- usnT=new JTextField(200);
- usnT.setBounds(725,130,250,30);
+ usnT = new JTextField(200);
+ usnT.setBounds(725, 130, 250, 30);
usnT.setFont(font);
usnT.setForeground(Color.BLACK);
-
- semL=new JLabel("Enter Semester:");
- semL.setBounds(350,190,150,40);
+
+ semL = new JLabel("Enter Semester:");
+ semL.setBounds(350, 190, 150, 40);
semL.setFont(font);
semL.setForeground(Color.BLACK);
- semT=new JComboBox(sems);
- semT.setBounds(725,190,250,30);
+ semT = new JComboBox<>(sems);
+ semT.setBounds(725, 190, 250, 30);
semT.setFont(font);
semT.setForeground(Color.BLACK);
- branchL=new JLabel("Enter Branch:");
- branchL.setBounds(350,250,150,40);
+ branchL = new JLabel("Enter Branch:");
+ branchL.setBounds(350, 250, 150, 40);
branchL.setFont(font);
branchL.setForeground(Color.BLACK);
- branchT=new JComboBox(branches);
- branchT.setBounds(725,250,250,30);
+ branchT = new JComboBox<>(branches);
+ branchT.setBounds(725, 250, 250, 30);
branchT.setFont(font);
branchT.setForeground(Color.BLACK);
- cgpaL=new JLabel("Enter CGPA:");
- cgpaL.setBounds(350,310,150,40);
+ cgpaL = new JLabel("Enter CGPA:");
+ cgpaL.setBounds(350, 310, 150, 40);
cgpaL.setFont(font);
cgpaL.setForeground(Color.BLACK);
- cgpaT=new JTextField(200);
- cgpaT.setBounds(725,310,250,30);
+ cgpaT = new JTextField(200);
+ cgpaT.setBounds(725, 310, 250, 30);
cgpaT.setFont(font);
cgpaT.setForeground(Color.BLACK);
- nobL=new JLabel("Enter Number of backlogs:");
- nobL.setBounds(350,370,300,40);
+ nobL = new JLabel("Enter Number of backlogs:");
+ nobL.setBounds(350, 370, 300, 40);
nobL.setFont(font);
nobL.setForeground(Color.BLACK);
- nobT=new JTextField(200);
- nobT.setBounds(725,370,250,30);
+ nobT = new JTextField(200);
+ nobT.setBounds(725, 370, 250, 30);
nobT.setFont(font);
nobT.setForeground(Color.BLACK);
- companyL=new JLabel("Enter Aspiring Company:");
- companyL.setBounds(350,430,300,40);
+ companyL = new JLabel("Enter Aspiring Company:");
+ companyL.setBounds(350, 430, 300, 40);
companyL.setFont(font);
companyL.setForeground(Color.BLACK);
- companyT=new JComboBox(companies);
- companyT.setBounds(725,430,250,30);
+ companyT = new JComboBox<>(companies);
+ companyT.setBounds(725, 430, 250, 30);
companyT.setFont(font);
companyT.setForeground(Color.BLACK);
companyT.addActionListener(this);
- /*ctcL=new JLabel("Enter Aspiring CTC:");
- ctcL.setBounds(350,490,300,40);
- ctcL.setFont(font);
- ctcL.setForeground(Color.BLACK);
- ctcT=new JTextField(200);
- ctcT.setBounds(725,490,250,30);
- ctcT.setFont(font);
- ctcT.setForeground(Color.BLACK);
- ctcT.setText(ctc);*/
-
- commentsL=new JLabel("Enter Comments:");
- commentsL.setBounds(350,490,300,40);
+ commentsL = new JLabel("Enter Comments:");
+ commentsL.setBounds(350, 490, 300, 40);
commentsL.setFont(font);
commentsL.setForeground(Color.BLACK);
- commentsT=new JTextField(200);
- commentsT.setBounds(725,490,250,30);
+ commentsT = new JTextField(200);
+ commentsT.setBounds(725, 490, 250, 30);
commentsT.setFont(font);
commentsT.setForeground(Color.BLACK);
- insert=new JButton("Insert");
- insert.setBounds(400,550,150,40);
- insert.addActionListener(this);
+ insert = new JButton("Insert");
+ insert.setBounds(400, 550, 150, 40);
+ insert.addActionListener(this);
insert.setFont(font);
- Color pul = new Color(0,0,255);
- Border bored = BorderFactory.createLineBorder(pul,5);
+ Color pul = new Color(0, 0, 255);
+ Border bored = BorderFactory.createLineBorder(pul, 5);
insert.setBorder(bored);
insert.setForeground(Color.WHITE);
insert.setBackground(blue);
- back = new JButton("Go Back");
- back.setBounds(750,550,150,40);
- back.addActionListener(this);
+ back = new JButton("Go Back");
+ back.setBounds(750, 550, 150, 40);
+ back.addActionListener(this);
back.setFont(font);
back.setBorder(bored);
back.setForeground(Color.WHITE);
back.setBackground(blue);
con.add(nameL);
- con.add(nameT);
+ con.add(nameT);
con.add(usnL);
- con.add(usnT);
- con.add(semL);
- con.add(semT);
- con.add(branchL);
- con.add(branchT);
+ con.add(usnT);
+ con.add(semL);
+ con.add(semT);
+ con.add(branchL);
+ con.add(branchT);
con.add(cgpaL);
- con.add(cgpaT);
+ con.add(cgpaT);
con.add(nobL);
- con.add(nobT);
- con.add(companyL);
- con.add(companyT);
- //con.add(ctcL);
- //con.add(ctcT);
- con.add(commentsL);
- con.add(commentsT);
- con.add(insert);
- con.add(back);
+ con.add(nobT);
+ con.add(companyL);
+ con.add(companyT);
+ con.add(commentsL);
+ con.add(commentsT);
+ con.add(insert);
+ con.add(back);
}
- public void actionPerformed(ActionEvent ae)
- {
- if(ae.getSource()==insert)
- {
- try
- {
- String p = "999" + "|" + "999" + "|" +"999" + "|" +"999" + "|" +"999" + "|" +"999" + "|"+"999" + "|"+"999" + "|"+"999" + "|" ;
- File data = new File("student.txt");
- File data1 = new File("journal.txt");
- if(data.createNewFile() && data1.createNewFile())
- {
- Boolean createNewFile = data.createNewFile();
- Boolean createNewFile1 = data1.createNewFile();
- // System.out.println("student "+createNewFile);
- // System.out.println("journal "+createNewFile1);
- BufferedWriter pw = new BufferedWriter(new FileWriter(data));
- BufferedWriter pw1 = new BufferedWriter(new FileWriter(data1));
- pw.write(p);
- pw.write("\n");
- pw.close();
- pw1.write(p);
- pw1.write("\n");
- pw1.close();
- }
-
- String name = nameT.getText();
- String usn1 = usnT.getText();
- String sem = (String) semT.getSelectedItem();
- String branch = (String) branchT.getSelectedItem();
- String cgpa = cgpaT.getText();
- String nob = nobT.getText();
- String company = (String) companyT.getSelectedItem();
- String ctc = ctcofcompany(company);
- //ctcT.setText(ctc);
- String comments = commentsT.getText();
+ public void actionPerformed(ActionEvent ae) {
+ if (ae.getSource() == insert) {
+ try {
+ BufferedWriter bwStudent = new BufferedWriter(new FileWriter("student.csv", true));
+ BufferedWriter bwJournal = new BufferedWriter(new FileWriter("journal.csv", true));
- int check=0,usn2=0,usn3=0;
- String usn="",r,sort,sort1="";
- File file = new File("student.txt");
- BufferedReader br=new BufferedReader(new FileReader(file));
- while((r= br.readLine()) !=null)
- {
- String[] result = r.split("\\|");
- usn=result[1];
- if(usn.equals(usn1))
- { check=1;
- showMessageDialog(null, "A record already exists with usn: "+result[1]);
- break;
- }
- }
- br.close();
- //if record already exists
- if(check==1)
- {
- showMessageDialog(null, "Record Updated!");
- }
- String b = usn1 + "|" + sem + "|" + cgpa + "|" + nob + "|" + company + "|" +ctc + "|" + comments + "|";
- int len = b.length();
- File file2 = new File ("journal.txt");
- BufferedReader br2 = new BufferedReader(new FileReader(file2));
- usn3=Integer.parseInt(usn1);
- //sorting before insertion
- File temp1 = new File("temp.txt");
- Boolean createNewFile1 = temp1.createNewFile();
- BufferedWriter pw2 = new BufferedWriter(new FileWriter(temp1));
- String result1[]={};
- String sem1,cgpa1,nob1,company1,ctc1,comments1;
- while((sort = br2.readLine()) != null)
- {
- result1 = sort.split("\\|");
- usn2=Integer.parseInt(result1[0]);
- sem1 = result1[1];
- cgpa1=result1[2];
- nob1=result1[3];
- company1=result1[4];
- ctc1=result1[5];
- comments1=result1[6];
- sort1 = usn2 + "|" + sem1 + "|" + cgpa1 + "|" + nob1 + "|" + company1 + "|" +ctc1 + "|" + comments1 + "|";
- if(usn3usn2)
- {
- pw2.write(b);
- pw2.write("\n");
- pw2.write(p);
- pw2.write("\n");
- }
- else if (usn3 == usn2)
- {
- while(!(result1[1].equals("999")))
- {
- sort = br2.readLine();
- result1 = sort.split("\\|");
- usn2=Integer.parseInt(result1[0]);
- sem1 = result1[1];
- cgpa1=result1[2];
- nob1=result1[3];
- company1=result1[4];
- ctc1=result1[5];
- comments1=result1[6];
- sort1 = usn2 + "|" + sem1 + "|" + cgpa1 + "|" + nob1 + "|" + company + "|" +ctc + "|" + comments + "|";
- pw2.write(sort1);
- pw2.write("\n");
- }
- }
- else
- {
- while(!result1[1].equals("999"))
- {
- pw2.write(sort1);
- pw2.write("\n");
- sort = br2.readLine();
- result1 = sort.split("\\|");
- usn2=Integer.parseInt(result1[0]);
- sem1 = result1[1];
- cgpa1=result1[2];
- nob1=result1[3];
- company1=result1[4];
- ctc1=result1[5];
- comments1=result1[6];
- sort1 = usn2 + "|" + sem1 + "|" + cgpa1 + "|" + nob1 + "|" + company + "|" +ctc + "|" + comments + "|";
- }
- }
- pw2.write(p);
- pw2.write("\n");
- }
- }
- pw2.flush();
- pw2.close();
- br2.close();
- file2.delete();
- temp1.renameTo(file2);
- modify(name,usn1,sem,branch,cgpa,nob,company,ctc,comments);
- //}
- //if record does not exist
- if(check == 0)
- {
- File file1 = new File("student.txt");
- BufferedReader br1 = new BufferedReader(new FileReader(file1));
- b = name + "|" + usn1 + "|" + sem + "|" + branch + "|" + cgpa + "|" + nob + "|" + company + "|" +ctc + "|" + comments + "|";
- len = b.length();
- usn3=Integer.parseInt(usn1);
+ String studentData = getStudentDataString();
+ String journalData = getJournalDataString();
- //sorting before insertion
- File temp = new File("temp.txt");
- Boolean createNewFile = temp.createNewFile();
- BufferedWriter pw1 = new BufferedWriter(new FileWriter(temp));
- String result[]={};
- while((sort = br1.readLine()) != null)
- {
- result = sort.split("\\|");
- usn2=Integer.parseInt(result[1]);
- if(usn3= 2 && parts[1].equals(usn)) {
+ recordText.append("Student Records:\n");
+ recordText.append("NAME\t|USN\t|SEM\t|BRANCH\t|CGPA\t|NOB\t|COMPANY\t|CTC\t|COMMENTS\n");
+ recordText.append(
+ "--------------------------------------------------------------------------------------------------------------------------------\n");
+ recordText.append(line.replace(",", "\t"));
+ recordText.append("\n");
+ recordFound = true;
+ }
+ }
+
+ if (!recordFound) {
+ showMessageDialog(null, "Record not found");
+ }
+ }
+
+ output.setText(recordText.toString());
}
-}
+ public static void main(String args[]) {
+ Search ser = new Search();
+ ser.setSize(2300, 790);
+ ser.setVisible(true);
+ }
+}
diff --git a/SearchByBranch.java b/SearchByBranch.java
index 296b01e..5dd0c81 100644
--- a/SearchByBranch.java
+++ b/SearchByBranch.java
@@ -11,13 +11,12 @@ public class SearchByBranch extends JFrame implements ActionListener
{
private JLabel branchL;
- private JComboBox branchT;
+ private JComboBox branchT;
private JTextArea output;
private JButton search,back;
Container con=null;
- String usn="";
- String[] branches= {"CSE","ISE","EEE","ECE","MEC","TEC","AIML"};
+ String[] branches= {"CSE","IT","EEE","ECE","MEC","AIML"};
SearchByBranch()
{
@@ -33,18 +32,18 @@ public class SearchByBranch extends JFrame implements ActionListener
Font font = new Font("Verdana", Font.BOLD, 16);
Color blue = new Color(30,144,255);
- branchL=new JLabel("Enter Branch of record to be searched");
+ branchL=new JLabel("Select Branch to search for records:");
branchL.setBounds(300, 50, 700,150);
branchL.setFont(font);
branchL.setForeground(Color.BLACK);
- branchT=new JComboBox(branches);
+ branchT=new JComboBox<>(branches);
branchT.setBounds(725,100,250,50);
branchT.setFont(font);
branchT.setForeground(Color.BLACK);
output=new JTextArea();
- output.setBounds(20,200,1200,350);
+ output.setBounds(20,200,1300,350);
output.setFont(font);
output.setForeground(Color.BLACK);
output.setEditable(false);
@@ -78,47 +77,10 @@ public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==search)
{
- String branch1 = (String) branchT.getSelectedItem();
+ String branch = (String) branchT.getSelectedItem();
try
{
- String name = "", usn ="", sem = "", branch = "", cgpa= "", nob="", company="",ctc="",comments="", r;
-
- File temp = new File("temp.txt");
- Boolean createNewFile1 = temp.createNewFile();
- BufferedWriter pw = new BufferedWriter(new FileWriter("temp.txt"));
- String b = "NAME\t|USN\t|SEM\t|BRANCH\t|CGPA\t|NOB\t|COMPANY\t|CTC\t|COMMENTS";
- pw.write(b);
- pw.write("\n");
-
- BufferedReader br = new BufferedReader(new FileReader("student.txt"));
- while((r= br.readLine()) !=null)
- {
- String[] result = r.split("\\|");
- name=result[0];
- usn=result[1];
- sem= result[2];
- branch=result[3];
- cgpa=result[4];
- nob=result[5];
- company=result[6];
- ctc=result[7];
- comments=result[8];
- if(name.equals("999"))
- break;
- if(branch.equals(branch1)) {
- String bb = name + "\t|" + usn + "\t|" + sem + "\t|" + branch + "\t|" + cgpa + "\t|" + nob + "\t|" + company + "\t|" + ctc + "\t|" + comments;
- pw.write(bb);
- pw.write("\n");
- }
- }
- br.close();
- pw.close();
- File file = new File("temp.txt");
- BufferedReader br1 = new BufferedReader(new FileReader(file));
- output.read(br1,null);
- br1.close();
- output.requestFocus();
- file.delete();
+ searchRecordInCSV("student.csv", branch);
}
catch(Exception e)
{
@@ -142,11 +104,37 @@ public void actionPerformed(ActionEvent ae)
}
}
+ private void searchRecordInCSV(String filename, String branch) throws IOException {
+ StringBuilder recordText = new StringBuilder();
+ boolean recordFound = false;
+
+ try (BufferedReader br = new BufferedReader(new FileReader(filename))) {
+ String line;
+ while ((line = br.readLine()) != null) {
+ String[] parts = line.split(",");
+ if (parts.length >= 4 && parts[3].equalsIgnoreCase(branch)) {
+ recordText.append("Student By Branch Records:\n");
+ recordText.append("NAME\t|USN\t|SEM\t|BRANCH\t|CGPA\t|NOB\t|COMPANY\t|CTC\t|COMMENTS\n");
+ recordText.append(
+ "--------------------------------------------------------------------------------------------------------------------------------\n");
+ recordText.append(line.replace(",", "\t"));
+ recordText.append("\n");
+ recordFound = true;
+ }
+ }
+ }
+
+ if (!recordFound) {
+ showMessageDialog(null, "No records found for the selected branch.");
+ }
+
+ output.setText(recordText.toString());
+ }
+
public static void main(String args[])
{
- Search1 ser=new Search1();
+ SearchByBranch ser=new SearchByBranch();
ser.setSize(2300,790);
ser.setVisible(true);
}
}
-
diff --git a/SearchByCompany.java b/SearchByCompany.java
index 76258a3..8f053d9 100644
--- a/SearchByCompany.java
+++ b/SearchByCompany.java
@@ -7,147 +7,123 @@
import java.util.*;
import static javax.swing.JOptionPane.showMessageDialog;
-public class SearchByCompany extends JFrame implements ActionListener
-{
+public class SearchByCompany extends JFrame implements ActionListener {
private JLabel companyL;
- private JComboBox companyT;
+ private JComboBox companyT;
private JTextArea output;
- private JButton search,back;
+ private JButton search, back;
Container con=null;
- String usn="";
- String[] companies= {"Amazon","Flipcart","Ebay","SAP_LABS","Capgemini","Cognizant","Infosys","Wipro"};
+ String[] companies= {"Google", "Amazon","Flipkart","Ebay","SAP_LABS","Capgemini","Cognizant","Infosys","Wipro"};
- SearchByCompany()
- {
- super("\"Search By Company");
+ SearchByCompany() {
+ super("Search By Company");
con = getContentPane();
con.setLayout(null);
- Color lightBlue = new Color(0,255,255);
+ Color lightBlue = new Color(0, 255, 255);
con.setBackground(lightBlue);
- con.setSize(300,300);
+ con.setSize(300, 300);
con.setLayout(null);
con.setVisible(true);
Font font = new Font("Verdana", Font.BOLD, 16);
- Color blue = new Color(30,144,255);
- companyL=new JLabel("Enter Company of record to be searched");
- companyL.setBounds(300, 50, 700,150);
+ Color blue = new Color(30, 144, 255);
+
+ companyL = new JLabel("Select Company to search for records:");
+ companyL.setBounds(300, 50, 700, 150);
companyL.setFont(font);
companyL.setForeground(Color.BLACK);
- companyT=new JComboBox(companies);
- companyT.setBounds(725,100,250,50);
+ companyT = new JComboBox<>(companies);
+ companyT.setBounds(725, 100, 250, 50);
companyT.setFont(font);
companyT.setForeground(Color.BLACK);
- output=new JTextArea();
- output.setBounds(20,200,1200,350);
+ output = new JTextArea();
+ output.setBounds(20, 200, 1300, 350);
output.setFont(font);
output.setForeground(Color.BLACK);
output.setEditable(false);
search = new JButton("Search");
- search.setBounds(400,600,150,40);
- search.addActionListener(this);
+ search.setBounds(400, 600, 150, 40);
+ search.addActionListener(this);
search.setFont(font);
- Color pul = new Color(0,0,255);
- Border bored = BorderFactory.createLineBorder(pul,5);
+ Color pul = new Color(0, 0, 255);
+ Border bored = BorderFactory.createLineBorder(pul, 5);
search.setBorder(bored);
search.setForeground(Color.WHITE);
search.setBackground(blue);
back = new JButton("Go Back");
- back.setBounds(600,600,150,40);
- back.addActionListener(this);
+ back.setBounds(600, 600, 150, 40);
+ back.addActionListener(this);
back.setFont(font);
back.setBorder(bored);
back.setForeground(Color.WHITE);
back.setBackground(blue);
con.add(companyL);
- con.add(companyT);
+ con.add(companyT);
con.add(output);
con.add(search);
con.add(back);
}
- public void actionPerformed(ActionEvent ae)
- {
- if(ae.getSource()==search)
- {
- String company1 = (String) companyT.getSelectedItem();
- //String company1 = companyT.getText();
- try
- {
- String name = "", usn ="", sem = "", branch = "", cgpa= "", nob="", company="",ctc="",comments="", r;
-
- File temp = new File("temp.txt");
- Boolean createNewFile1 = temp.createNewFile();
- BufferedWriter pw = new BufferedWriter(new FileWriter("temp.txt"));
- String b = "NAME\t|USN\t|SEM\t|BRANCH\t|CGPA\t|NOB\t|COMPANY\t|CTC\t|COMMENTS";
- pw.write(b);
- pw.write("\n");
-
- BufferedReader br = new BufferedReader(new FileReader("student.txt"));
- while((r= br.readLine()) !=null)
- {
- String[] result = r.split("\\|");
- name=result[0];
- usn=result[1];
- sem= result[2];
- branch=result[3];
- cgpa=result[4];
- nob=result[5];
- company=result[6];
- ctc=result[7];
- comments=result[8];
- if(name.equals("999"))
- break;
- if(company.equals(company1)) {
- String bb = name + "\t|" + usn + "\t|" + sem + "\t|" + branch + "\t|" + cgpa + "\t|" + nob + "\t|" + company + "\t|" + ctc + "\t|" + comments;
- pw.write(bb);
- pw.write("\n");
- }
- }
- br.close();
- pw.close();
- File file = new File("temp.txt");
- BufferedReader br1 = new BufferedReader(new FileReader(file));
- output.read(br1,null);
- br1.close();
- output.requestFocus();
- file.delete();
- }
- catch(Exception e)
- {
+ public void actionPerformed(ActionEvent ae) {
+ if (ae.getSource() == search) {
+ String company = (String) companyT.getSelectedItem();
+ try {
+ searchRecordInCSV("student.csv", company);
+ } catch (IOException e) {
e.printStackTrace();
}
}
- if(ae.getSource()==back)
- {
- try
- {
+ if (ae.getSource() == back) {
+ try {
this.dispose();
- Search1 h=new Search1();
- h.setSize(2300,790);
+ Search1 h = new Search1();
+ h.setSize(2300, 790);
h.setVisible(true);
- }
- catch(Exception e)
- {
+ } catch (Exception e) {
e.printStackTrace();
}
}
}
- public static void main(String args[])
- {
- Search1 ser=new Search1();
- ser.setSize(2300,790);
- ser.setVisible(true);
+ private void searchRecordInCSV(String filename, String company) throws IOException {
+ StringBuilder recordText = new StringBuilder();
+
+ try (BufferedReader br = new BufferedReader(new FileReader(filename))) {
+ String line;
+ boolean recordFound = false;
+ while ((line = br.readLine()) != null) {
+ String[] parts = line.split(",");
+ if (parts.length >= 7 && parts[6].equalsIgnoreCase(company)) {
+ recordText.append("Company Results:\n");
+ recordText.append("NAME\t|USN\t|SEM\t|BRANCH\t|CGPA\t|NOB\t|COMPANY\t|CTC\t|COMMENTS\n");
+ recordText.append(
+ "--------------------------------------------------------------------------------------------------------------------------------\n");
+ recordText.append(line.replace(",", "\t"));
+ recordText.append("\n");
+ recordFound = true;
+ }
+ }
+
+ if (!recordFound) {
+ showMessageDialog(null, "No records found for the selected company.");
+ }
+ }
+
+ output.setText(recordText.toString());
+ }
+
+ public static void main(String args[]) {
+ SearchByCompany ser = new SearchByCompany();
+ ser.setSize(2300, 790);
+ ser.setVisible(true);
}
}
-
diff --git a/SearchByUSN.java b/SearchByUSN.java
index 02c8611..a0c64bf 100644
--- a/SearchByUSN.java
+++ b/SearchByUSN.java
@@ -7,145 +7,122 @@
import java.util.*;
import static javax.swing.JOptionPane.showMessageDialog;
-public class SearchByUSN extends JFrame implements ActionListener
-{
+public class SearchByUSN extends JFrame implements ActionListener {
- private JLabel usnL,companyL;
- private JTextField usnT,companyT;
- private JTextArea output,companyoutput;
- private JButton search,back;
+ private JLabel usnL;
+ private JTextField usnT;
+ private JTextArea output;
+ private JButton search, back;
- Container con=null;
- String usn="";
+ Container con = null;
- SearchByUSN()
- {
+ SearchByUSN() {
super("Search By USN");
con = getContentPane();
con.setLayout(null);
- Color lightBlue = new Color(0,255,255);
+ Color lightBlue = new Color(0, 255, 255);
con.setBackground(lightBlue);
- con.setSize(300,300);
+ con.setSize(300, 300);
con.setLayout(null);
con.setVisible(true);
Font font = new Font("Verdana", Font.BOLD, 16);
- Color blue = new Color(30,144,255);
- usnL=new JLabel("Enter usn of record to be searched");
- usnL.setBounds(400, 50, 700,150);
+ Color blue = new Color(30, 144, 255);
+
+ usnL = new JLabel("Enter USN of record to be searched");
+ usnL.setBounds(400, 50, 700, 150);
usnL.setFont(font);
usnL.setForeground(Color.BLACK);
- usnT=new JTextField(200);
- usnT.setBounds(725,100,250,50);
+ usnT = new JTextField(200);
+ usnT.setBounds(725, 100, 250, 50);
usnT.setFont(font);
usnT.setForeground(Color.BLACK);
- output=new JTextArea();
- output.setBounds(20,200,1200,350);
+ output = new JTextArea();
+ output.setBounds(20, 200, 1300, 350);
output.setFont(font);
output.setForeground(Color.BLACK);
output.setEditable(false);
search = new JButton("Search");
- search.setBounds(400,600,150,40);
- search.addActionListener(this);
+ search.setBounds(400, 600, 150, 40);
+ search.addActionListener(this);
search.setFont(font);
- Color pul = new Color(0,0,255);
- Border bored = BorderFactory.createLineBorder(pul,5);
+ Color pul = new Color(0, 0, 255);
+ Border bored = BorderFactory.createLineBorder(pul, 5);
search.setBorder(bored);
search.setForeground(Color.WHITE);
search.setBackground(blue);
back = new JButton("Go Back");
- back.setBounds(600,600,150,40);
- back.addActionListener(this);
+ back.setBounds(600, 600, 150, 40);
+ back.addActionListener(this);
back.setFont(font);
back.setBorder(bored);
back.setForeground(Color.WHITE);
back.setBackground(blue);
con.add(usnL);
- con.add(usnT);
+ con.add(usnT);
con.add(output);
con.add(search);
con.add(back);
}
- public void actionPerformed(ActionEvent ae)
- {
- if(ae.getSource()==search)
- {
+ public void actionPerformed(ActionEvent ae) {
+ if (ae.getSource() == search) {
String usn = usnT.getText();
- try
- {
- String name = "", usn1 ="", sem = "", branch = "", cgpa= "", nob="", company="",ctc="",comments="", r;
- BufferedReader br = new BufferedReader(new FileReader("student.txt"));
- while((r= br.readLine()) !=null)
- {
- String[] result = r.split("\\|");
- name=result[0];
- usn1=result[1];
- sem= result[2];
- branch=result[3];
- cgpa=result[4];
- nob=result[5];
- company=result[6];
- ctc=result[7];
- comments=result[8];
- if(usn1.equals(usn))
- {
- File temp = new File("temp.txt");
- Boolean createNewFile1 = temp.createNewFile();
- BufferedWriter pw = new BufferedWriter(new FileWriter(temp));
- String b = "NAME\t|USN\t|SEM\t|BRANCH\t|CGPA\t|NOB\t|COMPANY\t|CTC\t|COMMENTS";
- String bb = name + "\t|" + usn1 + "\t|" + sem + "\t|" + branch + "\t|" + cgpa + "\t|" + nob + "\t|" + company + "\t|" + ctc + "\t|" + comments;
- pw.write(b);
- pw.write("\n");
- pw.write(bb);
- pw.write("\n");
- pw.close();
- br.close();
- File file = new File("temp.txt");
- BufferedReader br1 = new BufferedReader(new FileReader(file));
- output.read(br1,null);
- br1.close();
- output.requestFocus();
- file.delete();
- return ;
- }
- }
- showMessageDialog(null , "Record not found");
- br.close();
- }
- catch(Exception e)
- {
+ try {
+ searchRecordInCSV("student.csv", usn);
+ } catch (IOException e) {
e.printStackTrace();
}
}
- if(ae.getSource()==back)
- {
- try
- {
+ if (ae.getSource() == back) {
+ try {
this.dispose();
- Search1 h=new Search1();
- h.setSize(2300,790);
+ Search1 h = new Search1();
+ h.setSize(2300, 790);
h.setVisible(true);
- }
- catch(Exception e)
- {
+ } catch (Exception e) {
e.printStackTrace();
}
}
}
- public static void main(String args[])
- {
- Search1 ser=new Search1();
- ser.setSize(2300,790);
- ser.setVisible(true);
+ private void searchRecordInCSV(String filename, String usn) throws IOException {
+ StringBuilder recordText = new StringBuilder();
+
+ try (BufferedReader br = new BufferedReader(new FileReader(filename))) {
+ String line;
+ boolean recordFound = false;
+ while ((line = br.readLine()) != null) {
+ String[] parts = line.split(",");
+ if (parts.length >= 2 && parts[1].equals(usn)) {
+ recordText.append("Student Records:\n");
+ recordText.append("NAME\t|USN\t|SEM\t|BRANCH\t|CGPA\t|NOB\t|COMPANY\t|CTC\t|COMMENTS\n");
+ recordText.append(
+ "--------------------------------------------------------------------------------------------------------------------------------\n");
+ recordText.append(line.replace(",", "\t"));
+ recordText.append("\n");
+ recordFound = true;
+ }
+ }
+
+ if (!recordFound) {
+ showMessageDialog(null, "Record not found");
+ }
+ }
+
+ output.setText(recordText.toString());
+ }
+
+ public static void main(String args[]) {
+ SearchByUSN ser = new SearchByUSN();
+ ser.setSize(2300, 790);
+ ser.setVisible(true);
}
}
-
diff --git a/journal.csv b/journal.csv
new file mode 100644
index 0000000..14b75d8
--- /dev/null
+++ b/journal.csv
@@ -0,0 +1,2 @@
+101,03,8,1,Amazon,2400000,Exceptional Student
+102,03,9,1,Amazon,2400000,Good With DSA
diff --git a/student.csv b/student.csv
new file mode 100644
index 0000000..b9e89d8
--- /dev/null
+++ b/student.csv
@@ -0,0 +1,2 @@
+Shuence,101,03,ECE,8,1,Amazon,2400000,Exceptional Student
+Pranali,102,03,CSE,9,1,Amazon,2400000,Good With DSA