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

aim algorithm for oops manuval

The document outlines various Java programming exercises, including implementations of sequential and binary search algorithms, quadratic sorting algorithms, stack and queue data structures, employee payroll generation, area calculation for different shapes using abstract classes and interfaces, user-defined exceptions, multi-threaded applications, file operations, generics, JavaFX applications, and a mini project for an OPAC system. Each exercise includes an aim and a detailed algorithm for implementation. The content serves as a comprehensive guide for learning and applying Java programming concepts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

aim algorithm for oops manuval

The document outlines various Java programming exercises, including implementations of sequential and binary search algorithms, quadratic sorting algorithms, stack and queue data structures, employee payroll generation, area calculation for different shapes using abstract classes and interfaces, user-defined exceptions, multi-threaded applications, file operations, generics, JavaFX applications, and a mini project for an OPAC system. Each exercise includes an aim and a detailed algorithm for implementation. The content serves as a comprehensive guide for learning and applying Java programming concepts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Ex.

No:1A
IMPLEMENTATION OF SEQUENTIAL
Date:
SEARCH
Aim:
Aim is to write a program in java to solve problems by using
sequential search.

Algorithm:
1. Read the search element from the user

2. Compare, the search element with the first element in the list.

3. If both are matching, then display "Given element found!!!"


and terminate the function

4. If both are not matching, then compare search element with


the next element in the list.
5. Repeat steps 3 and 4 until the search element is compared
with the last element in the list.

6. If the last element in the list is also doesn't match, then


display "Element not found!!!" and terminate the function.
IMPLEMENTATION OF BINARY SEARCH
Ex. No:1B
Date:
Aim:
Aim is to write a program in java to solve problems by using
binary search.

Algorithm:

1. Read the search element from the user

2. Find the middle element in the sorted list

3. Compare, the search element with the middle element in the sorted
list.

4. If both are matching, then display "Given element found!!!" and


terminate the function

5. If both are not matching, then check whether the search element is
smaller or larger than middle element.

6. If the search element is smaller than middle element, then repeat


steps 2, 3, 4 and 5 for the left sublist of the middle element.
7. If the search element is larger than middle element, then repeat steps
2, 3, 4 and 5 for the right sub list of the middle element.

8. Repeat the same process until we find the search element in the list
or until sublist contains only one element.
Ex. No:1C IMPLEMENTATION OF QUADRATIC
Date: SORTING ALGORITHMS (SELECTION,
INSERTION)

Aim:
To write a java program for implementation of quadratic sorting
algorithms (selection,insertion)

Algorithm:

Selection sort:
1. Set the first element as minimum.
2. Compare minimum with the second element. If the second
element is smaller than minimum, assign the second
element as minimum.
3. Compare minimum with the third element. Again, if the
third element is smaller, then assign minimum to the third
element otherwise do nothing. The process goes on until
the last
4. After each iteration , minimum is placed in the front of the
unsorted list element.
5. Each iteration , indexing starts from the first unsorted
element. Steps 1 to 4 are repeated until all the elements are
placed at their correct positions.
Insertion sort:
1. The first element in the array is assumed to be sorted.
Take the second element and store it separately in key.
2. Compare key with the first element. If the first element is
greater than key, then key is placed in front of the first
element.
3. Now, the first two elements are sorted.
4. Take the third element and compare it with the elements
on the left of it. Placed it just behind the element smaller
than it. If there is no element smaller than it, then place it
at the beginning of the array.
5. Similarly, place every unsorted element at its correct
position.
Ex. No:2 IMPLEMENT STACK AND QUEUE DATA
Date: STRUCTURES USING CLASSES AND
OBJECTS.

Aim:
To implement the stack and queue data structures using classes and
objects.

Algorithm:

Stack data structures:


1. A pointer called TOP is used to keep track of the top element in the
stack.
2. When initializing the stack, we set its value to -1 so that we can check if
the stack is empty by comparing TOP == -1.
3. On pushing an element, we increase the value of TOP and place the new
element in the position pointed to by TOP.
4. On popping an element, we return the element pointed to by TOP and
reduce its value.
5. Before pushing, we check if the stack is already full
6. Before popping, we check if the stack is already empty
Queue data structures:

1.Each node in the queue contains data and link to the next node.
Front and rear pointer points to first and last node inserted in the queue.

2. The operations on the queue are


a. INSERT data into the queue
b. DELETE data out of queue
3. INSERT DATA INTO queue
a. Enter the data to be inserted into queue.
b. If TOP is NULL
i. The input data is the first node in queue.
ii.The link of the node is NULL.
iii. TOP points to that node. c. If
TOP is NOT NULL
i. The link of TOP points to the new node.
ii. TOP points to that node.

4. DELETE DATA FROM queue a. If


TOP is NULL
i. the queue is empty b. If
TOP is NOT NULL
i. The link of TOP is the current TOP.
ii. The pervious TOP is popped from queue.
5. The queue represented by linked list is traversed to display its
content.
GENERATING EMPLOYEE
Ex. No:3 PAYROLL DETAILS
Date:
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
Ex. No:4 FINDING THE AREA OF DIFFERENT
Date: SHAPES

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.
Ex. No:5 FINDING THE AREA OF
Date: DIFFERENT SHAPES BY
USING INTERFACE

Aim:
To write a java program to find the area of different shapes by using
interface

Algorithm:

1. Start
2. Create an interface named area that contains two double
values and initializes the pi value as 3.14.
3. Create a class triangle that implements the interface area for
getting base and height values then compute the area and
prints the area of the triangle by using the main method.
4. Create a class rectangle that implements the interface area for
getting length and breathe values then compute the area and
prints the area of the triangle by using the main method.
5. Create a class circle that implements the interface area for
getting radius and compute the area and prints the area of the
circle by using the main method.
6. Create object for a class in memory and assign it to the
reference variable, then the main method is invoked.
7. Stop.
Ex. No:6 CREATING OWN
Date: EXCEPTIONS

AIM:

To write a java program to implement user defined exception


handling.

ALGORITHM:

1. Import the java packages.


2. Create a subclass of Exception named as MyException it has only
a constructor plus an overloaded toString ( ) method that displays
the value of the exception.
3. The exception is thrown when compute ( ) integer parameter is
greater than 10.
4. The main ( ) method sets up an exception handler for
MyException, then calls compute ( ) with a legal value (less than
10) and an illegal one to show both paths through the code.
Ex. No:7 MULTI THREADED
Date: APPLICATION

AIM:

To write a 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, 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.
8. Wait for 1 Second and Continue to Step 3 until user wants to
exits.
Ex. No:8
IMPLEMENT THE FILE OPERATIONS
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.

Ex. No:9
IMPLEMENT THE FEATURES OF
Date: GENERICS CLASSES

AIM:

To write a java program to find the maximum value from the


given type of element 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.

Ex. No:10
Date: Develop applications using JavaFX controls,
layouts and menus.

Aim:
To develop applications using javafx controls, layouts and menus.
Algorithm:
1. A menu is a list of options or commands presented to the user,
typically menus contain items that perform some action.
2. The contents of a menu are known as menu items and a menu
bar holds multiple menus.
3. You can create a menu by instantiating
the javafx.scene.control.Menu class.
4. Adding sub menus in a layout.
5. To create a menu –Instantiate the Menu class,Create a required
number of menu items by instantiating the MenuItem class,Add
the created menu items to the observable list of the menu.
6. To add sub-menu, you just need to add a menu to another menu.

Ex. No:11
Date:
MINI PROJECT - OPAC
SYSTEM

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.

You might also like