0% found this document useful (0 votes)
19 views

Oops Lab Manual

Uploaded by

jenishton7
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Oops Lab Manual

Uploaded by

jenishton7
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

EX.

NO:1 SEARCHING AND SORTING ALGORITHM

Solve problems by using sequential search, binary search, and quadratic sorting algorithms

(selection, insertion)

1A) SEQUENTIAL OR LINEAR SEARCH

Aim: To search the given elements using sequential search

PROCEDURE
Step 1: Traverse the array

Step 2: Match the key element with array element

Step 3: If key element is found, return the index position of the array element

Step 4: If key element is not found, return -1

1B) BINARY SEARCH

Aim: To search the given elements using binary search

PROCEDURE
Step 1: Calculate the mid element of the collection.
Step 2: Compare the key items with the mid element.
Step 3: If key = middle element, then we return the mid index position for the key
found.
Step 4: Else If key > mid element, then the key lies in the right half of the collection.
thus repeat steps 1 to 3 on the lower (right) half of the collection.
Step 5: Else key < mid element, then the key is in the upper half of the collection. To
repeat the binary search in the upper half.
1C) SELECTION SORTING

Aim: To sort the given elements using selection sorting algorithm

PROCEDURE

Step 1 - Select the first element of the list (i.e., Element at first position in the list).
Step 2: Compare the selected element with all the other elements in the list.
Step 3: In every comparison, if any element is found smaller than the selected
element (for Ascending order), then both are swapped.
Step 4: Repeat the same procedure with element in the next position in the list till the
entire list is sorted

1D) INSERTION SORT

Aim: To sort the given elements using Insertion sorting algorithm

PROCEDURE

Step 1 - Assume that first element in the list is in sorted portion and all the
remaining elements are in unsorted portion.
Step 2: Take first element from the unsorted portion and insert that element into the
sorted portion in the order specified.
Step 3: Repeat the above process until all the elements from the unsorted portion are
moved into the sorted portion.

RESULT:
Thus a java program for sorting and searching algorithms was implemented and executed
successfully.
EX.NO:2 STACKS AND QUEUE

Develop stack and queue data structures using classes and objects

2A) IMPLEMENTATION OF STACK


AIM: The JAVA Program is written for implementation of STACK using Array.

PROCEDURE
There are some basic operations that allow us to perform different actions on a stack.

Push: Add an element to the top of a stack


Pop: Remove an element from the top of a stack
IsEmpty: Check if the stack is empty
IsFull: Check if the stack is full
Peek: Get the value of the top element without removing it

The process of putting a new data element onto stack is known as a Push Operation. Push
operation involves a series of steps −

Step 1 − Checks if the stack is full.


Step 2 − If the stack is full, produces an error and exit.
Step 3 − If the stack is not full, increments top to point next empty space.
Step 4 − Adds data element to the stack location, where top is pointing.
Step 5 − Returns success.

A Pop operation may involve the following steps −

Step 1 − Checks if the stack is empty.


Step 2 − If the stack is empty, produces an error and exit.
Step 3 − If the stack is not empty, accesses the data element at which top is
pointing.
Step 4 − Decreases the value of top by 1.
Step 5 − Returns success.
2B) IMPLEMENTATION OF QUEUE
AIM: The JAVA Program is written for implementation of QUEUE using Array.

PROCEDURE
enqueue () − add (store) an item to the queue.
dequeue () − remove (access) an item from the queue.

To enqueue (insert) data into a queue −

Step 1 − Check if the queue is full.


Step 2 − If the queue is full, produce overflow error and exit.
Step 3 − If the queue is not full, increment rear pointer to point the next empty
space.
Step 4 − Add data element to the queue location, where the rear is pointing.
Step 5 − return success.

To perform dequeue operation −

Step 1 − Check if the queue is empty.


Step 2 − If the queue is empty, produce underflow error and exit.
Step 3 − If the queue is not empty, access the data where front is pointing.
Step 4 − Increment front pointer to point to the next available data element.
Step 5 − Return success.

RESULT

Thus a java program for stack and queue was implemented and executed successfully.
EX NO: 3 PROGRAM TO GENERATE PAYSLIP USING INHERITANCE

AIM
To develop a java application to generate pay slip for different category of employees using
the concept of inheritance.

PROCEDURE

1. Create the class employee with name, Empid, address, mailed, mobile no as members.
2. Inherit the classes programmer, asstprofessor, associateprofessor and professor from
employee class.
3. Add Basic Pay (BP) as the member of all the inherited classes.
4. Calculate DA as 97% of BP, HRA as 10% of BP, PF as 12% of BP, Staff club fund as
0.1% of BP.
5. Calculate gross salary and net salary.
6. Generate payslip for all categories of employees.
7. Create the objects for the inherited classes and invoke the necessary methods to display the
Payslip.

RESULT
Thus the java application to generate pay slip for different category of employees was
implemented using inheritance and the program was executed successfully.
EX NO: 4 CALCULATE AREA USING ABSTRACT CLASS

AIM

To write a java program to calculate the area of rectangle, circle and triangle using the
concept of abstract class.

PROCEDURE

1. Create an abstract class named shape that contains two integers and an empty method
named printarea().

2. Provide three classes named rectangle, triangle and circle such that each one of the classes
extends the class Shape.

3.Each of the inherited class from shape class should provide the implementation for the
method printarea().

4. Get the input and calculate the area of rectangle,circle and triangle .

5. In the shapeclass , create the objects for the three inherited classes and invoke the methods
and display the area values of the different shapes.

RESULT

Thus a java program for calculate the area of rectangle, circle and triangle was implemented
and executed successfully.
EX NO: 5 CALCULATE AREA USING INTERFACE

AIM

To write a java program to calculate the area of rectangle, circle and triangle using the
concept interface.

PROCEDURE

1. Create an interface named shape that contains empty method named printarea().

2. Provide three classes named rectangle, triangle and circle such that each one of the classes
implements interface Shape.

3.Each of the implemented class from shape interface should provide the implementation for
the method printarea().

4. Get the input and calculate the area of rectangle,circle and triangle .

5. In the shapeclass , create the objects for the three inherited classes and invoke the methods
and display the area values of the different shapes.

RESULT

Thus a java program for calculate the area of rectangle, circle and triangle using interface
was implemented and executed successfully.
EX NO: 6 Exception handling and creation of user defined exceptions

6A: MULTIPLE CATCH BLOCK IN EXCEPTION HANDLING

AIM
To write a java program to implement multiple catch block in exception handling

ALGORITHM
1. First, the code in try {...} is executed.
2. If there were no errors, then catch (err) is ignored: the execution reaches the end
of try and goes on, skipping catch.
3. If an error occurs, then the try execution is stopped, and control flows to the
beginning of catch (err).
4. For each try block, there can be zero or more catch blocks. Multiple catch blocks
allow us to handle each exception differently.
5. The exception is thrown to the first catch block. The first catch block does not handle
that exception, so it is passed to the next catch block.
6. The second catch block is the appropriate exception handler then it handles
an exception and executed.
6B: USER DEFINED EXCEPTION IN EXCEPTION HANDLING

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

ALGORITHM
1. Create a class which extends Exception class.
2. Create a constructor which receives the string as argument.
3. Get the Amount as input from the user.
4. If the amount is negative, the exception will be generated.
5. Using the exception handling mechanism, the thrown exception is handled by the catch
construct.
6. After the exception is handled, the string “invalid amount “ will be displayed.
7. If the amount is greater than 0, the message “Amount Deposited “will be displayed

RESULT

Thus a java program for exception handling application has been implemented and executed
successfully.
EX.NO:7 MULTITHREADED APPLICATION

AIM

To write a java program that implements a multi-threaded application .

ALGORITHM

STEP 1.Create a class even which implements first thread that computes .the square of the
number .

STEP 2. run () method implements the code to be executed when thread gets executed.

STEP 3. Create a class odd which implements second thread that computes the cube of the
number.

STEP 4.Create a third thread that generates random number. If the random number is even , it
displays the square of the number. If the random number generated is odd , it displays the
cube of the given number .

STEP 5.The Multithreading is performed and the task switched between multiple threads.

STEP 6.The sleep () method makes the thread to suspend for the specified time.

RESULT

Thus a java program for multi-threaded application has been implemented and executed
successfully.
EX.NO:8 GETTING FILE INFORMATION

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, orwritable, 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.

RESULT:
Thus the Implementation for getting file information has been successfully executed.
EX.NO:9 GENERIC PROGRAMMING

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
elementswith 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
compilerhandles each method.

RESULT:

Thus the Implementation for finding the maximum value from the given
type ofelements using a generic function has been successfully executed.
EX.NO:10

Creating a registration form in JavaFX

1. From the File menu, choose New Project.

2. In the JavaFX application category, choose JavaFX Application. Click Next.

3. Name the project Login and click Finish.

4. For the login form, use a GridPane layout to create the GridPane layout

5. Add Text, Labels, and Text Fields on the layout- The grid.add() method adds
the scenetitle variable to the layout grid. The numbering for columns and rows in the grid
starts at zero, and scenetitle is added in column 0, row 0. The last two arguments of
the grid.add() method set the column span to 2 and the row span to 1.

6. Add a Button and Text

A Button control for submitting the data and a Text control for displaying a message
when the user presses the button.

7. Add Code to Handle an Event-

The setOnAction() method is used to register an event handler that sets


the actiontarget object to Sign in button pressed when the user presses the button. The
color of the actiontarget object is set to firebrick red

RESULT:
Thus the registration form was created using javaFx controls, menus and layout and it has been
successfully executed.
Ex. No.: 11 LIBRARY MANAGEMENT SYSTEM

Aim
To design a library management system using Java.

Hardware Requirements:
Pentium IV with 2 GB RAM
160 GB HARD Disk
Monitor 1024 x 768 colour

Software Requirements:
WINDOWS 10 operating system
JDK 1.8
Notepad
Internet Explorer 4.0

Procedure:
1. Start the program
2. Using the swing components design the necessary layout
3. Add the details using JDBC (Java Data Base Connectivity).
4. Get the details from the user
5. Store it in the database and do the necessary manipulations.
6. Stop the program

You might also like