0% found this document useful (0 votes)
12 views64 pages

Kaka

The document outlines the curriculum and practical examination details for the CS3381 Object Oriented Programming Laboratory course at Anna University for the academic year 2024-25. It includes course objectives, program outcomes, specific outcomes, a list of experiments, and sample Java programs demonstrating various programming concepts. Additionally, it provides a structure for recording student work and assessments related to the course.

Uploaded by

ahamedahusan786
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)
12 views64 pages

Kaka

The document outlines the curriculum and practical examination details for the CS3381 Object Oriented Programming Laboratory course at Anna University for the academic year 2024-25. It includes course objectives, program outcomes, specific outcomes, a list of experiments, and sample Java programs demonstrating various programming concepts. Additionally, it provides a structure for recording student work and assessments related to the course.

Uploaded by

ahamedahusan786
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/ 64

DEPARTMENT OF COMPUTER SCIENCE AND ENGIN EERING

ACADEMIC YEAR 2024 – 25 ( ODD SEM )

CS3381 – Object Oriented Programming Laboratory

ANNA UNIVERSITY REGULATION – 2021

STUDENT NAME :
REGISTER NUMBER :
CLASS :
BATCH :
MOHAMED SATHAK ENGINEERING COLLEGE

KILAKARAI – 623806

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

ANNA UNIVERSITY – CHENNAI – 600025

UG PRACTICAL EXAMINATIONS - 2024

RECORD NOTE BOOK

CS3381 – Object Oriented Programming Laboratory

Student Name :

Register Number :

Class & Semester : II – CSE & III – Semester

Month & Year :


MOHAMED SATHAK ENGINEERING COLLEGE

KILAKARAI – 623806.

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

BONAFIDE CERTIFICATE

This is certified that this is the bonafide record of work done by . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . Register. No . . . . . . . . . . . . . . . . . . . . of the class II CSE, III SEMESTER for the

practical CS3381 – Object Oriented Programming Laboratory during the year 2024 - 25.

Staff-in-charge H.O.D.

Submitted for the university practical examination held on . . . . . . . . . . . . .

Internal Examiner External Examiner


B.E. COMPUTER SCIENCE AND ENGINEERING

PROGRAM OUTCOMES (POs)

1 Engineering knowledge: A pply the knowledge of mathematics, science, engineering


fundamenta l s, and an engineering specialization to the solut i o n of com p l ex engineering
problems.
2 Probl em analy sis : I dentify, f orm ulate, review research literature, an d analyze comple x
engineering problems reaching substant i ated conc l usions us i ng f i rst princ i ples of
mathematics, natural sciences, and engineering sciences.
3 Design/development of solutions: Design solutions for complex engineering problems and
design system components or processes that meet the specified needs with appropr i ate
consideration for the public health and safety, and the cultural, societal , and environmental
considerations.
4 Conduct investigations of comp lex pr oblems: Use research-based knowledge and
research methods including design of experiments, analysis and interpr etation of data, and
syn thesi s of the inf ormation to pr ovide v ali d co nclusions.
5 Modern tool usage: Create, select, and app l y appropriate techniques, resources, and
modern engineering and IT too l s inc l uding pred i c t i o n and modeling to complex engineering
activities with an understanding of the limitations.
6 The engineer and society: Apply reason i ng informed by the contextual knowledge to
assess societa l , health, safety, legal and cultural i ssues and the consequent responsibilities
relevant to the professional engineer i n g practice.
7 Environment and sustainability: Understand the impact of the professional engineering
solutions in societal and environmental contexts, and demonstrate the knowledge of, and need
for sustainab l e develo pment.
8 Ethics: Apply ethical principles and comm i t to professional ethics and responsibilities and
norms of the engineering practice.
9 Individual and team work: Function effectively as an i ndividual, and as a member or
leader in diverse teams, and in multidisc i plinary settings.
10 Communication: Communicate effectively on complex engineering activities with the
engineering community and with society at large, such as, being able to comprehend and write
effective reports and design documentation, make effective presentations, and give and receive
clear instructions.
11 Project management and finance: Demonstrate knowledge and understanding of the
engineering and management principles and apply these to one’s own work, as a member and
leader in a team, to manage projects and in multidisciplinary environments.

12 Life-long learning: Recognize the need for, and have the preparation and ability to
engage in independent and life-long learning in the broadest context of technological change.

PROGRAM SPECIFIC OUTCOMES (PSOs)

The Students will be able to

 Exhibit design and programming skills to build and automate business solutions using cutting
edge technologies.
 Strong theoretical foundation leading to excellence and excitement towards research, to
provide elegant solutions to complex problems.
 Ability to work effectively with various engineering fields as a team to design, build and
develop system applications. 1
CS3381 OBJECT ORIENTED PROGRAMMING LABORATORY L T P C
0 0 3 1.5
COURSE OBJECTIVES :
 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, Assi stant 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 clas ses 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.
TOTAL: 45 PERIODS
COURSE OUTCOMES:
On completion of this course, the students will be able to
CO1 : Design and develop java programs using object oriented programming concepts
CO2 : Develop simple applications using object oriented concepts such as package, exceptions
CO3: Implement multithreading, and generics concepts
CO4 : Create GUIs and event driven programming applications for real world problems
CO5: Implement and deploy web applications using Java
CO’s- PO’s & PSO’s MAPPING
CO’s PO’s PSO’s
1 2 3 4 5 6 7 8 9 10 11 12 1 2 3
1 2 1 2 1 - - - -

1 2 2 2 1 2 3
2 2 1 3 1 - - - -

2 3 3 2 1 3 1
3 2 2 1 2 1 - - -

1 2 1 3 2 3 2
4 2 2 1 3 - - - -

3 1 1 1 2 1 2
5 1 3 3 1 3 - - -

1 1 1 1 2 1 2
AVg. 2 2 2 2 2 - - -

2 2 2 2 2 2 2
1 - low, 2 - medium, 3 - high, ‘-“- no correlation
INDEX

Exp
DATE NAME OF THE PROGRAM PAGE No. SIGNATURE
No.

1 Solve problems by using sequential search,


binary search, and quadratic sorting algorithms

2 Develop stack and queue data structures


using classes and objects.

3 Generating Employee Payroll Details

4
Finding the area of different shapes

5 Solving the problem using Interface

6 Creating Own Exceptions

7 Multi Threaded Application

8 Getting File Information

9 Generic Programming

10 Develop applications using JavaFX controls,


layouts and menus.

11 Mini Project - Opac System


EXNO:1 a
Solve problems by using sequential search
DATE:

AIM:

To write a java program for Solve problems by using sequential search.

ALGORITHM:

1. Start.
2. Input the array array[] and the target value.
3. Set i = 0 (initialize the index).
4. Check if i is less than the length of array[].
5. If array[i] == target, return index i.
6. If not, increment i by 1.
7. Repeat steps 4-6 until either the target is found or the end of the array is reached.
8. If target is not found, return -1 and En

Program:
import java.util.Scanner;

public class SequentialSearch {

// Method to perform sequential search


public static int sequentialSearch(int[] array, int target) {
for (int i = 0; i < array.length; i++) {
if (array[i] == target) {
return i; // Return index of the target if found
}
}
return -1; // Return -1 if target is not found
}

public static void main(String[] args) {


// Create a Scanner object to read input
Scanner scanner = new Scanner(System.in);

// Sample array of integers


int[] array = { 5, 8, 3, 10, 15, 7, 9, 2, 6, 4 };

// Prompt user for the target value


System.out.print("Enter the target value to search for: ");
int target = scanner.nextInt();

// Call the sequentialSearch method to find the target


int result = sequentialSearch(array, target);

1
// Output the result of the search
if (result != -1) {
System.out.println("Target " + target + " found at index: " + result);
} else {
System.out.println("Target " + target + " not found in the array.");
}

// Close the scanner to avoid resource leaks


scanner.close();
}
}

2
Target Found at Index

Input

Enter the target value to search for: 10

Output

Target 10 found at index: 3

Target Not Found

Input
Enter the target value to search for: 12

Output
Target 12 not found in the array.

Result:

Thus the above program is executed successfully and output also verified.

3
EXNO:1 b
Solve problems by using binary search
DATE:

AIM:

To write a java program for Solve problems by using Binary search.

Algorithms:

1. Start.
2. Input the sorted array array[] and the target value.
3. Set low = 0 and high = length of array[] - 1 (initialize search bounds).
4. While low <= high, repeat the following:

• Calculate mid = low + (high - low) / 2.


5. If array[mid] == target, return mid (index where the target is found).
6. If array[mid] > target, set high = mid - 1 (search in the left half).
7. If array[mid] < target, set low = mid + 1 (search in the right half).
8. If target is not found, return -1 and End.

Program:

import java.util.Scanner;

public class BinarySearch {

// Method to perform binary search on a sorted array


public static int binarySearch(int[] array, int target) {
int low = 0;
int high = array.length - 1;

while (low <= high) {


// Find the middle index
int mid = low + (high - low) / 2;

// Check if the target is at the middle


if (array[mid] == target) {
return mid; // Return the index if target is found
}
// If target is smaller, search in the left half
else if (array[mid] > target) {
high = mid - 1;
}
// If target is larger, search in the right half
4
else {
low = mid + 1;
}
}

// If the target is not found, return -1


return -1;
}

public static void main(String[] args) {


// Create a Scanner object to read input
Scanner scanner = new Scanner(System.in);

// Sample sorted array


int[] array = {1, 3, 5, 7, 9, 11, 13, 15, 17, 19};

// Prompt user for the target value


System.out.print("Enter the target value to search for: ");
int target = scanner.nextInt();

// Call the binarySearch method to find the target


int result = binarySearch(array, target);

// Output the result of the search


if (result != -1) {
System.out.println("Target " + target + " found at index: " + result);
} else {
System.out.println("Target " + target + " not found in the array.");
}

// Close the scanner to avoid resource leaks


scanner.close();
}
}

Target Found
Input
Enter the target value to search for: 7

Output
Target 7 found at index: 3

5
Target Not Found

Input
Enter the target value to search for: 10
Output
Target 10 not found in the array.

Result:

Thus the above program are executed successfully and output also verified.

6
EXNO:1c
Solve problems by using quadratic sorting algorithms (SELECTION)
DATE:

AIM:

To write a java program for Solve problems by quadratic sorting algorithms.

ALGORITHMS:

1. Input number of elements (n).


2. Create an array arr[] of size n.
3. Input n elements into arr[].
4. Clone arr[] to create arr1[], arr2[], arr3[].
5. Print the original array (arr[]).
6. Sort and print arr1[] using Bubble Sort.
7. Sort and print arr2[] using Selection Sort.
8. Sort and print arr3[] using Insertion Sort.

7
PROGRAM:

// Java program for implementation of Selection Sort

import java.util.Scanner;

import java.util.Arrays;

public class QuadraticSorting {

// Bubble Sort

public static void bubbleSort(int[] arr) {

for (int i = 0; i < arr.length - 1; i++) {

for (int j = 0; j < arr.length - 1 - i; j++) {

if (arr[j] > arr[j + 1]) {

int temp = arr[j];

arr[j] = arr[j + 1];

arr[j + 1] = temp;

// Selection Sort

public static void selectionSort(int[] arr) {

for (int i = 0; i < arr.length - 1; i++) {

int minIndex = i;

for (int j = i + 1; j < arr.length; j++) {

if (arr[j] < arr[minIndex]) minIndex = j;

8
int temp = arr[minIndex];

arr[minIndex] = arr[i];

arr[i] = temp;

// Insertion Sort

public static void insertionSort(int[] arr) {

for (int i = 1; i < arr.length; i++) {

int key = arr[i];

int j = i - 1;

while (j >= 0 && arr[j] > key) {

arr[j + 1] = arr[j];

j--;

arr[j + 1] = key;

// Method to print an array

public static void printArray(int[] arr) {

System.out.println(Arrays.toString(arr));

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

// Input array size and elements


9
System.out.print("Enter the number of elements:");

int n = sc.nextInt();

int[] arr = new int[n];

System.out.println("Enter the array elements:");

for (int i = 0; i < n; i++) arr[i] = sc.nextInt();

// Clone and sort

int[] arr1 = arr.clone(), arr2 = arr.clone(), arr3 =


arr.clone();

System.out.println("\nOriginal Array: ");

printArray(arr);

System.out.println("\nBubble Sort:");

bubbleSort(arr1);

printArray(arr1);

System.out.println("\nSelection Sort:");

selectionSort(arr2);

printArray(arr2);

System.out.println("\nInsertion Sort:");

insertionSort(arr3);

printArray(arr3);

sc.close();

10
}

Input

Enter the number of elements: 5

Enter the array elements:

64 25 12 22 11

Output

The program will display:

The original unsorted array.

The array after being sorted using Bubble Sort.

The array after being sorted using Selection Sort.

The array after being sorted using Insertion Sort.

Result:

Thus the above program are executed successfully and output also verified.

11
EXNO:1d
Solve problems by using quadratic sorting algorithms (INSERTION)
DATE:

AIM:

To write a java program for Solve problems by quadratic sorting algorithms..

ALGORITHMS:

1. Import the java packages.


2. Iterate from arr[1]to arr[N] over the array.
3. Compare the current element(key)to its predecessor.
4. If the key element is smaller than its predecessor, compare it to the elements before.
5. Move the greater elements one position up to make space for the swapped element
6. Run the program.
7. Display the result.
8. Stop the program.

12
PROGRAM:

// Java program for implementation of Insertion Sort


public class InsertionSort {

/* Function to sort array using insertion sort */


void sort(int arr[]) {
int n = arr.length; // Declare the length of the array
for (int i = 1; i < n; ++i) {
int key = arr[i]; // Key element to insert
int j = i - 1; // Index of the previous element

// Move elements of arr[0..i-1], that are greater than key,


// to one position ahead of their current position
while (j >= 0 && arr[j] > key) {
arr[j + 1] = arr[j]; // Shift the element
j = j - 1; // Move to the previous element
}
arr[j + 1] = key; // Place key in its correct position
}
}

/* A utility function to print array of size n */


static void printArray(int arr[]) {
int n = arr.length; // Declare the length of the array
for (int i = 0; i < n; ++i)
System.out.print(arr[i] + " "); // Print the element
System.out.println(); // Move to the next line after printing the array
}

// Driver method
public static void main(String args[]) {
int arr[] = {12, 11, 13, 5, 6}; // Array to be sorted

InsertionSort ob = new InsertionSort(); // Create an object of InsertionSort


ob.sort(arr); // Call the sort method to sort the array

printArray(arr); // Print the sorted array

13
}
}

Output
5 6 11 12 13

Result:

Thus the above program is executed successfully and out put also verified.

14
EXNO:2a
Develop stack data structure using classes and objects.
DATE:

AIM:

To write a java program for Develop stack using classes and objects.

ALGORITHMS:

1. Import the java packages.


2. The class is based on the basic principle of last-in-first-out.
3. In addition to the basic push and pop operations, the class provides three more
functions of empty, search, and peek.
4. The class can also be said to extend Vector and treats the class as a stack with the
five mentioned functions.
5. The class can also be referred to as the sub class of Vector.
6. Run the program.
7. Display the result.
8. Stop the program.

15
PROGRAM:

import java.util.Stack;

class Test {
// Pushing elements on the top of the stack
static void stack_push(Stack<Integer> stack) {
for (int i = 0; i < 5; i++) {
stack.push(i);
}
}

// Popping elements from the top of the stack


static void stack_pop(Stack<Integer> stack) {
System.out.println("Pop Operation:");

for (int i = 0; i < 5; i++) {


Integer y = stack.pop();
System.out.println(y);
}
}

// Displaying the element on the top of the stack


static void stack_peek(Stack<Integer> stack) {
if (!stack.isEmpty()) {
Integer element = stack.peek();
System.out.println("Element on stack top: " + element);
} else {
System.out.println("Stack is empty");
}
}

// Searching element in the stack


static void stack_search(Stack<Integer> stack, int element) {
int pos = stack.search(element);

if (pos == -1)
System.out.println("Element not found");
else
System.out.println("Element is found at position: " + pos);
}

public static void main(String[] args) {


Stack<Integer> stack = new Stack<Integer>();

stack_push(stack); // Push elements 0 to 4 into the stack


stack_pop(stack); // Pop all elements from the stack
stack_push(stack); // Push elements 0 to 4 again into the stack
stack_peek(stack); // Peek at the top element of the stack
stack_search(stack, 2); // Search for element 2 in the stack
stack_search(stack, 6); // Search for element 6 in the stack
16
}
}

Output
Pop Operation:
4
3
2
1
0
Element on stack top: 4
Element is found at position: 3
Element not found

Result:

Thus the above program are executed successfully and output also verified.

17
EXNO:2b
Develop queued at a structures using classes and object
DATE:

AIM:

To write a java program for Develop queue data structures using classes and object.

ALGORITHMS:

1. Import the java packages.

2. An operation to insert an element in the queue is En queue

3. The operation to delete an element from the queue is De queue

4. This method returns the front of the queue.

5. This method traverses the queue and displays the elements of the queue.

6. Run the program.

7. Display the result.

8. Stop the program.

18
PROGRAM:
class Queue {
private int front, rear, capacity;
private int[] queue;

// Constructor to initialize the queue with the given size


Queue(int size) {
front = rear = 0;
capacity = size;
queue = new int[capacity];
}

// Insert an element into the queue


void queueEnqueue(int item) {
// Check if the queue is full
if (rear == capacity) {
System.out.println("\nQueue is full");
return;
}

// Insert element at the rear


queue[rear] = item;
rear++;
}

// Remove an element from the queue


void queueDequeue() {
// Check if the queue is empty
if (front == rear) {
System.out.println("\nQueue is empty");
return;
}

// Shift elements to the left by one position


for (int i = 0; i < rear - 1; i++) {
queue[i] = queue[i + 1];
}

// Set the last element to 0 (optional step, but keeps the queue clean)
if (rear < capacity) {
queue[rear - 1] = 0;
}

// Decrement rear
rear--;
}

// Display all elements of the queue


19
void queueDisplay() {
if (front == rear) {
System.out.println("Queue is empty");
return;
}

// Traverse from front to rear and print elements


for (int i = front; i < rear; i++) {
System.out.printf("%d, ", queue[i]);
}
System.out.println(); // For a clean line after the queue output
}

// Print the front element of the queue


void queueFront() {
if (front == rear) {
System.out.println("Queue is empty");
return;
}
System.out.printf("\nFront element of the queue: %d\n", queue[front]);
}
}

public class QueueArrayImplementation {


public static void main(String[] args) {
// Create a queue with a capacity of 4
Queue q = new Queue(4);

System.out.println("Initial Queue:");
// Print the queue elements
q.queueDisplay();

// Enqueue some elements


q.queueEnqueue(10);
q.queueEnqueue(20);
q.queueEnqueue(30);
q.queueEnqueue(40);

System.out.println("\nQueue after enqueuing 4 elements:");


q.queueDisplay();

// Try to enqueue one more element (this should print "Queue is full")
q.queueEnqueue(50);

// Dequeue an element
q.queueDequeue();
System.out.println("\nQueue after dequeue:");
q.queueDisplay();

20
// Print the front element of the queue
q.queueFront();
}
}

Output
Initial Queue:
Queue is empty

Queue after enqueuing 4 elements:


10, 20, 30, 40,

Queue is full

Queue after dequeue:


20, 30, 40,

Front element of the queue: 20

Result:

Thus the above program is executed successfully and output also verified.

21
EXNO:03
GENERATING EMPLOYEE PAYROLL DETAILS
DATE:

AIM:

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

AIGORITHM:

1. Create Package: Use package employee; to create a package.


2. Employee Class: Define Employee class with variables Emp_name, Emp_id, Address, Mail_id, Mobile_no.
3. Constructor & Display: Initialize variables via constructor and print details using display() method.
4. Subclasses: Create Programmer, AssistantProfessor, AssociateProfessor, and Professor extending
Employee.
5. Subclass Variables: Add bPay (basic pay) and des (designation) to each subclass.
6. Override paySlip: Calculate and display gross and net salary in overridden paySlip() method.
7. Initialize Parent Class: Use super() in subclasses to call Employee constructor.
8. Main Class: Import employee package and create Employee objects.
9. Store in ArrayList: Add employee objects to ArrayList<Employee>.
10. Display Pay Slips: Use displayEmployee() to print pay slips of all employees.

Program: import java.util.ArrayList;


import java.util.Scanner;

class Employee {
private String name;
private String id;
private String address;
private String mailId;
private String mobileNo;

// Constructor to initialize employee details


public Employee(String name, String id, String address, String mailId, String mobileNo) {
this.name = name;
this.id = id;
this.address = address;
this.mailId = mailId;
this.mobileNo = mobileNo;
}

// Display employee details


public void display() {
System.out.println("Emp_Name: " + name + "\t" + "Emp_id: " + id);
System.out.println("Address: " + address);
22
System.out.println("Mail_id: " + mailId + "\t" + "Mobile_no: " + mobileNo);
}

// Placeholder for pay slip method


public void paySlip() {
// To be overridden in subclasses
}
}

class Programmer extends Employee {


private float bPay;
private String des;

// Constructor to initialize programmer details


public Programmer(String name, String id, String address, String mailId, String mobileNo, float bPay,
String des) {
super(name, id, address, mailId, mobileNo);
this.bPay = bPay;
this.des = des;
}

// Override paySlip method to calculate pay slip for programmer


@Override
public void paySlip() {
float da = bPay * 97 / 100;
float hra = bPay * 10 / 100;
double grossSalary = bPay + da + hra;
float pf = bPay * 12 / 100;
double scf = bPay * 0.1 / 100;
double netSalary = grossSalary - pf - scf;

System.out.println("------------ Employee's Pay Slip -------------");


super.display();
System.out.println("Designation: " + des);
System.out.println("Basic_Pay: " + bPay);
System.out.println("Gross Salary: " + grossSalary + "\t" + "Net Salary: " + netSalary);
System.out.println("------------ End of the Statement -----------");
}
}

class AssistantProfessor extends Employee {


private float bPay;
private String des;

// Constructor to initialize assistant professor details


public AssistantProfessor(String name, String id, String address, String mailId, String mobileNo, float
bPay, String des) {
super(name, id, address, mailId, mobileNo);
this.bPay = bPay;
this.des = des;
}
23
// Override paySlip method to calculate pay slip for assistant professor
@Override
public void paySlip() {
float da = bPay * 97 / 100;
float hra = bPay * 10 / 100;
double grossSalary = bPay + da + hra;
float pf = bPay * 12 / 100;
double scf = bPay * 0.1 / 100;
double netSalary = grossSalary - pf - scf;

System.out.println("------------ Employee's Pay Slip -------------");


super.display();
System.out.println("Designation: " + des);
System.out.println("Basic_Pay: " + bPay);
System.out.println("Gross Salary: " + grossSalary + "\t" + "Net Salary: " + netSalary);
System.out.println("------------ End of the Statement -----------");
}
}

class AssociateProfessor extends Employee {


private float bPay;
private String des;

// Constructor to initialize associate professor details


public AssociateProfessor(String name, String id, String address, String mailId,
String mobileNo, float bPay, String des) {
super(name, id, address, mailId, mobileNo);
this.bPay = bPay;
this.des = des;
}

// Override paySlip method to calculate pay slip for associate professor


@Override
public void paySlip() {
float da = bPay * 97 / 100;
float hra = bPay * 10 / 100;
double grossSalary = bPay + da + hra;
float pf = bPay * 12 / 100;
double scf = bPay * 0.1 / 100;
double netSalary = grossSalary - pf - scf;

System.out.println("------------ Employee's Pay Slip -------------");


super.display();
System.out.println("Designation: " + des);
System.out.println("Basic_Pay: " + bPay);
System.out.println("Gross Salary: " + grossSalary + "\t" + "Net Salary: " + netSalary);
System.out.println("------------ End of the Statement -----------");
}
}

24
class Professor extends Employee {
private float bPay;
private String des;

// Constructor to initialize professor details


public Professor(String name, String id, String address, String mailId, String mobileNo,
float bPay, String des) {
super(name, id, address, mailId, mobileNo);
this.bPay = bPay;
this.des = des;
}

// Override paySlip method to calculate pay slip for professor


@Override
public void paySlip() {
float da = bPay * 97 / 100;
float hra = bPay * 10 / 100;
double grossSalary = bPay + da + hra;
float pf = bPay * 12 / 100;
double scf = bPay * 0.1 / 100;
double netSalary = grossSalary - pf - scf;

System.out.println("------------ Employee's Pay Slip -------------");


super.display();
System.out.println("Designation: " + des);
System.out.println("Basic_Pay: " + bPay);
System.out.println("Gross Salary: " + grossSalary + "\t" + "Net Salary: " + netSalary);
System.out.println("------------ End of the Statement -----------");
}
}

public class Emp {


Employee e;
ArrayList<Employee> obj = new ArrayList<>();
Scanner get = new Scanner(System.in);

// Method to add an employee based on user input


public void addEmployee() {
System.out.println("Enter the Emp_Name:");
String name = get.next();
System.out.println("Enter the Emp_id:");
String id = get.next();
System.out.println("Enter the Address:");
String address = get.next();
System.out.println("Enter the Mail_id:");
String mailId = get.next();
System.out.println("Enter the Mobile_no:");
String mobileNo = get.next();
System.out.println("Enter the Designation:");
String des = get.next();
System.out.println("Enter the Basic_Pay:");
25
float bPay = get.nextFloat();

// Depending on designation, instantiate the appropriate class


if (des.equalsIgnoreCase("Programmer")) {
e = new Programmer(name, id, address, mailId, mobileNo, bPay, des);
obj.add(e);
} else if (des.equalsIgnoreCase("AssistantProfessor")) {
e = new AssistantProfessor(name, id, address, mailId, mobileNo, bPay, des);
obj.add(e);
} else if (des.equalsIgnoreCase("AssociateProfessor")) {
e = new AssociateProfessor(name, id, address, mailId, mobileNo, bPay, des);
obj.add(e);
} else if (des.equalsIgnoreCase("Professor")) {
e = new Professor(name, id, address, mailId, mobileNo, bPay, des);
obj.add(e);
}
}

// Method to display pay slip of all employees


public void displayEmployee() {
for (Employee e : obj) {
e.paySlip();
}
}

// Main method to control the program flow


public static void main(String args[]) {
Emp x = new Emp();
String check;

// Loop to keep adding employees until the user opts to stop


do {
x.addEmployee();
System.out.println("Do you want to continue? Press 'y' to continue:");
check = x.get.next();
} while (check.equalsIgnoreCase("y"));

// Display pay slips of all added employees


x.displayEmployee();
}
}

26
Output

Enter the Emp_Name: John


Enter the Emp_id: 101
Enter the Address: 123 Main St
Enter the Mail_id: john.doe@example.com
Enter the Mobile_no: 9876543210
Enter the Designation: Programmer
Enter the Basic_Pay: 50000
Do you want to continue? Press 'y' to continue: y

Enter the Emp_Name: Alice


Enter the Emp_id: 102
Enter the Address: 456 Oak Rd
Enter the Mail_id: alice.smith@example.com
Enter the Mobile_no: 9876543211
Enter the Designation: AssistantProfessor
Enter the Basic_Pay: 60000
Do you want to continue? Press 'y' to continue: n

------------ Employee's Pay Slip -------------


Emp_Name: John Emp_id: 101
Address: 123 Main St
Mail_id: john.doe@example.com Mobile_no: 9876543210
Designation: Programmer
Basic_Pay: 50000.0
Gross Salary: 104850.0 Net Salary: 89980.0
------------ End of the Statement -----------

------------ Employee's Pay Slip -------------


Emp_Name: Alice Emp_id: 102
Address: 456 Oak Rd
Mail_id: alice.smith@example.com Mobile_no: 9876543211
Designation: AssistantProfessor
Basic_Pay: 60000.0
Gross Salary: 119400.0 Net Salary: 107940.0
------------ End of the Statement -----------

RESULT:

Thus the application for generating pay slips of employees with their gross and
net salary has been successfully executed.

27
EXNO:04
FINDING THE AREA OF DIFFERENT SHAPES
DATE:

AIM:

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

ALGORITHM:

1. Import the java packages.

2. . Create an abstract class named Shape that contains two integers and an empty method
named printArea().

3. 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.

4. 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

5. 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.

6. By using Scanner class get the input during runtime.

7. Create object for a class in memory and assign it to the reference variable, then the
method is invoked.

28
PROGRAM:

import java.util.Scanner;

// Abstract class Shape


abstract class Shape {
double a = 0.0, b = 0.0;

// Abstract method to print area


public abstract void printArea();
}

// Rectangle class extending Shape


class Rectangle extends Shape {
double area = 0.0;

@Override
public void printArea() {
System.out.println("----- Area of Rectangle -----");
Scanner in = new Scanner(System.in);
System.out.print("Enter the Width: ");
this.a = in.nextDouble();
System.out.print("Enter the Length: ");
this.b = in.nextDouble();
this.area = a * b; // Calculate area
System.out.println("The area of the rectangle is: " + this.area);
}
}

// Triangle class extending Shape


class Triangle extends Shape {
double area = 0.0;

@Override
public void printArea() {
System.out.println("----- Area of Triangle -----");
Scanner in = new Scanner(System.in);
System.out.print("Enter the Base: ");
this.a = in.nextDouble();
System.out.print("Enter the Height: ");
this.b = in.nextDouble();
this.area = 0.5 * a * b; // Calculate area
29
System.out.println("The area of the triangle is: " + this.area);
}
}

// Circle class extending Shape


class Circle extends Shape {
double area = 0.0;

@Override
public void printArea() {
System.out.println("----- Area of Circle -----");
Scanner in = new Scanner(System.in);
System.out.print("Enter the Radius: ");
this.a = in.nextDouble();
this.area = Math.PI * a * a; // Calculate area using Math.PI
System.out.println("The area of the circle is: " + this.area);
}
}

// Main class Area


public class Area {
public static void main(String[] args) {
System.out.println("----- Finding the Area of Shapes -----");

// Create a Shape reference and instantiate different shapes


Shape s;

// Rectangle
s = new Rectangle();
s.printArea();

// Triangle
s = new Triangle();
s.printArea();

// Circle
s = new Circle();
s.printArea();
}
}

30
Output
----- Finding the Area of Shapes -----
----- Area of Rectangle -----
Enter the Width: 5
Enter the Length: 10
The area of the rectangle is: 50.0

----- Area of Triangle -----


Enter the Base: 4
Enter the Height: 8
The area of the triangle is: 16.0

----- Area of Circle -----


Enter the Radius: 7
The area of the circle is: 153.93804002589985

RESULT:

Thus the Implementation for finding the area of different shapes using abstract class
has been successfully executed.
31
EXNO:05
SOLVE THE ABOVE PROBLEM USING AN INTERFACE
DATE:

AIM:

To write a java program for Solve the above problem using an interface.

ALGORITHM:

1. Import the java packages.


2. Design an interface for My Stack with functions push, pop and display.
3. Define a class Stack Array to implement the My Stack using array.
4. Define the functions of the interface accordingly and handle the stack overflow
and under flow exceptions.
5. Create a class and object for a class Stack Array in memory and assign it to
the reference variable, then the method is invoked.
6. By using Scanner class get the choices for switch statement during runtime.
7. By using switch case statement we can push ,pop and display thee elements for
each choice.

32
Program:
import java.io.*;

// Define the Vehicle interface


interface Vehicle {
// Abstract methods
void changeGear(int a);
void speedUp(int a);
void applyBrakes(int a);
}

// Bicycle class implementing the Vehicle interface


class Bicycle implements Vehicle {
int speed = 0;
int gear = 0;

// To change gear
@Override
public void changeGear(int newGear) {
gear = newGear;
}

// To increase speed
@Override
public void speedUp(int increment) {
speed += increment;
}

// To decrease speed
@Override
public void applyBrakes(int decrement) {
speed -= decrement;
}

// Method to print current state


public void printStates() {
System.out.println("Speed: " + speed + ", Gear: " + gear);
}
}

// Bike class implementing the Vehicle interface


class Bike implements Vehicle {
33
int speed = 0;
int gear = 0;

// To change gear
@Override
public void changeGear(int newGear) {
gear = newGear;
}

// To increase speed
@Override
public void speedUp(int increment) {
speed += increment;
}

// To decrease speed
@Override
public void applyBrakes(int decrement) {
speed -= decrement;
}

// Method to print current state


public void printStates() {
System.out.println("Speed: " + speed + ", Gear: " + gear);
}
}

// Main class GFG


class GFG {
public static void main(String[] args) {
// Creating an instance of Bicycle and performing operations
Bicycle bicycle = new Bicycle();
bicycle.changeGear(2);
bicycle.speedUp(3);
bicycle.applyBrakes(1);
System.out.println("Bicycle present state:");
bicycle.printStates();

// Creating an instance of Bike and performing operations


Bike bike = new Bike();
bike.changeGear(1);
bike.speedUp(4);
34
bike.applyBrakes(3);
System.out.println("Bike present state:");
bike.printStates();
}
}

Output

Bicycle present state:

Speed: 2, Gear: 2

Bike present state:

Speed: 1, Gear: 1

Result:

Thus the above program are executed successfully and output also verified.

35
EXNO:06 CREATING OWN EXCEPTIONS
DATE:

AIM:

To write a java program to implement user defined exception handling.

ALGORITHM:

1. Import the java packages.

2. Create a sub class of Exception named as My Exception it has only a


constructor plus an overloaded to String ( ) method that displays the value of
the exception.

3. The exception is thrown when compute()integer parameterisgreaterthan10.

4. 4.The main ( ) method sets up an exception handler for My Exception, then calls
compute()with a legal value (lessthan10) and an illegal one to show both paths
through the code.

36
PROGRAM:

// File Name should be UserException.java

import java.io.*;

// Define custom exception class


class MyException extends Exception {
private int d;

// Constructor to initialize the exception with a value


MyException(int a) {
d = a;
}

// Overriding toString() to customize exception message


@Override
public String toString() {
return "MyException[" + d + "]";
}
}

// Main class to demonstrate custom exception


class UserException {
// Method to compute and throw exception if `a > 10`
static void compute(int a) throws MyException {
System.out.println("Called compute(" + a + ")");
if (a > 10)
throw new MyException(a);
System.out.println("Normal Exit");
}

// Main method
public static void main(String[] args) {
try {
// Test compute method with different inputs
compute(1);
compute(20); // This will throw the exception
} catch (MyException e) {
System.out.println("Caught " + e); // Handle exception and print the message
37
}
}
}

Output
Called compute(1)
Normal Exit
Called compute(20)
Caught MyException[20]

RESULT:

ThustheImplementationforuserdefinedexceptionhandlinghasbeensuccessfully
executed.
38
EXNO: 07
DATE: MULTITHREADEDAPPLICATION

AIM:
Towriteaprogramthatimplementsamulti-threadedapplicationthathasthree
threads. First thread generates a random integer every 1 second and if the value is even, second
thread computes the square of the number and prints. If the value is odd, the third thread will
print the value of cube of the number.

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.

39
PROGRAM:

// File Name: Multithread.java


import java.util.Random;

class Even implements Runnable {


public int x;

public Even(int x) {
this.x = x;
}

public void run() {


System.out.println("New Thread " + x + " is EVEN and Square of " + x + " is: " + (x * x));
}
}

class Odd implements Runnable {


public int x;

public Odd(int x) {
this.x = x;
}

public void run() {


System.out.println("New Thread " + x + " is ODD and Cube of " + x + " is: " + (x * x * x));
}
}

class Generate extends Thread {


public void run() {
Random r = new Random();

try {
for (int i = 0; i < 5; i++) {
int num = r.nextInt(100);
System.out.println("Main Thread Generates Random Integer: " + num);

if (num % 2 == 0) {
Thread t1 = new Thread(new Even(num));
t1.start();
} else {
40
Thread t2 = new Thread(new Odd(num));
t2.start();
}

Thread.sleep(1000);
}
} catch (Exception ex) {
System.out.println("Exception: " + ex.getMessage());
}
}
}

public class Multithread {


public static void main(String[] args) {
Generate g = new Generate();
g.start();
}
}

Output
For example, suppose the generated random numbers are: 34, 17, 62, 89, and 12
The output might look like this:

Main Thread Generates Random Integer: 34


New Thread 34 is EVEN and Square of 34 is: 1156
Main Thread Generates Random Integer: 17
New Thread 17 is ODD and Cube of 17 is: 4913
Main Thread Generates Random Integer: 62
New Thread 62 is EVEN and Square of 62 is: 3844
Main Thread Generates Random Integer: 89
New Thread 89 is ODD and Cube of 89 is: 704969
Main Thread Generates Random Integer: 12
New Thread 12 is EVEN and Square of 12 is: 144

RESULT:

Thus the Implementation for application for multithreading has been successfully
executed.

41
EXNO:08
GETTING FILE OPERATIONS
DATE:

AIM:

To write a java program to implement file operations 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 methods else it
returns false.
10. The program uses conditional operator to check different functionalities of the given file.

42
PROGRAM:

// File Name should be FileOp.java


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

public class FileOp {


public static void main(String[] args) throws IOException {
Scanner in = new Scanner(System.in);

System.out.print("\nEnter the File Name: ");


String fName = in.next();
File f = new File(fName);

String result = f.exists() ? "exists." : "does not exist.";


System.out.println("\nThe given file " + fName + " " + result);
System.out.println("\nFile Location: " + f.getAbsolutePath());

if (f.exists()) {
result = f.canRead() ? "readable." : "not readable.";
System.out.println("\nThe file is " + result);

result = f.canWrite() ? "writable." : "not writable.";


System.out.println("\nThe file is " + result);

System.out.println("\nFile length is " + f.length() + " in bytes.");

if (fName.endsWith(".jpg") || fName.endsWith(".gif") || fName.endsWith(".png")) {


System.out.println("\nThe given file is an image file.");
} else if (fName.endsWith(".pdf")) {
System.out.println("\nThe given file is a portable document format.");
} else if (fName.endsWith(".txt")) {
System.out.println("\nThe given file is a text file.");
} else {
System.out.println("\nThe file type is unknown.");
}
}
}
}

43
Case 1: File Exists
Input : Enter the File Name: example.txt

Output : The given file example.txt exists.

File Location: C:\path\to\example.txt

The file is readable.


The file is writable.

File length is 1024 in bytes.

The given file is a text file.

Case 2: File Does Not Exist

Input
Enter the File Name: missingfile.txt
Output
The given file missingfile.txt does not exist.

File Location: C:\path\to\missingfile.txt

Case 3: File Exists but Type Unknown

Input
Enter the File Name: data.bin

Output
The given file data.bin exists.

File Location: C:\path\to\data.bin

The file is readable.


The file is writable.

File length is 2048 in bytes.

The file type is unknown.

44
RESULT:

Thus the Implementation for getting file information has been successfully executed.
45
EXNO:09
GENERIC CLASS
DATE:

AIM:

To write a java program for Develop applications to demonstrate the features of generics
classes.
ALGORITHM:

1. Import the java packages.


2. Import java util.Scanner.
3. Comparable interface is used to order the objects of user-defined class.
4. Java Generics allows us to create a single class , interface ,and method that can
be used with different types of data (objects).
5. Generics does not work with primitive types (int ,float ,char , etc ).
6. Run the program.
7. Display the result
8. Stop the program.

46
Program:
import java.util.Scanner;

class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

// Input for Integer


System.out.print("Enter an integer: ");
int intData = scanner.nextInt();
GenericsClass<Integer> intObj = new GenericsClass<>(intData);
System.out.println("Generic Class returns: " + intObj.getData());

// Input for String


System.out.print("Enter a string: ");
scanner.nextLine(); // Consume the newline
String stringData = scanner.nextLine();
GenericsClass<String> stringObj = new GenericsClass<>(stringData);
System.out.println("Generic Class returns: " + stringObj.getData());
}
}

// Create a generics class


class GenericsClass<T> {
// Variable of T type
private T data;

// Constructor
public GenericsClass(T data) {
this.data = data;
}

// Method that returns T type variable


public T getData() {
return this.data;
}
}

47
Input
Enter an integer: 42
Enter a string: Hello World

Output
Generic Class returns: 42
Generic Class returns: Hello World

RESULT:

Thus the Implementation for generic class has been successfully executed.
48
EXNO:10
DEVELOP APPLICATIONS USING JAVA FX CONTROLS,
DATE: LAYOUTS AND MENUS.

AIM:

To write a java program for Develop applications using JavaFX controls ,layouts
and menus.

ALGORITHM:

1. Import the java packages.


2. JavaFX provides a Menu class to implement menus.
3. Menu is the main component of a any application.
4. InJavaFX,javafx.scene.control.Menuclassprovidesallthemethodstodealwith
menus.
5. This class needs to be instantiated to create a Menu.
6. Run the program.
7. Display the result.
8. Stop the program.

49
Program:

package application;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;

public class MenuExample extends Application {


public static void main(String[] args) {
launch(args);
}

@Override
public void start(Stage primaryStage) throws Exception {
// Create a BorderPane as the root layout
BorderPane root = new BorderPane();
Scene scene = new Scene(root, 300, 200);

// Create a MenuBar
MenuBar menubar = new MenuBar();

// Create the File menu and its menu items


Menu fileMenu = new Menu("File");
MenuItem fileMenu1 = new MenuItem("New");
MenuItem fileMenu2 = new MenuItem("Save");
MenuItem fileMenu3 = new MenuItem("Exit");
fileMenu.getItems().addAll(fileMenu1, fileMenu2, fileMenu3);

// Create the Edit menu and its menu items


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);

50
// Add menus to the menu bar
menubar.getMenus().addAll(fileMenu, editMenu);

// Set the menu bar at the top of the BorderPane


root.setTop(menubar);

// Set up the Stage


primaryStage.setTitle("Menu Example");
primaryStage.setScene(scene);
primaryStage.show();
}
}

Output
Expected Output:

When you successfully run the program:

• A window titled "Menu Example" will open.


• It will contain a menu bar with:
o A File menu (New, Save, Exit items).
o An Edit menu (Cut, Copy, Paste items).

51
You can interact with these menus, but since no functionality has been implemented

for the menu items, they won't perform any actions yet.

52
Result:

Thus the above program are executed successfully and output also verified.

53
EXNO: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 actionlistener to the class datas.
3. Create the textfield for id, name and button for next, address and the panel.
4. Create object for the getcontentpane().
5. .Assign the length and breadth value for the layout using gridlayout
6. Add the new labels for ISBN and book name.
7. Add the new button for the nextbook
8. Create the bookname 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 showrecord.

54
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");

// Setting up the frame


Container c = getContentPane();
c.setLayout(new GridLayout(5, 1));

// Initializing components
id = new JTextField(20);
name = new JTextField(20);
next = new JButton("Next BOOK");
p = new JPanel();

// Adding components to the frame


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);

// Adding action listener to the button


next.addActionListener(this);

55
// Finalizing the frame
pack();
setVisible(true);
addWindowListener(new WIN());
}

public static void main(String args[]) {


Data d = new Data(); // Create instance of Data

try {
// Loading JDBC driver
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

// Establishing connection
conn = DriverManager.getConnection("jdbc:odbc:stu"); // DSN Name
stat = conn.createStatement();

// Executing query
res = stat.executeQuery("SELECT * FROM stu"); // Table name: stu
res.next(); // Moving to the first record
} catch (Exception e) {
System.out.println("Error: " + e);
}

// Displaying the first record


d.showRecord(res);
}

@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == next) {
try {
// Move to the next record
if (res.next()) {
showRecord(res);
} else {
JOptionPane.showMessageDialog(this, "No more records.", "End of records",
JOptionPane.INFORMATION_MESSAGE);
}
} catch (SQLException ex) {

56
System.out.println("Error while fetching next record: " + ex);
}
}
}

public void showRecord(ResultSet res) {


try {
// Displaying the record
id.setText(res.getString(1)); // Assuming 1st column is ISBN
name.setText(res.getString(2)); // Assuming 2nd column is Book Name
} catch (SQLException e) {
System.out.println("Error while displaying record: " + e);
}
}

// Inner class for window closing


class WIN extends WindowAdapter {
@Override
public void windowClosing(WindowEvent w) {
JOptionPane jop = new JOptionPane();
jop.showMessageDialog(null, "Thank you", "My Application",
JOptionPane.QUESTION_MESSAGE);
System.exit(0);
}
}
}

Output

When you run this program:

1. A window will pop up with fields for ISBN and Book Name.
2. It will initially display the first record from the database (stu table).
3. If you click the "Next BOOK" button, the program will fetch and display the next record from the database.
4. When you close the window, a thank-you message will appear.

57
RESULT:

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

58

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy