Oops Lab Manual
Oops Lab Manual
Solve problems by using sequential search, binary search, and quadratic sorting algorithms
(selection, insertion)
PROCEDURE
Step 1: Traverse the array
Step 3: If key element is found, return the index position of the array element
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
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
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
PROCEDURE
There are some basic operations that allow us to perform different actions on a stack.
The process of putting a new data element onto stack is known as a Push Operation. Push
operation involves a series of steps −
PROCEDURE
enqueue () − add (store) an item to the queue.
dequeue () − remove (access) an item from the queue.
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
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
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:
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:
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
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.
A Button control for submitting the data and a Text control for displaying a message
when the user presses the button.
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