Oops Lab Manual (3) - Merged
Oops Lab Manual (3) - Merged
AIM:
ALGORITHM:
Step-2: Get the element to be searched and store it in a variable named value.
Step-3: Compare each element of the array with the variable name
PROGRAM:
(SequentialSearch.java)
import java.util.*;
class SequentialSearch
{
public static int search(int arr[], int x)
{
int n = arr.length;
for (int i = 0; i < n; i++)
{
if (arr[i] == x)
return i;
}
return -1;
}
public static void main(String args[])
{
int arr[] = new int[10];
int i;
Scanner s=new Scanner(System.in)
System.out.println(“Enter the Number of elements”);
int n= s.nextInt();
System.out.println(“Enter the array elements”)
for(i=0;i<n;i++)
{
arr[i] = s.nextInt();
}
System.out.println(“Enter the elements to be searched:”)
int x=s.nextInt();
int result = search(arr, x);
if (result == -1)
System.out.print("Element is not present in array");
else
System.out.print("Element is present at index “+ result);
}
}
OUTPUT:
AIM:
ALGORITHM:
PROGRAM:
(BinarySearch.java)
import java.util.*;
class BinarySearch
{
public static void binarySearch(int[] arr, int key)
{
int first = 0;
int last = input.length - 1;
int mid = (first + last) / 2;
while (first <= last)
{
if (arr[mid] < key)
{
first = mid + 1;
}
else if (arr[mid] == key)
{
System.out.println(key + " is found at location"+mid);
break;
}
else
{
last = mid - 1;
}
mid = (first + last) / 2;
}
if (first > last)
{
System.out.println(key + " is not present in the list.\n");
}
}
public static void main (String args[])
{
int arr[] = new int[10];
int i;
Scanner s=new Scanner(System.in)
System.out.println(“Enter the Number of elements”);
int n= s.nextInt();
System.out.println(“Enter the array elements”)
for(i=0;i<n;i++)
{
arr[i] = s.nextInt();
}
System.out.println(“Enter the elements to be searched:”)
int x=s.nextInt();
binarysearch(arr, x);
}
OUTPUT:
AIM:
ALGORITHM:
Program:
(SelectionSort.java)
import java.util.*;
class SelectionSort
{
public static void main (String args[ ])
{
int a[] = new int[10];
System.out.println(“\n How many elements want to enter in an array?”);
Scanner sc = new Scanner(System.in);
int n = sc.nextInt( );
for (int i=0; i<n; i++)
{
System.out.println(“\n Enter the Elements:”);
a[i] = sc.nextInt( );
}
System.out.println(“Before Sorting…”);
for (int i=0; i<n; i++)
{
System.out.println(a[i]+“ ”);
}
System.out.println(“Sorting process…”);
for(int i=0; i<n-1; i++)
{
int k = i;
for(int j=i+1; j<n; j++)
{
if(a[j]<a[k])
k = j;
}
int temp = a[k];
a[k] = a[i];
a[i] = temp;
}
System.out.println(“After Sorting…”);
for (int i=0; i<n; i++)
{
System.out.println(a[i]+“ ”);
}
}
}
OUTPUT:
How many elements want to enter in an array?
5
Enter the Elements
56
Enter the Elements
3
Enter the Elements
87
Enter the Elements
14
Enter the Elements
2
Before Sorting…
56 3 87 14 2
Sorting process….
After Sorting…
2 3 14 56 87
1 d) Implementation of Insertion Sort
AIM:
ALGORITHM:
PROGRAM:
(InsertionSort.java)
import java.util.*;
public class InsertionSort
{
public static void main(String[] args)
{
int a[] = new int[10];
System.out.println("How many elements want to enter in an array?");
Scanner sc = new Scanner(System.in);
int n = sc.nextInt( );
for (int i=0; i<n; i++)
{
System.out.println("Enter the Elements");
a[i] = sc.nextInt( );
}
System.out.println("Before Sorting…");
for (int i=0; i<n; i++)
{
System.out.println(a[i]+" ");
}
System.out.println("Sorting process ... ");
for(int i=1; i<n; ++i)
{
int key = a[i];
int j = i-1;
while(j >=0 && a[j]>key)
{
a[j+1] = a[j];
j = j-1;
}
a[j+1] = key;
}
System.out.println("After Sorting…");
for (int i=0; i<n; i++)
{
System.out.println(a[i]+" ");
}
}
}
OUTPUT:
How many elements want to enter in an array?
6
Enter the Elements
98
Enter the Elements
56
Enter the Elements
24
Enter the Elements
43
Enter the Elements
18
Enter the Elements
3
Before Sorting…
98 56 24 43 18 3
Sorting process....
After Sorting…
3 18 24 43 56 98
2 a) Implementation of Stack ADT
AIM:
ALGORITHM:
PROGRAM:
(StackDemo.java)
public class StackDemo //Class Creation
{
int size;
int stack[];
int top;
StackDemo(int s) //Constructor with one parameter
{
size = s;
stack = new int[size];
top = -1;
}
public void push(int element) //push operation
{
if(top == size-1)
{
System.out.println("Cannot insert Stack is Full");
}
else
{
top++;
stack[top] = element;
System.out.println("Elements Pused on stack is:"+element);
}
}
public int pop() //pop operation
{
if(top == -1)
{
System.out.println(" Cannot pop Stack is Empty");
return -1;
}
else
{
int item;
item = stack[top];
top --;
System.out.println("Element popped from stack is:"+item);
return item;
}
}
public int peek() //peek operation
{
if(top == -1)
{
System.out.println(" Cannot peek Stack is Empty");
return -1;
}
else
{
return stack[top];
}
}
-----------PUSH OPERATION------------
Elements Pused on stack is:30
Elements Pused on stack is:50
Elements Pused on stack is:80
Elements Pused on stack is:10
Elements Pused on stack is:40
------------PEEK OPERATION-----------
The Top element in the stack is:40
-----------POP OPERATION------------
Element popped from stack is:40
Element popped from stack is:10
Element popped from stack is:80
Element popped from stack is:50
Element popped from stack is:30
AIM:
ALGORITHM:
PROGRAM:
(QueueDemo.java)
import java.util.*;
public class QueueDemo
{
int capacity;
int que[];
int front,rear,size;
QueueDemo(int n)
{
capacity = n;
que = new int[n];
front = 0;
rear = -1;
size = 0;
}
public void enqueue(int item)
{
if(rear == capacity)
{
System.out.println("Queue is Full");
}
else
{
que[++rear] = item;
size++;
System.out.println("Insertion to queue:" +item);
}
}
public void dequeue()
{
if(front==rear)
{
System.out.println("Queue is empty");
}
else
{
int item=que[front++];
size--;
System.out.println("The deleted item is:"+item);
}
}
public void display()
{
if(front == rear)
{
System.out.println("Queue is empty");
}
else
{
for(int i=front; i<=rear; i++)
{
System.out.println(""+que[i]);
}
}
}
}
}
}
}
OUTPUT:
1. Enqueue
2.Dequeue
3.Display
4.Exit
AIM:
To develop a java application with employee class and implementation pay slips for the employees
with their gross and net salary.
ALGORITHM:
PROGRAM :
(Employee.java)
import java.util.*;
class Employee
{
String ename,address,mailid;
int eid;
long mobileno;
Scanner sc=new Scanner(System.in);
Employee()
{
System.out.println("enter the employee name");
ename=sc.next();
System.out.println("enter the employee id");
eid=sc.nextInt();
System.out.println("enter the address");
address=sc.next();
System.out.println("enter the mailid");
mailid=sc.next();
System.out.println("enter the mobileno");
mobileno=sc.nextLong();
}
}
(Programmer.java)
class Programmer extends Employee
{
double basic,hra,da,pf,stafffund,grosssalary,netsalary;
Programmer()
{
super();
System.out.println("enter the basic");
basic=sc.nextDouble();
}
void calculate()
{
da=0.97*basic;
hra=0.1*basic;
pf=0.12*basic;
stafffund=0.001*basic;
grosssalary=basic+da+hra;
netsalary=grosssalary-pf-stafffund;
void display()
{
System.out.println(" .................. ");
System.out.println("name "+ename);
System.out.println("id "+eid);
System.out.println("address "+address);
System.out.println("mailid "+mailid);
System.out.println("mobile "+mobileno);
System.out.println("da "+da);
System.out.println("hra "+hra);
System.out.println("pf "+pf);
System.out.println("stafffund "+stafffund);
System.out.println("grosssalary "+grosssalary);
System.out.println("netsalary "+netsalary);
System.out.println(" .................. ");
}
}
(Asstprof.java)
class Asstprof extends Employee
{
double basic,hra,da,pf,stafffund,grosssalary,netsalary;
Asstprof()
{
super();
System.out.println("enter the basic");
basic=sc.nextDouble();
}
void calculate()
{
da=0.97*basic;
hra=0.1*basic;
pf=0.12*basic;
stafffund=0.001*basic;
grosssalary=basic+da+hra;
netsalary=grosssalary-pf-stafffund;
}
void display()
{
System.out.println(" .................. ");
System.out.println("name "+ename);
System.out.println("id "+eid);
System.out.println("address "+address);
System.out.println("mailid "+mailid);
System.out.println("mobile "+mobileno);
System.out.println("da "+da);
System.out.println("hra "+hra);
System.out.println("pf "+pf);
System.out.println("stafffund "+stafffund);
System.out.println("grosssalary "+grosssalary);
System.out.println("netsalary "+netsalary);
System.out.println(" .................. ");
}
}
(Assoprof.java)
class Assoprof extends Employee
{
double basic,hra,da,pf,stafffund,grosssalary,netsalary;
Assoprof()
{
super();
System.out.println("enter the basic");
basic=sc.nextDouble();
}
void calculate()
{
da=0.97*basic;
hra=0.1*basic;
pf=0.12*basic;
stafffund=0.001*basic;
grosssalary=basic+da+hra;
netsalary=grosssalary-pf-stafffund;
}
void display()
{
System.out.println(" .................. ");
System.out.println("name "+ename);
System.out.println("id "+eid);
System.out.println("address "+address);
System.out.println("mailid "+mailid);
System.out.println("mobile "+mobileno);
System.out.println("da "+da);
System.out.println("hra "+hra);
System.out.println("pf "+pf);
System.out.println("stafffund "+stafffund);
System.out.println("grosssalary "+grosssalary);
System.out.println("netsalary "+netsalary);
System.out.println(" .................. ");
}
}
(Professor.java)
class Professor extends Employee
{
double basic,hra,da,pf,stafffund,grosssalary,netsalary;
Professor()
{
super();
System.out.println("enter the basic");
basic=sc.nextDouble();
}
void calculate()
{
da=0.97*basic;
hra=0.1*basic;
pf=0.12*basic;
stafffund=0.001*basic;
grosssalary=basic+da+hra;
netsalary=grosssalary-pf-stafffund;
}
void display()
{
System.out.println(" .................. ");
System.out.println("name "+ename);
System.out.println("id "+eid);
System.out.println("address "+address);
System.out.println("mailid "+mailid);
System.out.println("mobile "+mobileno);
System.out.println("da "+da);
System.out.println("hra "+hra);
System.out.println("pf "+pf);
System.out.println("stafffund "+stafffund);
System.out.println("grosssalary "+grosssalary);
System.out.println("netsalary "+netsalary);
System.out.println(" .................. ");
}
}
(EmployeepaySlipDemo.java)
class EmployeePaySlipDemo
{
public static void main (String m[])
{
Programmer obj=new Programmer();
obj.calculate();
obj.display();
AIM:
To write a java program to create an abstract class named shape and provide three classes named
rectangle ,triangle and circle such that each of the class extends the class shape.
ALGORITHM:
PROGRAM:
(Shapes.java)
public abstract class Shapes
{
double a,b;
abstract void printArea();
}
(Rectangle.java)
import java.util.*;
public class Rectangle extends Shapes
{
void printArea()
{
System.out.println("\t\t Claculating Area of Rectangle");
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Length:");
a = sc.nextDouble();
System.out.println("Enter the Breadth:");
b = sc.nextDouble();
double area = a*b;
System.out.println("Area of Rectangle is:"+area);
}
}
(Triangle.java)
(Circle.java)
(AbstractClassDemo.java)
public class AbstractClassDemo
{
public static void main(String[] args)
{
Shapes obj;
System.out.println(“Implementation of Abstract classes”);
obj = new Rectangle();
obj.printArea();
obj = new Triangle();
obj.printArea();
obj = new Circle();
obj.printArea();
}
}
OUTPUT:
AIM:
ALGORITHM:
PROGRAM:
(myinterface.java)
interface myinterface
{
public void printArea();
}
(Shapes.java)
public abstract class Shapes
{
double a,b;
abstract void printArea();
}
(Rectangle.java)
import java.util.*;
public class Rectangle extends Shapes implements myinterface
{
void printArea()
{
System.out.println("\t\t Claculating Area of Rectangle");
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Length:");
a = sc.nextDouble();
System.out.println("Enter the Breadth:");
b = sc.nextDouble();
double area = a*b;
System.out.println("Area of Rectangle is:"+area);
}
}
(Triangle.java)
(Circle.java)
(AbstractClassDemo.java)
public class InterfaceDemo
{
public static void main(String[] args)
{
Shapes obj;
System.out.println(“Implementation of Interface”);
obj = new Rectangle();
obj.printArea();
obj = new Triangle();
obj.printArea();
obj = new Circle();
obj.printArea();
}
}
OUTPUT:
Implementation of Interface
Claculating Area of Rectangle
Enter the Length:
15
Enter the Breadth:
30
Area of Rectangle is:450.0
Claculating Area of Triangle
Enter the Height:
50
Enter the Breadth:
20
Area of Triangle is:500.0
Claculating Area of Circle
Enter the Radius:
48
Area of Circle is:7234.5599999999995
6 a) Implementation of Predefined Exception
AIM:
ALGORITHM:
PROGRAM:
(Predefinedexception.java)
import java.util.*;
public class PredefinedException
{
public static void main (String[] args)
{
int a,b,c;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the value for divident:");
a = sc.nextInt();
System.out.println("Enter the the value for Divisor:");
b = sc.nextInt();
System.out.println("The value of a:"+a);
System.out.println("The value of b:"+b);
try
{
c=a/b;
}
catch(ArithmeticException e)
{
System.out.println("Exception caught:"+e);
}
}
OUTPUT:
AIM:
ALGORITHM:
Program:
(MyException.java)
int a;
MyException(int x)
{
a=x;
}
public String toString()
{
return "exception caught: The value is greater than 10:"+a;
}
static void compute (int n) throws MyException
{
if(n>10)
throw new MyException(n);
else
System.out.println(" The value is less than 10. Normal exit");
}
public static void main (String args[])
{
try
{
compute(1);
compute(20);
}
catch(MyException e)
{
System.out.println(e);
}
}
}
OUTPUT:
AIM:
ALGORITHM:
PROGRAM:
(FileDemoOperation.java)
import java.io.*;
class FileDemoOperation
{
public static void main (String m[]) throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the file name:");
String fname=br.readLine();
File f=new File(fname);
String result =f.exists()?"exist":"not exist";
System.out.println("The file "+result);
if(f.exists())
{
System.out.println("The Length of the file is "+f.length()+"bytes");
if(f.canRead())
System.out.println("The file is Readable");
else
System.out.println("The file is not Readable");
if(f.canWrite())
System.out.println("The file is Writeable");
else
System.out.println("The file is not Writable");
if(fname.endsWith(".txt"))
System.out.println("The file is text file");
if(fname.endsWith(".java"))
System.out.println("The file is java file");
if(fname.endsWith(".jpg"))
System.out.println("The file is image file");
}
}
}
OUTPUT:
AIM:
To develop a java program for copy the content of ine file into another file
ALGORITHM:
PROGRAM:
import java.io.*;
class FileDemo
{
public static void main (String args[ ])throws IOException
{
FileInputStream fin = new FileInputStream(“input.txt”);
FileOutputStream fout = new FileOutputStream(“output.txt”);
int c= fin.read();
while(c! = -1)
{
fout.write((char)c);
c = fin.read();
System.out.println(c);
}
fin.close( );
fout.close( );
}
}
OUTPUT:
Input File:(input.txt)
Output File:(output.txt)
AIM:
ALGORITHM:
PROGRAM:
(ThreadOne.java)
import java.util.*;
class ThreadOne extends Thread
{
}
t2.setnum(n);
System.out.println(“Second Thread is started….”); t2.start();
}
}
}
(ThreadTwo.java)
class ThreadTwo extends Thread
{
int num;
void setnum(int num)
{
this.num=num;
}
public void run()
{
try
{
System.out.println(“The Random Number Generated is even:”+num
+” ” +”Its Square is”+(num*num));
Thread.sleep(100);
}
catch(InterruptedException e)
{
System.out.println(e);
}
}
}
(ThreadThree.java)
class ThreadThree extends Thread
{
int num;
void setnum(int num)
{
this.num=num;
}
public void run()
{
try
{
System.out.println(“The Random Number Generated is odd:”+num +” “+”Its
Cube is:”+(num*num*num));
Thread.sleep(200);
}
catch(InterruptedException e)
{
System.out.println(e);
}
}
}
(ThreadDemo.java)
class ThreadDemo
{
public static void main(String m[])
{
System.out.println(“Main Thread is started…”);
ThreadOne t1=new ThreadOne();
t1.start();
}
}
OUTPUT:
AIM:
To develop a java application for finding maximum value using a generic function.
ALGORITHM:
PROGRAM:
(GenericMethodDemo.java)
class GenericMethodDemo
{
public static <T extends Comparable<T>> T maximum(T list[ ])
{
T max;
max=list[0];
for(int i=1;i<list.length;i++)
{
T element=list[i];
if(element.compareTo(max)>0)
max=element;
}
return(max);
}
public static void main(String m[])
{
Integer a[]={10,20,30,54,75,32,98,87};
Double b[]={23.45,67.89,4.2,3.76};
String c[]={"Priya","Nancy"};
System.out.println("Demonstration of Generic Method ... ");
System.out.println("The Maximum of Integer elements is:"+maximum(a));
System.out.println("The Maximum of Floating point elements is:”
+maximum(b));
System.out.println("The Maximum of String elements is:"+maximum(c));
} }
}
OUTPUT:
AIM:
ALGORITHM:
PROGRAM:
(GenericClassArr.java)
import java.util.*;
public class GenericClassArr<T>
{
public ArrayList <T> obj;
public GenericClassArr(int size)
{
obj = new ArrayList<T>(size);
}
public void insert(int index, T item)
{
obj.add(index,item);
}
public void display()
{
System.out.println(" " +obj);
}
public T del(int index)
{
return obj.remove(index);
}
}
(GenericClassDemo.java)
public class GenericClassDemo
{
public static void main(String[] args)
{
int[] iArray = {3,5,7,8,54};
GenericClassArr <Integer> iobj = new GenericClassArr <Integer>(10);
int i,index;
System.out.println("Array of Integers is .... ");
for(i=0;i<5;i++)
iobj.insert(i,iArray[i]);
iobj.display();
System.out.println("Inserting the Elemetns in Integer Array");
System.out.println("Enter the Element to be inserted:");
Scanner sc= new Scanner(System.in);
int item = sc.nextInt();
System.out.println("Enter the index at which the element to be inserted:");
index = sc.nextInt();
iobj.insert(index,item);
System.out.println(“The integer array after inserting is:”+iobj.display());
System.out.println("Enter the index of the Element to be deleted:");
index = sc.nextInt();
iobj.del(index);
System.out.println(“The integer array after deletion is:”+iobj.display());
double[] dArray = {11.11,22.22,33.33,44.44,55.55};
GenericClassArr<Double> dobj = new GenericClassArr<Double>(10);
System.out.println("Array of Doubles is .... ");
for(i=0;i<5;i++)
dobj.insert(i,dArray[i]);
dobj.display();
System.out.println("Inserting the Elemetns in Double Array");
System.out.println("Enter the Element to be inserted:");
double ditem = sc.nextDouble();
System.out.println("Enter the index at which the element to be inserted:");
index = sc.nextInt();
dobj.insert(index,ditem);
System.out.println(“The double array after inserting is:”+dobj.display());
System.out.println("Enter the index of the Element to be deleted:");
index = sc.nextInt();
dobj.del(index);
System.out.println(“The double array after deletion is:”+dobj.display());
}
}
OUTPUT:
AIM:
ALGORITHM:
PROGRAM:
(ControlsDemo.java)
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.*;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.stage.Stage;
public class ControlsDemo extends Application
{
public void start(Stage ps)
{
Label l1=new Label("Name");
TextField t1= new TextField();
Label l2=new Label("Register number");
TextField t2= new TextField();
Label l3=new Label("Age");
TextField t3= new TextField();
Label l4=new Label("Address");
TextArea t4= new TextArea();
t4.setPrefHeight(100);
t4.setPrefWidth(100);
Label l5=new Label("Gender");
RadioButton rb1= new RadioButton("Male");
RadioButton rb2= new RadioButton("Female");
Label l6=new Label("Hobbies");
CheckBox cb1= new CheckBox("Watching TV");
CheckBox cb2= new CheckBox("Reading Books");
CheckBox cb3= new CheckBox("Palying");
CheckBox cb4= new CheckBox("Lisening Music");
Label l7=new Label("Country");
ChoiceBox chb1= new ChoiceBox();
chb1.getItems().add("America");
chb1.getItems().add("Cannada");
chb1.getItems().add("India");
chb1.getItems().add("Russia");
Button btn = new Button();
btn.setText("Submit");
btn.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
System.out.println("Controls Demo!");
System.out.println("The Name is:"+t1.getText());
System.out.println("The Register Number is:"+t2.getText());
System.out.println("The Age is:"+t3.getText());
System.out.println("The Address is:"+t4.getText());
System.out.println("The Country is:"+chb1.getValue());
}
});
GridPane root= new GridPane();
root.addRow(0,l1,t1);
root.addRow(1,l2,t2);
root.addRow(2,l3,t3);
root.addRow(3,l4,t4);
root.addRow(4,l5,rb1,rb2);
root.addRow(5,l6,cb1,cb2,cb3,cb4);
root.addRow(6,l7,chb1);
root.addRow(7,btn);
Scene scene = new Scene(root, 300, 250);
ps.setTitle("Controls Demo");
ps.setScene(scene);
ps.show();
}
public static void main(String[] args)
{
launch(args);
}
}
OUTPUT:
10 b) Implementation of JavaFX layouts
AIM:
PROGRAM:
(FlowPaneLayoutDemo.java)
mport javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.*;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.stage.*
public class FlowPaneLayoutDemo extends Application
{
public void start(Stage ps)
{
FlowPane root = new FlowPane();
Button b1 = new Button("ONE");
Button b2 = new Button("TWO");
Button b3 = new Button("THREE");
Button b4 = new Button("FOUR");
Button b5 = new Button("FIVE");
Button b6 = new Button("SIX");
root.getChildren().addAll(b1,b2,b3,b4,b5,b6);
Scene scene = new Scene(root, 300, 250);
ps.setTitle("LayoutDEmo");
ps.setScene(scene);
ps.show();
}
public static void main(String[] args)
{
launch(args);
}
}
OUTPUT:
10 c) Implementation of Menus
AIM:
ALGORITHM:
PROGRAM:
(MenusDemo.java)
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
public class MenusDemo extends Application
{
public void start(Stage primaryStage)
{
// creating Menu Bar
MenuBar mbar = new MenuBar();
// Creating Three Menus
Menu fmenu = new Menu("File");
Menu emenu = new Menu("Edit");
Menu hmenu = new Menu("Help");
//Creating Menu Items for File menu
MenuItem newItem = new MenuItem("New");
MenuItem openItem = new MenuItem("Open File");
MenuItem saveItem = new MenuItem("Save");
MenuItem exitItem = new MenuItem("Exit");
// Creating Menu Items for Edit menu
MenuItem cutItem = new MenuItem("Cut");
MenuItem copyItem = new MenuItem("Copy");
MenuItem pasteItem = new MenuItem("Paste");
// Adding MenuItems to the Menus
fmenu.getItems().addAll(newItem,openItem,saveItem,exitItem);
emenu.getItems().addAll(cutItem,copyItem,pasteItem);
// Adding Menus to the Menu bar
mbar.getMenus().addAll(fmenu,emenu,hmenu);
BorderPane root = new BorderPane();
//Adding Menu Bar to the Border Layout
root.setTop(mbar);
Scene scene = new Scene(root, 400, 300);
primaryStage.setTitle("JavaFX Menus Demo");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args)
{
launch(args);
}
}
OUTPUT:
MINI PROJECT - OPAC SYSTEM
AIM:
To develop a mini project OPAC system for library using Java concepts.
ALGORITHM:
PROGRAM:
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Data extends JFrame implements ActionListener
{
JTextField id;
JTextField name;
JButton next;
JButton addnew;
JPanel p;
static ResultSet res;
static Connection conn;
static Statement stat;
public Data()
{
super("My Application");
Container c = getContentPane();
c.setLayout(new GridLayout(5,1));
id = new JTextField(20);
name = new JTextField(20);
next = new JButton("Next BOOK");
p = new JPanel();
p.add(next);
next.addActionListener(this);
pack();
setVisible(true);
addWindowListener(new WIN());
}
NOTE:
Create a new Database
1. Create a new Database file in MS ACCESS (our backend) named “books.mdb”.
2. Then create a table named “stu” in it.
3. The table stu contains the following fields and data types
i. ISBN - Text
ii. BookName - Text
4. Enter various records as you wish.
5. Save the database file.
Next step is to add our “books.mdb” to the System DSN. To do that follows the procedure
given below,
i. Go to Start-> Control Panel -> Administrative tools.
ii. In that double click “Data Sources (ODBC)”.
iii. ODBC Data Source Administrator dialog appears.
iv. In that select “System DSN” tab and click the Add Button.
v. Select “Microsoft Access Driver(*.mdb)” and click Finish.
vi. ODBC Microsoft Access Setup appears. In the “Data Source name” type “stu”.
vii. Click on the “Select” button and choose your database file. Then click ok.
To Compile:
javac Data.java
To Run:
java Data
RESULT:
Thus the program to develop the simple OPAC for the libraries is executed
successfully.