Thursday, September 16, 2010

OPAC System program in Java

Question

Develop a simple OPAC system for library using even-driven and concurrent programming paradigms of Java. Use JDBC to connect to a back-end database.

Procedure

  1. Create a new Database file in MS ACCESS (our backend) named “books.mdb”.

  2. Then create a table named “Library” in it.

  3. The table Library contains the following fields and data types,

  1. AuthorName – Text

  2. ISBN – Text

  3. BookName - Text

  4. Price - Number

  5. Publisher – Text

  1. Enter various records as you wish.

  2. Save the database file.

  3. Next step is to add our “books.mdb” to the System DSN. To do that follow the procedure given below,

  1. Go to Start-> Control Panel -> Administrative tools.

  2. In that double click “Data Sources (ODBC)”.

  3. ODBC Data Source Administrator dialog appears.

  4. In that select “System DSN” tab and click the Add Button.

  5. Select “Microsoft Access Driver(*.mdb)” and click Finish.

  6. ODBC Microsoft Access Setup appears. In the “Data Source name” type “Library”.

  7. Click on the “Select” button and choose your database file. Then click ok.

Now your database file gets added to the System DSN. It should look like below,


Now execute the following code “Library.java”.


Library.java

import java.sql.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;

public class Library implements ActionListener
{
JRadioButton rbauthor = new JRadioButton("Search by Author name");
JRadioButton rbbook = new JRadioButton("Search by Book name");
JTextField textfld = new JTextField(30);
JLabel label = new JLabel("Enter Search Key");
JButton searchbutton = new JButton("Search");
JFrame frame = new JFrame();
JTable table;
DefaultTableModel model;
String query = "select * from Library";

public Library()
{
frame.setTitle("Online Public Access Catalog");
frame.setSize(500,600);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new BorderLayout());

JPanel p1 = new JPanel();
JPanel p2 = new JPanel();
JPanel p3 = new JPanel();

p1.setLayout(new FlowLayout());
p1.add(label);
p1.add(textfld);

ButtonGroup bg = new ButtonGroup();
bg.add(rbauthor);
bg.add(rbbook);

p2.setLayout(new FlowLayout());
p2.add(rbauthor);
p2.add(rbbook);
p2.add(searchbutton);
searchbutton.addActionListener(this);

p3.setLayout(new BorderLayout());
p3.add(p1,BorderLayout.NORTH);
p3.add(p2,BorderLayout.CENTER);

frame.add(p3,BorderLayout.NORTH);
addTable(query);
frame.setVisible(true);
}
public void addTable(String s)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection("jdbc:odbc:Library","","");
Statement st = conn.createStatement();

ResultSet rs = st.executeQuery(s);
ResultSetMetaData md = rs.getMetaData();
int cols = md.getColumnCount();
model = new DefaultTableModel(1,cols);
table = new JTable(model);
String[] tabledata = new String[cols];
int i=0;
while(i0)
model.removeRow(0);
frame.remove(table);
addTable(query);
}
public static void main(String[] args)
{
new Library();
}

}

Screenshots of Output

(Opening Screen)


(author Search)

(Book Search)



Download the Source Code


Library.java



Saturday, September 11, 2010

Multithreading using Pipes Program

Question

Write a multi-threaded Java program to print all numbers below 100,000 that are
both prime and fibonacci number (some examples are 2, 3, 5, 13, etc.). Design a
thread that generates prime numbers below 100,000 and writes them into a pipe.
Design another thread that generates fibonacci numbers and writes them to another pipe. The main thread should read both the pipes to identify numbers common to both.

Program Written by
Mr.G.Kumaresan sir.

Program


import java.util.*;
import java.io.*;

class Fibonacci extends Thread
{
private PipedWriter out = new PipedWriter();
public PipedWriter getPipedWriter()
{
return out;
}
public void run()
{
Thread t = Thread.currentThread();
t.setName("Fibonacci");
System.out.println(t.getName() + " thread started");
int fibo1=0,fibo2=1,fibo=0;
while(true)
{
try
{
fibo = fibo1 + fibo2;
if(fibo>100000)
{
out.close();
break;
}
out.write(fibo);
sleep(1000);
}
catch(Exception e)
{
System.out.println("Fibonacci:"+e);
}
fibo1=fibo2;
fibo2=fibo;
}
System.out.println(t.getName() + " thread exiting");

}
}
class Prime extends Thread
{
private PipedWriter out1 = new PipedWriter();
public PipedWriter getPipedWriter()
{
return out1;
}
public void run()
{
Thread t= Thread.currentThread();
t.setName("Prime");
System.out.println(t.getName() + " thread Started...");
int prime=1;
while(true)
{
try
{
if(prime>100000)
{
out1.close();
break;
}
if(isPrime(prime))
out1.write(prime);
prime++;
sleep(0);
}
catch(Exception e)
{
System.out.println(t.getName() + " thread exiting.");
System.exit(0);
}
}
}
public boolean isPrime(int n)
{
int m=(int)Math.round(Math.sqrt(n));
if(n==1 || n==2)
return true;
for(int i=2;i<=m;i++)
if(n%i==0)
return false;
return true;
}
}
public class PipedIo
{
public static void main(String[] args) throws Exception
{
Thread t=Thread.currentThread();
t.setName("Main");
System.out.println(t.getName() + " thread Started...");
Fibonacci fibonacci = new Fibonacci();
Prime prime = new Prime();
PipedReader fpr = new PipedReader(fibonacci.getPipedWriter());
PipedReader ppr = new PipedReader(prime.getPipedWriter());
fibonacci.start();
prime.start();
int fib=fpr.read(), prm=ppr.read();
System.out.println("The numbers common to PRIME and FIBONACCI:");
while((fib!=-1) && (prm!=-1))
{
while(prm<=fib)
{
if(fib==prm)
System.out.println(prm);
prm=ppr.read();
}
fib=fpr.read();
}
System.out.println(t.getName() + " thread exiting");
}
}

Download Source Code

PipedIo.java

Tuesday, September 7, 2010

Electives for 6th Semester

We have two Electives for sixth sem,

of which I feel these to be better

Elective 1

We can take either CS2023(Advanced Java Programming) or IT2353(Web Technology)....Both are of use to us.

Elective 2

Ofc, Numerical Methods would be an unanimous choice....

What do you feel????? What's your choice??

Monday, September 6, 2010

Software Engineering Important Ques

Unit 2 Important Ques in S/W Engineering.

Part A

1.List out the elements of Analysis Modelling. (with diagram).
2.Define Cardinality and Modality. (with diagram)
3. Compare and Contrast throw away and evolutionary prototyping.
4. Compare STD and DFD (with diagram).
5. Write the distinct steps in Requirement Engineering process.
6. Why requirement Elicitation process is difficult?
7. What are steps required to build ERD?
8. Benefits of Prototyping.
9. What is SRS, and its Characteristics.

Part B

1. Explain in detail about Requirement Engineering process.
2. Explain in detail about Data, Functional and Behavioral modelling along with diagrams.