Está en la página 1de 10

Ex.

No:1 JAVA PACKAGE OF STACK AND QUEUE CLASS USING


JAVADOC

Date:

Aim

To develop a java package with simple stack and queue classes with java documentation
comments.

Algorithm

Step 1 : Start the program .

Step 2 : Create two packages Queue and Stack .

Step 3 : In Queue package , create a class which has member functions for

Insert, remove, peek front, is empty, is full and size.

Step 4 : In Stack package , create a class which has member functions for

Push, pop, seek ,is empty and is full .

Step 5 : In another file , import the packages Queue and Stack .

Step 6 : Create a class packagedemo which contains the main function .

Step 7 : Create instances of the classes Queue and Stack .

Step 8 : Maintain an array using Queue and Stack and access all the member

Functions of Queue and Stack class .

Step 9 : End the program .

Result:

Thus the package concept with stack and queue classes was executed .

Basic Arithmetic Operation on Complex Numbers

Ex.No:2

Date:

AIM:
To design a class for Complex numbers , to perform basic operations on complex numbers
and count the number of active objects created.

ALGORITHM :
Step 1 : Start the program .

Step 2 : Create a class Complex with member functions like toString ,

getimaginary , getreal , magnitude , add , subtract ,multiply , divide and equals .

Step 3 : Perform the addition , subtraction , multiplication and division of the two complex numbers in
the methods add , subtract ,multiply and divide.

Step 4 : In the main function , create two instances of the class Complex .

Step 5 : Initialize the values of the instances using the constructor .

Step 6 : Display the values stored in the two instances .

Step 7 : Invoke the various functions from the Complex class using the two

instances and perform the various operations on these instances .

Step 8 : Display the output of the various of the operations performed on the

Two instances .

Step 9 : Display the number of active objects created at the end of the program .

Step 10 : Stop the program .

Result:

Thus the class complex was designed and executed

Designing Date Class

Ex.No:3

Date:

Aim:

To design a date class provided in the utility package

Algorithm:

Step 1: start the program.

Step 2: define a userdefined class as name DateUtility by the keyword class.

Step 3: create an instance for an prediefined calendar class by importing


predefined package as

java.util.* and use the static method as getInstance().


Step 4: returns the date object equivalent to the time of the invoking
calendar object.getTime().

Step 5: print the current date and time.

Step 6: stop the program

Result:

Thus the date class was implemented using utility package.

Dynamic polymorphism

Ex.No:4

Date:

Aim:

To write a program to design geometric shapes using dynamic polymorphism.

ALGORITHM :

Step 1 : Start the program .

Step 2 : Declare a class named point and get the values of x and y coordinates .

Step 3 : Declare another class named Shape and define the output() and shape () Method .

Step 4 : Declare a class Square which extends Shape and displays the position Of the Square drawn .

Step 5 : Declare a class Rectangle which extends Shape and displays the

Position of the rectangle drawn .

Step 6 : Declare a class triangle which extends Shape and displays the vertices

Of the triangle drawn .

Step 7 : Declare a class circle which extends Shape and displays that the circle

Is drawn .

Step 8 : Declare a class Ellipses which extends Shape and displays that the

Ellipse is drawn .

Step 9 : In the main() method , create instances of the various classes like point,

Shape , Square , Rectangle , triangle ,Circle and Ellipses and invoke the
Display function .

Step 10 : Stop the program .

Result:

Thus geometric shapes was designed and executed using dynamic polymorphism.

IMPLEMENTATION OF INTERFACE FOR ADT STACK

Ex.No:5

Date:

Aim:

To design a class array and linked list which implements the interface ADT stack.

ALGORITHM :

Step 1 : Start the program .

Step 2 : Create an interface with functions for ADT Stack .

Step 3 : Create a class ArrayStack which implements the Stack interface.

Step 4 : In this class, declare methods isEmpty , push , pop ,peep and display for performing
various operations on array as stack .

Step 5 : Create a class ListNode that uses constructors to return the element of object .

Step 6 : Create a class ListStack that implements stack and has methods isEmpty , makeEmpty ,
push , pop , peep and display .

Step 7 : Declare the interface Stack and create a class Stack ArrayImp with main method that
immplements Array as Stack .

Step 8 : Stop the program .

Result:

Thus the interface ADT stack was implemented and executed successfully.

I/O Streams
Ex.No:6

Date:

Aim:

To write a program handling Input and output streams.

Algorithm

step 1: start the program.

Step 2: create a text file that contains DNA sequence as TATA.

Step 3: read the file using file reader class and count the number of TATA
count in each line.

Step 4: create the element array class.

Step 5: sort the TATA count based on the index value.

Step 6: call the filewriting class by passing the element object.

Step 7: read the maximum TATA count line in the input file and write into the
new file.

Step 8: stop the program

Result :

Thus the file is read and written using the I/O stream classes.

Simple paint program – Drawing different dimensions

Ex no:7

Date:

Aim:

To write a paint-like program that can draw basic graphical primitives in different dimensions
and color.

Algorithm:

Step 1: start the program.

Step 2: import GUI packages and utility package.


Step 3: declare class shapedraw extends JApplet.

Step 4: initialize the applet using init() method and insert the applet code.

Step 4: create the instance for GUI components and add to the content panel.

Step 5: create a class shapecanvas which implements ActionListener, MouseListener,


MouseMotionListner.
Step 6: use Paintcomponent, actionPerformed, mouseDragged, mouseMoved ,
mouseReleased methods to generate the GUI actions.
Step 7: create a class for RectShape, RoundRectShape, OvalShape with necessary
methods to draw the shapes.
Step 8: using actionPerformed method the event object is handled generated by the event
source.
Step 9: stop the program.

Result:

Thus the different dimensions are drawn and successfully executed using GUI.

Scientific calculator using event- driven program

Ex no: 8

Date:

Aim:

To develop a scientific calculator using even-driven programming paradigm.

Algorithm.

Step 1: start the program

Step 2: create a class calculator implementing ActionListener Interface.


Step 3: declare the GUI component classes.

Step 4: create an object for menu, menubar and checkboxes.

Step 5: set the LayoutManager class to position the components.

Step 6: initialize the number from 1to 9 using Button class.

Step 7: create a class implements listener interface and override the


actionperformed method.

Step 8: using actionperformed method the event object is handled generated


by event source.

Step 9: stop the program.

Result:

Thus the scientific calculator was developed and executed.

Template for linked-list

Ex no:9

Date:

Aim:

To develop a template for linked-list along with its method.

Algorithm:

Step 1: start the program

Step 2: create the template as mountain class and initialize the string value
and integer in mountain constructor.

Step 3: use the template in the class linkedlist.

Step 4: add the elements in linkedlist by method add(),addfirst(),addlast().

Step 5: remove the elements using remove(), removefirst(), removelast()


Step 6: sort the elements using sort method based on the data members in
the object.

Step 7: stop the program

Result:

Thus the template for linked list was executed.

Thread-safe implementation

Ex no:10

Date:

Aim:

To write a multi-threaded producer-consumer application.

Algorithm:

Step 1: start the program.

Step 2: create a class thread with synchronized methods.

Step 3: declare a class producer and consumer implementing Runnable interface.

Step 4: Declare a class ThreadSafe .

Step 5: create a thread object.

Step 6: pass the thread object to the producer, consumer constructor and implement the thread-
safe .

Step 7: stop the program.

Result:

Thus the program was executed using Multi-threaded application.

Multi-threaded application

Ex no:11

Date:
Aim:

To write a program that generates prime and Fibonacci number using thread concept.

Algorithm

Step 1: start the program

Step 2: declare the class FibMaker extends thread to generate the Fibonacci
numbers below

100,000 using run method.

Step 3: declare the class primemaker extends thread to generate the prime
numbers below

100,000 using run method.

Step 4: declare the DataOutputStream as object in FibMaker and Primemaker


class.

Step 4: create a class pipetest.

Step 5: call the start method of makefis method. The start method inturn
calls the run method to generate the Fibonacci numbers.

Step 6: call the start method of makeprime method. The start method inturn
calls the run method to generate the prime numbers.

Step 7: print the generated Fibonacci and prime numbers.

Step 8: stop the program

Result:

Thus the program generates prime and Fibonacci number and executed successfully.

Multi-threaded GUI applications

Ex no:12

Date:
Aim:

To develop a multi-threaded GUI applications.

Algorithm:

Step 1: start the program.

Step 2: create a class ApplicantApplet which extends JApplet and


implementing Runnable and declare the GUI component classes.

Step 3: start the applet program with the init() method.

Step 4: create a thread object and GUI component objects to get the input.

Step 5: the start method inturn calls the run method to print the current
date.

Step 6: stop the program.

Result:

Thus the multi-threaded GUI applications was developed and executed

También podría gustarte