Professional Documents
Culture Documents
& MANAGEMENT
import java.util.*;
import java.util.logging.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.FlowLayout;
import java.io.*;
class Record implements Serializable{
String F_name;
String L_name;
int Rollno;
int Marks;
String Grade;
Record(String F_name,String L_name,int Rollno,int Marks,String
Grade){
this.F_name=F_name;
this.L_name=L_name;
this.Rollno=Rollno;
this.Marks=Marks;
this.Grade=Grade;
}
public String toString(){
return F_name+" : "+L_name+" : "+Rollno+" : "+Marks+" :
"+Grade;
}
}
public class Stud_Info_System implements ActionListener{
private static Logger logger=Logger.getLogger("Log");
String s0,s1,s2,s3,s4;
Stud_Info_System()
{
s0=s1=s2=s3=s4="";
}
public static void main(String[]args) throws Exception{
Stud_Info_System SIS =new Stud_Info_System();
// Create and set up a frame window
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame frame = new JFrame("OOPS lab project:PCCCS593");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
panel.add(t);
// Set the window to be visible as the default to be false
frame.add(panel);
frame.pack();
frame.setVisible(true);
jb1.addActionListener(SIS);
jb2.addActionListener(SIS);
jb3.addActionListener(SIS);
jb4.addActionListener(SIS);
jb5.addActionListener(SIS);
jb6.addActionListener(SIS);
frame.setLayout(new FlowLayout(FlowLayout.LEFT, 18, 28));
frame.setSize(400,400);
}
try{
if(file.isFile()){
ois=new ObjectInputStream(new FileInputStream(file));
ll=(ArrayList<Record>)ois.readObject();
ois.close();}}
catch(FileNotFoundException F){
F.printStackTrace();
}
catch(IOException IO){
IO.printStackTrace();
}
catch(ClassNotFoundException C){
C.printStackTrace();
}
if(E.getActionCommand().equals("Insert record")){
Scanner s1,s2;
s1=new Scanner(System.in);
s2=new Scanner(System.in);
System.out.println("How many records you want to add?:");
int n=s1.nextInt();
int i;
for(i=0;i<n;i++){
System.out.println("Enter First name");
String fn=s2.nextLine();
System.out.println("Enter Last name");
String ln=s2.nextLine();
System.out.println("Enter roll no:");
int roll=s1.nextInt();
System.out.println("Enter marks :");
int marks=s1.nextInt();
System.out.println("Enter grade :");
String grade=s2.nextLine();
ll.add(new Record(fn,ln,roll,marks,grade));
try{
oos=new ObjectOutputStream(new
FileOutputStream(file));
oos.writeObject(ll);
oos.close();
}
catch(IOException I){
I.printStackTrace();
}
System.out.println("");
System.out.println("Log file content:");
FileHandler fh;
try{
fh=new FileHandler("Mylogfile.log");
logger.addHandler(fh);
SimpleFormatter formatter=new SimpleFormatter();
logger.info("Insert operation");
}catch(Exception e){
logger.log(Level.WARNING,"Exception ::",e);
}
}
else if(E.getActionCommand().equals("Display record")){
ListIterator li=null;
li=ll.listIterator();
while(li.hasNext())
System.out.println(li.next());
System.out.println("...................");
FileHandler fh;
try{
fh=new FileHandler("Mylogfile.log");
logger.addHandler(fh);
SimpleFormatter formatter=new SimpleFormatter();
logger.info("Display operation");
}catch(Exception e){
logger.log(Level.WARNING,"Exception ::",e);
}
}
else if(E.getActionCommand().equals("Search record")){
Scanner s1,s2;
s1=new Scanner(System.in);
s2=new Scanner(System.in);
try{
if(file.isFile()){
ois=new ObjectInputStream(new FileInputStream(file));
ll=(ArrayList<Record>)ois.readObject();
ois.close();}}
catch(FileNotFoundException fe){
fe.printStackTrace();
}
catch(IOException ie){
ie.printStackTrace();
}
catch(ClassNotFoundException ce){
ce.printStackTrace();
}
System.out.println("Enter the roll no, First name and Last name
to search the record");
int roll=s1.nextInt();
String fs=s2.nextLine();
String ls=s2.nextLine();
int count=0;
ListIterator li=null;
li=ll.listIterator();
while(li.hasNext()){
Record R=(Record)li.next();
if(R.Rollno==roll){
count=count+1;
System.out.println(R);
}
else{
count=count;
}
}
if(count!=0){
System.out.println("Yes.The record is found");
}else{System.out.println("No.The record is not found.");}
FileHandler fh;
try{
fh=new FileHandler("Mylogfile.log");
logger.addHandler(fh);
SimpleFormatter formatter=new SimpleFormatter();
logger.info("Searching operation");
}catch(Exception e){
logger.log(Level.WARNING,"Exception ::",e);
}
}
else if(E.getActionCommand().equals("Update record")){
Scanner s1,s2;
s1=new Scanner(System.in);
s2=new Scanner(System.in);
try{
if(file.isFile()){
ois=new ObjectInputStream(new FileInputStream(file));
ll=(ArrayList<Record>)ois.readObject();
ois.close();}}
catch(FileNotFoundException FE){
FE.printStackTrace();
}
catch(IOException O){
O.printStackTrace();
}
catch(ClassNotFoundException CE){
CE.printStackTrace();
}
System.out.println("Enter the roll no to update the datils for ");
int roll=s1.nextInt();
int count=0;
ListIterator li=null;
li=ll.listIterator();
while(li.hasNext()){
Record R=(Record)li.next();
if(R.Rollno==roll){
count=count+1;
System.out.println(R);
int ch;
}
else{
count=count;
}
}
if(count!=0){
try{
oos=new ObjectOutputStream(new
FileOutputStream(file));
oos.writeObject(ll);
oos.close();
}
catch(IOException pe){
pe.printStackTrace();
}
System.out.println("The record is updated successfully");
}else{System.out.println("No.The record is not found.");}
FileHandler fh;
try{
fh=new FileHandler("Mylogfile.log");
logger.addHandler(fh);
SimpleFormatter formatter=new SimpleFormatter();
logger.info("Update operation");
}catch(Exception e){
logger.log(Level.WARNING,"Exception ::",e);
}
}
else if(E.getActionCommand().equals("Delete record")){
Scanner s1,s2;
s1=new Scanner(System.in);
s2=new Scanner(System.in);
try{
if(file.isFile()){
ois=new ObjectInputStream(new FileInputStream(file));
ll=(ArrayList<Record>)ois.readObject();
ois.close();
}}
catch(FileNotFoundException fe){
fe.printStackTrace();
}
catch(IOException ie){
ie.printStackTrace();
}
catch(ClassNotFoundException ce){
ce.printStackTrace();
}
try{
if(newfile.isFile()){
ris=new ObjectInputStream(new
FileInputStream(newfile));
rl=(ArrayList<Record>)ris.readObject();
ris.close();
}}
catch(FileNotFoundException XE){
XE.printStackTrace();
}
catch(IOException Y){
Y.printStackTrace();
}
catch(ClassNotFoundException Z){
Z.printStackTrace();
}
System.out.println("Enter the roll no to delete the record");
int roll=s1.nextInt();
int count=0;
ListIterator li=null;
li=ll.listIterator();
while(li.hasNext()){
Record R=(Record)li.next();
if(R.Rollno==roll){
System.out.println("The following record will be
removed:"+R);
count=count+1;
li.remove();
rl.add(new
Record(R.F_name,R.L_name,R.Rollno,R.Marks,R.Grade));
}
else{
count=count;
}
}
if(count!=0){
try{
oos=new ObjectOutputStream(new
FileOutputStream(file));
oos.writeObject(ll);
oos.close();
rcs=new ObjectOutputStream(new
FileOutputStream(newfile));
rcs.writeObject(rl);
rcs.close();
}
catch(IOException PE){
PE.printStackTrace();
}
System.out.println("The record is deleted successfully and the
databse is updated");
count=count+1;
li.remove();
ll.add(new
Record(R.F_name,R.L_name,R.Rollno,R.Marks,R.Grade));
}
else{
count=count;
}
}
if(count!=0){
try{
oos=new ObjectOutputStream(new
FileOutputStream(file));
oos.writeObject(ll);
oos.close();
rcs=new ObjectOutputStream(new
FileOutputStream(newfile));
rcs.writeObject(rl);
rcs.close();
}
catch(IOException pe){
pe.printStackTrace();
}
System.out.println("The record is restored successfully and the
databse is updated");
FileHandler fh;
try{
fh=new FileHandler("Mylogfile.log");
logger.addHandler(fh);
SimpleFormatter formatter=new SimpleFormatter();
logger.info("Restore operation");
}catch(Exception e){
logger.log(Level.WARNING,"Exception ::",e);
}
}
else{
System.out.print("Nothing");}
}
}
Output:-