0% found this document useful (0 votes)
34 views55 pages

OOPS Lab 2023-2024

The selection sorting algorithm iterates through an array, finds the minimum element, and swaps it into the current position to sort the array. It compares each element to find the minimum, stores its index, and swaps the minimum element into the current position in an outer loop to sort the array from lowest to highest. The program takes an unsorted array as input, applies the selection sorting algorithm to find the minimum element and swap it into place at each iteration, and outputs the sorted array.

Uploaded by

MANI KANDAN
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views55 pages

OOPS Lab 2023-2024

The selection sorting algorithm iterates through an array, finds the minimum element, and swaps it into the current position to sort the array. It compares each element to find the minimum, stores its index, and swaps the minimum element into the current position in an outer loop to sort the array from lowest to highest. The program takes an unsorted array as input, applies the selection sorting algorithm to find the minimum element and swap it into place at each iteration, and outputs the sorted array.

Uploaded by

MANI KANDAN
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 55

B.

E SIXTH SEMESTER

RECORD FOR

CS3381 OBJECT ORIENTED PROGRAMMING LABORATORY

NAME:…….…..............................................……………………

REG NO:….……………………………….…….…………………

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING


UNIVERSITY COLLEGE OF ENGINEERING TINDIVANAM
MELPAKKAM
TINDIVANAM-604001
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
LABORATORY RECORD NOTE BOOK

2023-204

This is to certify that this is a bonafide record of the work done by


Mr./Ms./Mrs………….……………………………………………………...,
Register Number …………………………………..………….. of the Fourth
year B.E., Department of Computer Science and Engineering in the CS3381 Object

Oriented Programming Laboratory in the Third Semester.

Record Work Completed on: …………………………………

Staff in-charge Head of the Department

Submitted for the University Practical Examination held on___________________

Internal Examiner External Examiner


TABLE OF CONTENT

Page
S.No Date Experiment Name Signature
No.

10

11

12

13

14

15

16
CS3381 Object Oriented Programming Laboratory

 To build software development skills using java programming for real-world applications.
 To understand and apply the concepts of classes, packages, interfaces, inheritance,
exception handling and file processing.
 To develop applications using generic programming and event handling
LIST OF EXPERIMENTS:

1. Solve problems by using sequential search, binary search, and quadratic sorting algorithms
(selection, insertion).
2. Develop stack and queue data structures using classes and objects.
3. Develop a java application with an Employee class with Emp_name, Emp_id, Address,
Mail_id, Mobile_no as members. Inherit the classes, Programmer, Assistant Professor,
Associate Professor and Professor from employee class. Add Basic Pay (BP) as the member
of all the inherited classes with 97% of BP as DA, 10 % of BP as HRA, 12% of
BP as PF, 0.1% of BP for staff club funds. Generate pay slips for the employees with their
gross and net salary.
4. Write a Java Program to create an abstract class named Shape that contains two integers and
an empty method named printArea(). Provide three classes named Rectangle, Triangle and
Circle such that each one of the classes extends the class Shape. Each one of the classes
contains only the method printArea( ) that prints the area of the given shape.
5. Solve the above problem using an interface.
6. Implement exception handling and creation of user defined exceptions.
7. Write a java program that implements a multi-threaded application that has three threads. First
thread generates a random integer every 1 second and if the value is even, the second thread
computes the square of the number and prints. If the value is odd, the third thread will print
the value of the cube of the number.
8. Write a program to perform file operations.
9. Develop applications to demonstrate the features of generics classes.
10. Develop applications using JavaFX controls, layouts and menus.
11. Develop a mini project for any application using Java concepts.

Lab Requirements: for a batch of 30 students


Operating Systems: Linux / Windows
Front End Tools: Eclipse IDE / Netbeans IDE
Ex. No : 1(a)

Date :

SEQUENTIAL SEARCH

AIM:

To develop a java program for Sequential search using array.

ALGORITHM:

1. We are searching the key in the array.


2. Read the array length and store the value into the variable len, read the elements
using the Scanner class method and store the elements into the array array[].
3. Read the key value and search for that key in the array.
4. Run the for loop for i = 0 to i < length of the array.
5. Compare array[i] with the key, If any one of the elements of an array is equal to the
key then print the key and position of the key.
Sample Output:
Enter Array length:
5
Enter 5 elements
8
3
56
4
8
Enter the search key value:
1
1 doesn't exist in array. Enter Array length:
3
Enter 3 elements
11
21
31
Enter the search key value:
11
11 is present at location 1
PROGRAM:
import java.util.Scanner;

/**
*
* @author Manikandan Ramamurthy - University College of Engineering Tindivanam
*/
class Linear {

public static void main(String args[]) {


int i, len, key, array[];
Scanner input = new Scanner(System.in);
System.out.println("Enter Array length:");
len = input.nextInt();
array = new int[len];
System.out.println("Enter " + len + " elements");
for (i = 0; i < len; i++) {
array[i] = input.nextInt();
}
System.out.println("Enter the search key value:");
key = input.nextInt();
for (i = 0; i < len; i++) {
if (array[i] == key) {
System.out.println(key + " is present at location " + (i + 1));
break;
}
}
if (i == len) {
System.out.println(key + " doesn't exist in array.");
}
}
}
OUTPUT:
run:
Enter Array length:
10
Enter 10 elements
55
66
99
88
77
11
22
2
33
66
Enter the search key value:
55
55 is present at location 1
BUILD SUCCESSFUL (total time: 2 minutes 47 seconds)

RESULT:
Thus the Implementation of sequential search program is executed successfully.
Ex. No : 1(b)

Date :

BINARY SEARCH

AIM:
To develop a java program for Binary search using array.

ALGORITHM:

1. Start the program


2. Create an object of binary class
3. Create a sorted array
4. Get input from user for element to be searched
5. Call the binary search method pass arguments: array, element, index of first and last
element
6. Create the Binary search function definition
7. Checking the condition while (low <= high) Repeat until the pointers low and high
meet each other
8. Get index of mid element int mid = low + (high - low) / 2, if element to be searched is
the mid element return mid.if element is less than mid element search only the left side
of mid. if element is greater than mid element search only the right side of mid, else
return -1.
9. Print the result and stop the process.
Sample Output:
Enter element to be searched:
8
Element found at index 5
PROGRAM:
import java.util.Scanner;
public class Binary {
int binarySearch(int array[], int element, int low, int high) {
while (low <= high) {
int mid = low + (high - low) / 2; if (array[mid] == element) return mid;
if (array[mid] < element)
low = mid + 1;
else
high = mid - 1;
}
return -1;
}
public static void main(String args[]) {
binary obj = new binary();
// create a sorted array
int[] array = { 3, 4, 5, 6, 7, 8, 9 };
int n = array.length;
// get input from user for element to be searched Scanner input = new Scanner(System.in);
System.out.println("Enter element to be searched:");
// element to be searched
int element = input.nextInt();
input.close();
// call the binary search method
// pass arguments: array, element, index of first and last element
int result = obj.binarySearch(array, element, 0, n - 1);
if (result == -1) System.out.println("Not found"); else
System.out.println("Element found at index " + result);
}
}
OUTPUT:
Enter element to be searched:
5
Element found at index 2

RESULT:
Thus the Implementation of Binary search program is executed successfully.
Ex. No : 1(c)

Date :

SELECTION SORTING

AIM:

To Develop Java program for Selecting Sorting Using Array

ALGORITHM:

1. Start the process


2. Entered numbers will store in to the int array a[] using for loop with the
structure for( i=0;i < n; i++).
3. Print array(int a[]) will print the numbers, from the index i=0 to i<length of the
array.
4. Sort(int a[]) will sort the numbers in ascending order. The inner loop will find the next least
number to the previous number and the outer loop will place the least number in proper
position in the array.
Given numbers are 9, 0, 1, 23, 99, 5.
a) The inner loop will compare the first two numbers 9,0 , the least number is 0,
then the loop compares 0 with 1, 23, 99, 5. There is no least number available than
0. So outer loop swap the 9,0 numbers. Then the series is 0, 9, 1, 23, 99, 5.
b) Now the inner loop compares the 9,1, the number 1 is the least than 9, then
compare 1 with 23, 99, 5. Compare with the next elements, 1 is the least number. Outer
loop swap the numbers 9,1. Now the series is 0, 1, 9, 23, 99, 5.
c) Compare 9,23, then the least number is 9, find the least number than 9. In this series 5
is least compare with 9, so the outer loop swap the numbers 9,5. The series is 0, 1, 5, 23,
99, 9.
d) Compare 23,99, the least number is 23, find the least number than 23, 9 is the
least number in the remaining series, Outer loop swap the numbers 23,9.Now the
series is 0,1,5,9,99,23.
e) Compare 99 with 23, 23 is the least number, swap the numbers 23,99.
After selection sort, the number series is 0, 1, 5, 9, 23, 99.
5. Print the result
Sample Output:

Enter number of elements in the array:6 Enter 6 elements


9
0
1
23
99
5
elements in array
9 0 1 23 99 5
elements after sorting
0 1 5 9 23 99

PROGRAM:
import java.util.Scanner;
/**
*
* @author Manikandan Ramamurthy - University College of Engineering Tindivanam
*/
public class SSort {

public static void Sort(int a[]) {


int n = a.length, i, j, p, temp;
for (i = 0; i < n - 1; i++) {
p = i;
for (j = i + 1; j < n; j++) {
if (a[p] > a[j]) {
p = j;
}
}
temp = a[p];
a[p] = a[i];
a[i] = temp;
}
}
public static void printarray(int a[]) {
for (int i = 0; i < a.length; i++) {
System.out.print(a[i] + " ");
}
}
public static void main(String[] args) {
int n, res, i;
Scanner s = new Scanner(System.in);
System.out.print("Enter number of elements in the array:");
n = s.nextInt();
int a[] = new int[n];
System.out.println("Enter " + n + " elements ");
for (i = 0; i < n; i++) {
a[i] = s.nextInt();
}
System.out.println("elements in array ");
printarray(a);
Sort(a);
System.out.println("\nelements after sorting");
printarray(a);
}
}

OUTPUT:
run:
Enter number of elements in the array:5
Enter 5 elements
55
44
33
22
11
elements in array
55 44 33 22 11
elements after sorting
11 22 33 44 55 BUILD SUCCESSFUL (total time: 7 seconds)

RESULT:

Thus the Implementation of Binary search program is executed successfully.


Ex. No : 1(d)

Date :
INSERTION SORTING
AIM:

To develop Java program for Insertion Sorting using Array.

ALGORITHM:

1. We are using an array for insertion sort.


2. The print method will print the array elements, the sort method will sort the
array elements.
3. The elements in the array are 9, 5, 0, 1, 8. For 1st iteration, the inner loop compares the number
with the previous number, if The previous number is greater than this number then shift the
least number to left. For i=1, inner loop compares the numbers 5<9, then 5 will be shifted to
left. Then the series is 5, 9, 0, 1, 8. In this sorted subarray is 5,9. for i=2, the inner loop
compares the numbers 0<9, shift 0 to left, compare 0<5, shift 0 to left.
4. Then the sorted subarray is 0, 5, 9. The series is 0, 5, 9, 1, 8.For i=3, the inner loop will
compare the numbers 1<9, shift 1 to left, compare 1<5, shift 1 to left, compare 1,0. The sorted
subarray is 0, 1, 5, 9 and the series is 0, 1, 5, 9, 8. For i=4, the inner loop will compare the
numbers 8<9, shift 8 to left. The sorted series is 0, 1, 5, 8, 9.
5. Stop the Process.

Sample Output:

Enter number of elements in the array:5 Enter 5 elements


9
5
1
8
elements in array
95018
elements after sorting
01589
PROGRAM:

import java.util.Scanner;

public class ISort {

public static void Sort(int a[]) {


int n = a.length, i, j, p, temp;
for (i = 1; i < n; i++) {

for (j = i - 1; j >= 0 && a[j + 1] < a[j]; j--) {


temp = a[j + 1];
a[j + 1] = a[j];
a[j] = temp;

}
}

public static void printarray(int a[]) {


for (int i = 0; i < a.length; i++) {

System.out.print(a[i] + " ");


}

public static void main(String[] args) {


int n, res, i;
Scanner s = new Scanner(System.in);
System.out.print("Enter number of elements in the array:");
n = s.nextInt();
int a[] = new int[n];
System.out.println("Enter " + n + " elements ");
for (i = 0; i < n; i++) {
a[i] = s.nextInt();
}
System.out.println("elements in array ");
printarray(a);
Sort(a);
System.out.println("\nelements after sorting");
printarray(a);

}
OUTPUT:
run:
Enter number of elements in the array:5
Enter 5 elements
8
9
1
5
6
elements in array
89156
elements after sorting
1 5 6 8 9 BUILD SUCCESSFUL (total time: 12 seconds)

RESULT:

Thus the Implementation of Insertion Sort program is executed successfully.


Ex. No : 2(a)

Date :
STACK IMPLENETATION USING CLASS AND OBJECT
AIM:

To develop Java program for Stack Implementation using Class and Object.

ALGORITHM:

1. Create stack and Store elements in stack for push pop operation
2. Push the elements to the top of stack, before push element in stack should stack is not
full
3. Pop the elements from the stack should not be empty.
4. After the push and pop operation print the stack elements
5. Stop the process.

Sample Output:

Inserting 1
Inserting 2
Inserting 3
Stack: 1, 2, 3,
After popping out
1, 2,

PROGRAM:

/**
*
* @author Manikandan Ramamurthy - University College of Engineering Tindivanam
*/
class stack {
private int arr[];
private int top;
private int capacity;
stack(int size) {
arr = new int[size];
capacity = size;
top = -1;
}
public void push(int x) {
if (isFull()) {
System.out.println("Stack OverFlow");
System.exit(1);
}
System.out.println("Inserting " + x);
arr[++top] = x;
}
public int pop() {
if (isEmpty()) {
System.out.println("STACK EMPTY");
System.exit(1);
}
return arr[top--];
}

public int getSize() {


return top + 1;
}

public Boolean isEmpty() {


return top == -1;
}

public Boolean isFull() {


return top == capacity - 1;
}

public void printStack() {


for (int i = 0; i <= top; i++) {
System.out.print(arr[i] + ", ");
}
}

public static void main(String[] args) {


stack stack = new stack(5);
stack.push(1);
stack.push(2);
stack.push(3);
System.out.print("Stack: ");
stack.printStack();
stack.pop();
System.out.println("\nAfter popping out");
stack.printStack();
}
}
OUTPUT:
run:
Inserting 1
Inserting 2
Inserting 3
Stack: 1, 2, 3,
After popping out
1, 2, BUILD SUCCESSFUL (total time: 0 seconds)

RESULT:

Thus the Implementation of Stack push, pop operation program is executed successfully.
Ex. No : 2(b)

Date :
QUEUE IMPLENETATION USING CLASS AND OBJECT
AIM:

To develop Java program for Queue Implementation using class and object.

ALGORITHM:
1. Enqueue: Adds an item from the back of the queue.
2. Dequeue: Removes an item from the front of the queue.
3. Front/Peek: Returns the value of the item in front of the queue without
dequeuing (removing) the item.
4. IsEmpty: Checks if the queue is empty.
5. IsFull: Checks if the queue is full.
6. Display: Prints all the items in the queue.

Sample Output:

Rear index-> 4
1 Deleted
Front index-> 1
Items ->
2345
Rear index-> 4

PROGRAM:

/**
*
* @author Manikandan Ramamurthy - University College of Engineering Tindivanam
*/
public class Queue {

int SIZE = 5;
int items[] = new int[SIZE];
int front, rear;

Queue() {
front = -1;
rear = -1;
}

boolean isFull() {
if (front == 0 && rear == SIZE - 1) {
return true;
}
return false;
}

boolean isEmpty() {
if (front == -1) {
return true;
} else {
return false;
}
}

void enQueue(int element) {


if (isFull()) {
System.out.println("Queue is full");
} else {
if (front == -1) {
front = 0;
}
rear++;
items[rear] = element;
System.out.println("Insert " + element);
}
}

int deQueue() {
int element;
if (isEmpty()) {
System.out.println("Queue is empty");
return (-1);
} else {
element = items[front];
if (front >= rear) {
front = -1;
rear = -1;
} else {
front++;
}
System.out.println(element + " Deleted");
return (element);
}
}

void display() {
int i;
if (isEmpty()) {
System.out.println("Empty Queue");
} else {
System.out.println("\nFront index-> " + front);
System.out.println("Items -> ");
for (i = front; i <= rear; i++) {
System.out.print(items[i] + " ");
}
System.out.println("\nRear index-> " + rear);
}
}
public static void main(String[] args) {
Queue q = new Queue();
q.deQueue();
for (int i = 1; i < 6; i++) {
q.enQueue(i);
}
q.enQueue(6);
q.display();
q.deQueue();
q.display();
}
}

OUTPUT:
run:
Queue is empty
Insert 1
Insert 2
Insert 3
Insert 4
Insert 5
Queue is full

Front index-> 0
Items ->
12345
Rear index-> 4
1 Deleted

Front index-> 1
Items ->
2345
Rear index-> 4
BUILD SUCCESSFUL (total time: 0 seconds)

RESULT:

Thus the Implementation of Queue enqueue, dequeue operation program is executed


successfully.
Ex. No : 3

Date :
GENERATING EMPLOYEE PAYROLL DETAILS
AIM:

To develop a java application for generating pay slips of employees with their Gross and Net
salary.

ALGORITHM:

1. The package keyword is used to create a package in java.


2. Create a class Employee inside a package name employee.
3. Class Employee contains Emp_name, Emp_id, Address, Mail_id, Mobile_no as
members.
4. By using Constructor initialize the instance variable of Employee class and display
method is used to print employee details.
5. Create classes Programmer, AssistantProfessor, AssociateProfessor and Professor
that extends Employee class and define necessary constructor for sub classes.
6. Each sub classes has its own instance variable like bPay and des.
7. Override the paySlip method in each sub classes to calculate the gross and net
salary
8. By using super () method subclasses initialize the super class constructor.
9. Import employee package and create the object for Empolyee class.
10. Create different Employee object to add ArrayList<> classes.
11. DisplayEmployee method is used to display all employee playSlip details
Sample Output:

Enter the Emp_Name:Manikandan.R


Enter the Emp_id: 4224058
Enter the Address:
Gingee
Enter the Mail_id: [email protected]
Enter the Mobile_no:
9943222676
Enter the Designation: Assistant Professor
Enter the Basic_Pay:
27000
Do you wnat continue press 'y'
y
Enter the Emp_Name: Rakesh
Enter the Emp_id: E705
Enter the Address:
pondy
Enter the Mail_id: [email protected] Enter the Mobile_no:
4567891230
Enter the Designation: Professor
Enter the Basic_Pay:
15000
PROGRAM:
package oops.lab;

import java.util.Scanner;

class Employee {

String Emp_name;
int Emp_id;
String Address;
String Mail_id;
String Mobile_no;

Scanner s = new Scanner(System.in);

public void fnRead() {


System.out.print("Enter name : ");
Emp_name = s.nextLine();

System.out.print("Enter ID : ");
Emp_id = Integer.parseInt(s.nextLine());

System.out.print("Enter Address : ");


Address = s.nextLine();

System.out.print("Enter mail ID : ");


Mail_id = s.nextLine();

System.out.print("Enter mobile number : ");


Mobile_no = s.nextLine();
}

public void fnDisplay() {


System.out.println("\n\n\t\t ** Employee Salary Details **");
System.out.println("============================Employee Details :
==========================");
System.out.println("Name : " + Emp_name);
System.out.println("Emp_ID : " + Emp_id);
System.out.println("Address : " + Address);
System.out.println("Mail ID : " + Mail_id);
System.out.println("Mobile number : " + Mobile_no);
System.out.println("============================Employee Salary Details :
=======================");
}
}

class Programmer extends Employee {

double BP, DA, HRA, PF, SCF;


double Gross_sal, Net_sal;

Programmer() {
BP = 8000;
}

public void fnCalc() {


DA = 0.97 * BP;
HRA = 0.10 * BP;
PF = 0.12 * BP;
SCF = 0.001 * BP;

Gross_sal = BP + DA + HRA;

Net_sal = Gross_sal - PF - SCF;

System.out.println("Basic : " + BP);


System.out.println("Dearness Allowance : " + DA);
System.out.println("HRA : " + HRA);
System.out.println("PF : " + PF);
System.out.println("Staff Club Fund : " + SCF);
System.out.println("Gross Salary : " + Gross_sal);
System.out.println("Net Salary : " + Net_sal);

System.out.println("===================================================
==================");

}
}
class AssistantProfessor extends Employee {

double BP, DA, HRA, PF, SCF;


double Gross_sal, Net_sal;

AssistantProfessor() {
BP = 15600;
}
public void fnCalc() {
DA = 0.97 * BP;
HRA = 0.10 * BP;
PF = 0.12 * BP;
SCF = 0.001 * BP;
Gross_sal = BP + DA + HRA;
Net_sal = Gross_sal - PF - SCF;
System.out.println("Basic : " + BP);
System.out.println("Dearness Allowance : " + DA);
System.out.println("HRA : " + HRA);
System.out.println("PF : " + PF);
System.out.println("Staff Club Fund : " + SCF);
System.out.println("Gross Salary : " + Gross_sal);
System.out.println("Net Salary : " + Net_sal);

System.out.println("===================================================
==================");

}
}
class AssociateProfessor extends Employee {

double BP, DA, HRA, PF, SCF;


double Gross_sal, Net_sal;

AssociateProfessor() {
BP = 37400;
}

public void fnCalc() {


DA = 0.97 * BP;
HRA = 0.10 * BP;
PF = 0.12 * BP;
SCF = 0.001 * BP;

Gross_sal = BP + DA + HRA;
Net_sal = Gross_sal - PF - SCF;

System.out.println("Basic : " + BP);


System.out.println("Dearness Allowance : " + DA);
System.out.println("HRA : " + HRA);
System.out.println("PF : " + PF);
System.out.println("Staff Club Fund : " + SCF);
System.out.println("Gross Salary : " + Gross_sal);
System.out.println("Net Salary : " + Net_sal);

System.out.println("===================================================
==================");

}
}

class Professor extends Employee {

double BP, DA, HRA, PF, SCF;


double Gross_sal, Net_sal;

Professor() {
BP = 54000;
}

public void fnCalc() {


DA = 0.97 * BP;
HRA = 0.10 * BP;
PF = 0.12 * BP;
SCF = 0.001 * BP;

Gross_sal = BP + DA + HRA;
Net_sal = Gross_sal - PF - SCF;

System.out.println("Basic : " + BP);


System.out.println("Dearness Allowance : " + DA);
System.out.println("HRA : " + HRA);
System.out.println("PF : " + PF);
System.out.println("Staff Club Fund : " + SCF);
System.out.println("Gross Salary : " + Gross_sal);
System.out.println("Net Salary : " + Net_sal);

System.out.println("===================================================
==================");

}
}

class Emp_PaySlip1 {

public static void main(String as[]) {


Programmer pgmr = new Programmer();
AssistantProfessor ap = new AssistantProfessor();
AssociateProfessor asp = new AssociateProfessor();
Professor prof = new Professor();
int choice;
Scanner s = new Scanner(System.in);
do {
System.out.println("1 – Programmer");
System.out.println("2 – Assistant Professor");
System.out.println("3 – AssociateProfessor");
System.out.println("4 – Professor");
System.out.println("5 – For Exit From Here.. : ");
System.out.print("Enter designation choice : ");

choice = s.nextInt();

switch (choice) {
case 1:
pgmr.fnRead();
pgmr.fnDisplay();
pgmr.fnCalc();
break;

case 2:
ap.fnRead();
ap.fnDisplay();
ap.fnCalc();
break;

case 3:
asp.fnRead();
asp.fnDisplay();
asp.fnCalc();
break;

case 4:
prof.fnRead();
prof.fnDisplay();
prof.fnCalc();
break;
}

} while (choice != 5);


}
}

OUTPUT:

1 – Programmer
2 – Assistant Professor
3 – Associate Professor
4 – Professor
5 – For Exit From Here.. :
Enter designation choice : 1
Enter name : Manikandan.R
Enter ID : 4334058
Enter Address : Tindivanam
Enter mail ID : [email protected]
Enter mobile number : 9943222676
** Employee Salary Details **
============================Employee Details :
==========================
Name : Manikandan.R
Emp_ID : 4334058
Address : Tindivanam
Mail ID : [email protected]
Mobile number : 9943222676
============================Employee Salary Details :
=======================
Basic : 8000.0
Dearness Allowance : 7760.0
HRA : 800.0
PF : 960.0
Staff Club Fund : 8.0
Gross Salary : 16560.0
Net Salary : 15592.0
============================Salary Slip with Details :
==========================
1 – Programmer
2 – Assistant Professor
3 – Associate Professor
4 – Professor
5 – For Exit From Here.. :
Enter designation choice :

RESULT:

Thus the application for generating pay slips of employees with their gross and net
salary has been successfully executed.
Ex. No : 4
Date:
FINDING THE AREA OF DIFFERENT SHAPE USING ABSTRACT CLASS

AIM:
To write a java program to find the area of different shapes by using abstract class.

ALGORITHM:
1. Import the java packages.
1. Create an abstract class named Shape that contains two integers and an empty method named
printArea().
2. Create a class Rectangle that extends the class Shape. Override the method printArea () by
getting Width and Length then compute the area and prints the area of the Rectangle.
3. Create a class Triangle that extends the class Shape. Override the method printArea () by
getting Base and Height then compute the area and prints the area of the Triangle.
4. Create a class Circle that extends the class Shape. Override the method printArea() by getting
the Radius, then compute the area and prints the area of the Circle.
5. By using Scanner class get the input during runtime.
6. Create object for a class in memory and assign it to the reference variable, then the method is
invoked.
Sample Output:
-------------------Finding the Area of Shapes :----------------------
----------------------- Area of Rectangle -----------------------
Enter the Width :
2.5
Enter the Length:
2.5
The area of the rectangle is : 6.25
------------------Area of Triangle---------------------------------------
Enter the Base :
6.6
Enter the Height :
2.2
The area of the triangle is :7.26
-----------------Area of Circle--------------------------------------------
Enter the Radius :
4.2
The area of circle is :55.3896
PROGRAM:
import java.util.*;

abstract class Shape {

public int x, y;

public abstract void printArea();


}

class Rectangle1 extends Shape {

public void printArea() {


float area;
area = x * y;
System.out.println("Area of Rectangle is " + area);
}
}

class Triangle extends Shape {

public void printArea() {


float area;
area = (x * y) / 2.0f;
System.out.println("Area of Triangle is " + area);
}
}

class Circle extends Shape {

public void printArea() {


float area;
area = (22 * x * x) / 7.0f;
System.out.println("Area of Circle is " + area);
}
}

public class AreaOfShapes {

public static void main(String[] args) {


int choice;
Scanner sc = new Scanner(System.in);

do {
System.out.println("Menu \n 1.Area of Rectangle \n 2.Area of Traingle \n 3.Area of
Circle \n 4.Exit");
System.out.print("Enter your choice : ");
choice = sc.nextInt();

switch (choice) {
case 1:
System.out.println("Enter length and breadth for area of rectangle : ");
Rectangle1 r = new Rectangle1();
r.x = sc.nextInt();
r.y = sc.nextInt();
r.printArea();
break;
case 2:
System.out.println("Enter bredth and height for area of traingle : ");
Triangle t = new Triangle();
t.x = sc.nextInt();
t.y = sc.nextInt();
t.printArea();
break;
case 3:
System.out.println("Enter radius for area of circle : ");
Circle c = new Circle();
c.x = sc.nextInt();
c.printArea();
break;
default:
System.out.println("Enter correct choice");
}
} while (choice < 4);
}
}
OUTPUT:
Menu
1.Area of Rectangle
2.Area of Traingle
3.Area of Circle
4.Exit
Enter your choice : 1
Enter length and breadth for area of rectangle :
55
66
Area of Rectangle is 3630.0
Menu
1.Area of Rectangle
2.Area of Traingle
3.Area of Circle
4.Exit
Enter your choice : 2
Enter bredth and height for area of traingle :
585
55
Area of Triangle is 16087.5
Menu
1.Area of Rectangle
2.Area of Traingle
3.Area of Circle
4.Exit
Enter your choice : 3
Enter radius for area of circle :
55
Area of Circle is 9507.143
Menu
1.Area of Rectangle
2.Area of Traingle
3.Area of Circle
4.Exit
Enter your choice : 4
Enter correct choice

RESULT:

Thus the Implementation for finding the area of different shapes using abstract class
has been successfully executed
Ex. No : 5
Date:
CIRCLE, RECTANGLE, TRIANGLE AREA CALCULATION USING INTERFACE
AIM:
To develop Java program Shape Area Calculation Using Interface.
ALGORITHM:
1. Import the java packages.
2. Create an Interface named Area that contains two integers and an method named
Compute().
3. Create a class Rectangle that implements Area. then compute the area and prints the area of
the Rectangle.
4. Create a class Triangle that implements the class Area. then compute the area and prints the
area of the Triangle.
5. Create a class Circle that implements the class Area. then compute the area and prints the
area of the Circle.
6. Create object for a class in memory and assign it to the reference variable, then the method
is invoked.

Sample Output:

The area of the Rectangle is 200.0


The area of the triangle is 100.0
The area of the Circle is 706.5
PROGRAM:
package oopslab;
/**
*
* @author Manikandan Ramamurthy from University college of Engineering
* Tindivanam
*/
import java.util.*;

interface Shape {

public abstract void printArea();


}

class Rectangle1 implements Shape {

public int x = 0, y = 0;

public void printArea() {


float area;
area = x * y;
System.out.println("Area of Rectangle is " + area);
}
}

class Triangle implements Shape {

public int x = 0, y = 0;

public void printArea() {


float area;
area = (x * y) / 2.0f;
System.out.println("Area of Triangle is " + area);
}
}

class Circle implements Shape {

public int x = 0, y = 0;

public void printArea() {


float area;
area = (22 * x * x) / 7.0f;
System.out.println("Area of Circle is " + area);
}
}
public class InterfaceShapeExp5 {

public static void main(String[] args) {


int choice;
Scanner sc = new Scanner(System.in);

do {
System.out.println("Menu \n 1.Area of Rectangle \n 2.Area of Traingle \n 3.Area of Circle
\n 4.Exit");
System.out.print("Enter your choice : ");
choice = sc.nextInt();

switch (choice) {
case 1:
System.out.println("Enter length and breadth for area of rectangle : ");
Rectangle1 r = new Rectangle1();
r.x = sc.nextInt();
r.y = sc.nextInt();
r.printArea();
break;
case 2:
System.out.println("Enter bredth and height for area of traingle : ");
Triangle t = new Triangle();
t.x = sc.nextInt();
t.y = sc.nextInt();
t.printArea();
break;
case 3:
System.out.println("Enter radius for area of circle : ");
Circle c = new Circle();
c.x = sc.nextInt();
c.printArea();
break;
default:
System.out.println("Enter correct choice");
}
} while (choice < 4);
}
}
OUTPUT:
Menu
1.Area of Rectangle
2.Area of Traingle
3.Area of Circle
4.Exit
Enter your choice : 1
Enter length and breadth for area of rectangle :
22
33
Area of Rectangle is 726.0
Menu
1.Area of Rectangle
2.Area of Traingle
3.Area of Circle
4.Exit
Enter your choice : 2
Enter bredth and height for area of traingle :
33
44
Area of Triangle is 726.0
Menu
1.Area of Rectangle
2.Area of Traingle
3.Area of Circle
4.Exit
Enter your choice : 3
Enter radius for area of circle :
2
Area of Circle is 12.571428
Menu
1.Area of Rectangle
2.Area of Traingle
3.Area of Circle
4.Exit
Enter your choice : 4
Enter correct choice

RESULT:
Thus the Implementation of different shape area calculated using Interface program is
executed successfully.
Ex. No : 6 USER DEFINED EXCEPTION

Date:

AIM:
To write a java program to implement user defined exception handling.
ALGORITHM:
1. Import the java packages.
1. Create a subclass of Exception named as InvalidCountryException it has only a constructor
displays the value of the exception.
2. The exception is thrown when registerUser ( ) when the country is not an India.
3. The main ( ) method sets up an exception handler for UserRegistration, then calls
registerUser ( ) with a legal value of the user’s country if the country of the user is other
then India it shows exception error message.

PROGRAM:

import java.util.Scanner;
class InvalidCountryException extends Exception {
public InvalidCountryException() {
System.out.println("InvalidCountryException occured");
System.out.println("User Outside India cannot be registered");
}
}

public class UserRegistration {

public void registerUser(String username, String userCountry) throws


InvalidCountryException {
if (!userCountry.equals("India"))
throw new InvalidCountryException();
else
System.out.println("User registration done successfully");
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String name = "", countryName = "";
System.out.print("Enter the name of user :");
name = scan.nextLine();
System.out.print("Enter country name :");
countryName = scan.nextLine();
UserRegistration registration = new UserRegistration();
try {
registration.registerUser(name, countryName);
}
catch (InvalidCountryException e) {
System.out.println(e.getMessage());
}
}

OUTPUT:

Enter the name of user :MANI


Enter country name :USA
InvalidCountryException occured
User Outside India cannot be registered null

RESULT:
Thus the Implementation for user defined exception handling has been successfully
executed.
Ex. No : 7 MULTI THREADED APPLICATION
Date:
AIM:
To write a program that implements a multi-threaded application.
ALGORITHM:
1. Import the java packages.
2. Create a thread that generates random number, Obtain one random number and
check is odd or even.
3. If number is even then create and start thread that computes square of a number,
Compute number * number and display the answer.
4. Notify to Random number thread and goto step 7.
5. If number is odd then create and start thread that computes cube of a number,
Compute number * number * number and display the answer.
6. Notify to Random number thread and goto step 7.
7. Wait for 1 Second and Continue to Step 3 until user wants to exits.
Sample Output:
Main Thread Generates Random Integer : 19
New Thread 19 is ODD and Cube of 19 is : 6859
-----------------------------------------------------
Main Thread Generates Random Integer : 60
New Thread 60 is EVEN and Square of 60 is : 3600
-----------------------------------------------------
Main Thread Generates Random Integer : 58
New Thread 58 is EVEN and Square of 58 is : 3364
-----------------------------------------------------
Main Thread Generates Random Integer : 55
New Thread 55 is ODD and Cube of 55 is : 166375
-----------------------------------------------------
Main Thread Generates Random Integer : 57
New Thread 57 is ODD and Cube of 57 is : 185193
-----------------------------------------------------
PROGRAM:
package oopslab;
import java.util.Random;
/**
*
* @author Manikandan Ramamurthy from University college of Engineering
* Tindivanam
*/
class Square extends Thread {

int x;

Square(int n) {
x = n;
}

public void run() {


int sqr = x * x;
System.out.println("Square of " + x + " = " + sqr);
}
}

class Cube extends Thread {

int x;

Cube(int n) {
x = n;
}

public void run() {


int cub = x * x * x;
System.out.println("Cube of " + x + " = " + cub);
}
}

class Number extends Thread {

public void run() {


Random random = new Random();
for (int i = 0; i < 10; i++) {
int randomInteger = random.nextInt(100);
System.out.println("Random Integer generated : " + randomInteger);
if (randomInteger %2 == 0) {
Square s = new Square(randomInteger);
s.start();
} else {
Cube c = new Cube(randomInteger);
c.start();
}
try {
Thread.sleep(1000);

} catch (InterruptedException ex) {


System.out.println(ex);
}
}
}
}

public class MultiThreadExp7 {

public static void main(String args[]) {


Number n = new Number();
n.start();
}
}
OUTPUT:
Random Integer generated : 59
Cube of 59 = 205379
Random Integer generated : 43
Cube of 43 = 79507
Random Integer generated : 43
Cube of 43 = 79507
Random Integer generated : 34
Square of 34 = 1156
Random Integer generated : 27
Cube of 27 = 19683
Random Integer generated : 60
Square of 60 = 3600
Random Integer generated : 7
Cube of 7 = 343
Random Integer generated : 71
Cube of 71 = 357911
Random Integer generated : 2
Square of 2 = 4
Random Integer generated : 93
Cube of 93 = 804357
BUILD SUCCESSFUL (total time: 10 seconds)

RESULT:
Thus the Implementation for application for multithreading has been successfully executed.
Ex. No : 8 FILE OPERATION

Date:

AIM:
To write a java program to implement file information such as reads a file name from the
user, displays information about whether the file exists, whether the file is readable, or writable, the
type of file and the length of the file in bytes.

ALGORITHM:

1. Import the java packages.


2. By using Scanner class get the input during runtime.
3. By using File class method create a File object associated with the file or directory specified
by pathname. The pathname can contain path information as well as a file or directory
name.
4. The exists() checks whether the file denoted by the pathname exists. Returns true if and only
if the file denoted by the pathname exists; false otherwise.
5. The getAbsolutePath() returns the absolute pathname string of the pathname.
6. The canRead() checks whether the application can read the file denoted by the pathname.
Returns true if and only if the file specified by the pathname exists and can be read by the
application; false otherwise.
7. The canWrite() checks whether the application can modify to the file denoted by the
pathname. Returns true if and only if the file system actually contains a file denoted by the
pathname and the application is allowed to write to the file; false otherwise.
8. The length() returns the length of the file denoted by the pathname. The return value is
unspecified if the pathname denotes a directory.
9. The endsWith() returns true if the given string ends with the string given as argument for the
method else it returns false.
10. The program uses conditional operator to check different functionalities of the given file.
PROGRAM:
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
// Importing the IOException class for handling errors
import java.io.IOException;
import java.util.Scanner;
public class FileOperationExp8 {

public static void main(String args[]) {


int choice, stop = 1;
Scanner sc = new Scanner(System.in);
do {
System.out.println(" ------- File Operation------");
System.out.println(" | 1. New File Creation ");
System.out.println(" | 2. File Information ");
System.out.println(" | 3. Write into the File ");
System.out.println(" | 4. Read from File ");
System.out.println(" | 5. Delete the File ");
System.out.println(" | 6. Exit From Here ");
System.out.println(" |_________");
System.out.print (" Enter Your Choice = ");
choice = sc.nextInt();
switch (choice) {
case 1: {
try {
// Creating an object of a file
File f0 = new File("D:FileOperationExample.txt");
if (f0.createNewFile()) {
System.out.println("File : " + f0.getName() + " is created successfully.");
} else {
System.out.println("File is already exist in the directory.");
}
} catch (IOException exception) {
System.out.println("An unexpected error is occurred.");
exception.printStackTrace();
}
break;
}
case 2: {
File f0 = new File("D:FileOperationExample.txt");
if (f0.exists()) {
// Getting file name
System.out.println("The name of the file is: " + f0.getName());

// Getting path of the file


System.out.println("The absolute path of the file is: " + f0.getAbsolutePath());

// Checking whether the file is writable or not


System.out.println("Is file writeable?: " + f0.canWrite());

// Checking whether the file is readable or not


System.out.println("Is file readable " + f0.canRead());

// Getting the length of the file in bytes


System.out.println("The size of the file in bytes is: " + f0.length());
} else {
System.out.println("The file does not exist.");
}
break;
}
case 3: {
try {
FileWriter fwrite = new FileWriter("D:FileOperationExample.txt");
// writing the content into the FileOperationExample.txt file
fwrite.write("A named location used to store related information is referred to as a
File.");

// Closing the stream


fwrite.close();
System.out.println("Content is successfully wrote to the file.");
} catch (IOException e) {
System.out.println("Unexpected error occurred");
e.printStackTrace();
}
break;
}
case 4: {
try {
// Create f1 object of the file to read data
File f1 = new File("D:FileOperationExample.txt");
Scanner dataReader = new Scanner(f1);
System.out.println("The file Contains: ");
while (dataReader.hasNextLine()) {
String fileData = dataReader.nextLine();
System.out.println(fileData);
}
dataReader.close();
} catch (FileNotFoundException exception) {
System.out.println("Unexcpected error occurred!");
exception.printStackTrace();
}
break;
}
case 5: {
File f0 = new File("D:FileOperationExample.txt");
if (f0.delete()) {
System.out.println(f0.getName() + " file is deleted successfully.");
} else {
System.out.println("Unexpected error found in deletion of the file.");
}
break;
}
case 6:
stop = 0;
default:
System.out.println("File Operation Completed");
}

} while (stop == 1);


}
}

OUTPUT:
run:
------- File Operation------
| 1. New File Creation
| 2. File Information
| 3. Write into the File
| 4. Read from File
| 5. Delete the File
| 6. Exit From Here
|_________
Enter Your Choice = 1
File : FileOperationExample.txt is created successfully.
------- File Operation------
| 1. New File Creation
| 2. File Information
| 3. Write into the File
| 4. Read from File
| 5. Delete the File
| 6. Exit From Here
|_________
Enter Your Choice = 2
The name of the file is: FileOperationExample.txt
The absolute path of the file is: D:\\FileOperationExample.txt
Is file writeable?: true
Is file readable true
The size of the file in bytes is: 0
------- File Operation------
| 1. New File Creation
| 2. File Information
| 3. Write into the File
| 4. Read from File
| 5. Delete the File
| 6. Exit From Here
|_________
Enter Your Choice = 3
Content is successfully wrote to the file.
------- File Operation------
| 1. New File Creation
| 2. File Information
| 3. Write into the File
| 4. Read from File
| 5. Delete the File
| 6. Exit From Here
|_________
Enter Your Choice = 4
The file Contains:
A named location used to store related information is referred to as a File.
------- File Operation------
| 1. New File Creation
| 2. File Information
| 3. Write into the File
| 4. Read from File
| 5. Delete the File
| 6. Exit From Here
|_________
Enter Your Choice = 5
FileOperationExample.txt file is deleted successfully.
------- File Operation------
| 1. New File Creation
| 2. File Information
| 3. Write into the File
| 4. Read from File
| 5. Delete the File
| 6. Exit From Here
|_________
Enter Your Choice = 6
File Operation Completed
BUILD SUCCESSFUL (total time: 8 seconds)

RESULT:

Thus the Implementation for getting file information has been successfully executed.
Ex. No : 9 GENERIC CLASSES

Date:

AIM:

To write a java program to find the maximum value from the given type of elements using a
generic function.

ALGORITHM:

1. Import the java packages.


2. Comparable interface is used to order the objects of user-defined class.
3. This interface is found in java.lang package and contains only one method named
compareTo(Object).
4. The compareTo() method works by returning an int value that is either positive, negative, or
zero.
5. Create a generic method max(), that can accept any type of argument.
6. Then sets the first element as the max element, and then compares all other elements with
the max element using compareTo() method
7. Finally the function returns an element which has the maximum value.
8. We can call generic method by passing with different types of arguments, the compiler
handles each method.
PROGRAM:

import java.util.*;

/**
*
* @author Manikandan Ramamurthy - University College of Engineering Tindivanam
*/
class MyGeneric {

public static <T extends Comparable<T>> T max(T... elements) {


T max = elements[0];
for (T element : elements) {
if (element.compareTo(max) > 0) {
max = element;
}
}
return max;
}

public static void main(String[] args) {


System.out.println("Integer Max: " + max(Integer.valueOf(32), Integer.valueOf(89)));
System.out.println("String Max: " + max("Manikandan ", "Mani"));
System.out.println("Double Max: " + max(Double.valueOf(5.6), Double.valueOf(2.9)));
System.out.println("Boolean Max: " + max(Boolean.TRUE, Boolean.FALSE));
System.out.println("Byte Max: " + max(Byte.MIN_VALUE, Byte.MAX_VALUE));
}
}

OUTPUT:

run:
Integer Max: 89
String Max: Manikandan
Double Max: 5.6
Boolean Max: true
Byte Max: 127
BUILD SUCCESSFUL (total time: 5 seconds)

RESULT:

Thus the Implementation for finding the maximum value from the given type of elements
using a generic function has been successfully executed.
Ex. No : 10 JAVAFX CONTROLS, LAYOUTS AND MENUS
Date:
AIM:
To develop Java program for creating controls, layouts and menus using JavaFX.
ALGORITHM:
1. Open new JavaFX New Application and save file name as JavaFXMenuSample
2. Import Supporting packages into program and extends javafx application object
Application.
3. Import menu package from javafx.scene.MenuBar.
4. Create menu and cerate menu items add the menu items to menu bar.
4. Launch the application and display the output.

PROGRAM:
package com.mycompany.mavenproject2;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
public class App extends Application {
public static void main(String[] args) {
launch(args);
}

@Override
public void start(Stage primaryStage) throws Exception {
// TODO Auto-generated method stub
BorderPane root = new BorderPane();
Scene scene = new Scene(root,200,300);
MenuBar menubar = new MenuBar();
Menu FileMenu = new Menu("File");
MenuItem filemenu1=new MenuItem("new");
MenuItem filemenu2=new MenuItem("Save");
MenuItem filemenu3=new MenuItem("Exit");
Menu EditMenu=new Menu("Edit");
MenuItem EditMenu1=new MenuItem("Cut");
MenuItem EditMenu2=new MenuItem("Copy");
MenuItem EditMenu3=new MenuItem("Paste");
EditMenu.getItems().addAll(EditMenu1,EditMenu2,EditMenu3);
root.setTop(menubar);
FileMenu.getItems().addAll(filemenu1,filemenu2,filemenu3);
menubar.getMenus().addAll(FileMenu,EditMenu);
primaryStage.setScene(scene);
primaryStage.show();

}
}

OUTPUT:

RESULT:

Thus the Implementation for JavaFX control, layout, menu program is executed
successfully.
Ex. No : 11 MINI PROJECT - OPAC SYSTEM

Date:

AIM:

To develop a mini project OPAC system for library using Java concepts.

ALGORITHM:

1. Import the awt,swing packages.

2. Extend the JFrame which implements action listener to the class datas.

3. Create the text field for id, name and button for next, address and the panel.

4. Create object for the get content pane().

5. Assign the length and breadth value for the layout using grid layout.

6. Add the new labels for ISBN and book name.

7. Add the new button for the next book

8. Create the book name under the driver jdbc odbc driver in the try block.

9. Create the object for exception as e and use it for catching the error.

10. Show all the records using show record.

MYSQL Table Creation:

Enter password: **** (root)

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 9

Server version: 8.0.33 MySQL Community Server - GPL

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> connect mysql

Connection id: 12

Current database: mysql


mysql> create table book(isbnno integer(5),bookname varchar(20));

Query OK, 0 rows affected, 1 warning (11.80 sec)

mysql> insert into book values(1000,"java");

Query OK, 1 row affected (0.42 sec)

mysql> insert into book values(1001,"C++");

Query OK, 1 row affected (0.08 sec)

mysql> insert into book values(1002,"C");

Query OK, 1 row affected (0.38 sec)

mysql> insert into book values(1003,"DBMS");

Query OK, 1 row affected (0.32 sec)

mysql> insert into book values(1004,"OOPS");

Query OK, 1 row affected (0.41 sec)

mysql> insert into book values(1005,"Compiler Design");

Query OK, 1 row affected (0.41 sec)

PROGRAM:

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

/**
*
* @author Manikandan Ramamurthy - University College of Engineering Tindivanam
*/
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();
c.add(new JLabel("ISBN Number", JLabel.CENTER));
c.add(id);
c.add(new JLabel("Book Name", JLabel.CENTER));
c.add(name);
c.add(p);
p.add(next);
next.addActionListener(this);
pack();
setVisible(true);
addWindowListener(new WIN());
}

public static void main(String args[]) {


Data d = new Data();
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
conn =
DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql?useUnicode=yes&characterEnc
oding=UTF-8&useSSL=false&allowPublicKeyRetrieval=true","root", "root");
// cust is the DSN Name
stat = conn.createStatement();
res = stat.executeQuery("Select * from book"); // stu is the table name
res.next();
} catch (Exception e) {
System.out.println("Error" + e);
}
d.showRecord(res);
}

@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == next) {
try {
res.next();
} catch (SQLException e1) {
}
showRecord(res);
}
}
public void showRecord(ResultSet res) {
try {
id.setText(res.getString(2));
name.setText(res.getString(3));
} catch (Exception e) {
}
}//end of the main
//Inner class WIN implemented

class WIN extends WindowAdapter {

public void windowClosing(WindowEvent w) {


JOptionPane jop = new JOptionPane();
jop.showMessageDialog(null, "Thank you", "My Application",
JOptionPane.QUESTION_MESSAGE);
}
}
}

OUTPUT:
RESULT:

Thus the program to develop the simple OPAC for the libraries is executed successfully.

You might also like