Sunteți pe pagina 1din 5

Ex.

No:1 JAVA PACKAGE WITH SIMPLE STACK AND QUEUE CLASS


AIM:
To write program to develop a java package for the stack and queue classes.
ALGORITHM:
Stack class:
1. Start the program.
2. Create a class with the class name Stack to demonstrate the application of the stack.
3. Create a constructor to initialize the top value of the stack.
4. Define the method push ().
5. If the top value is equal to 9, print stack is full. Otherwise push the value in to the stack.
6. Define the method pop ().
7. If the top value is less than zero, print stack underflow. Otherwise decrement the value of
the stack.
8. Create a main class with the class name teststack.
9. Create an object for the class Stack to call the methods define inside that class.
10. Call the methods push () & pop () using the objects.
Queue class:
1. Start the program.
2. Create a class with the name queue implement to demonstrate about a application of
queue.
3. Declare a variable str as string and num as integer.
4. Create an object for a class queue implement.
5. Create a constructor to of the Linked List class. This class is used by importing
the java.util. package. This constructor is used for constructing an empty list.
6. Get the value from the command line by using a variable str.
7. Using try and catch block to handle exception using IOException.
8. Print the elements in the queue using the statement.
Result:
Thus the Stack and queue program was compiled and executed successfully
Ex.No:2 COMPLEX NUMBER MANIPULATION
AIM:
To write a program to perform addition, subtraction, multiplication in complex numbers using
constructors.
ALGORITHM:
1: Start the program.
2: Create a class with a class name Complex Number.
3: Create a constructor with the arguments a and b with integer data type.
4: Define a method getcomplexvalue( ) to get the values of a and b.
5: Define static method named as addition, subtraction,multiplication to perform particular function
defined inside the method.
6: Create an object for the class Complex Number and pass the values in the argument list.
7: Call the method by using object to get the values.
8: Print the result.
9: Stop the program.
Result:
Thus the complex number program was executed and compiled successfully.
Ex.No:3 DATE CLASS SIMILAR TO JAVA.UTIL PACKAGE
AIM:
To write a java program to display the dates of before and after days for a given date.
ALGORITHM:
1. Start the program.

2. Create a class with name Date

3. Declare the variables month, day, year as private and create constructor with arguments.

4. Check the condition for exception. If the date is valid, It will proceed the program otherwise
display the exception Invalid.
5. Use Boolean type for method to return the values as either true or false.

6. Check the values for month and values for day using if loops.

7. Check the year using if loop whether it is leap year or not.

8. Define methods isAfter() and isBefore() in program.

9. Define method compareTo() to compare the date.

10. In main() create object today and give current date as value for constructor fields

11. Call the all methods to display the dates.


Result:
Thus the Date class program was compiled and executed successfully.
Ex.No:4 IMPLEMENTING DYNAMIC POLYMORPHISM IN JAVA
AIM:
To write a java program for abstract class to find areas of different shapes.
ALGORITHM:
1. Start the program.

2. Create an abstract class with class name Shape.

3. Create a constructor with arguments and declare variables dim1, dim2 and PI.

4. Declare an abstract method area() inside the class.

5. Create the classes Rectangle, Triangle, Circle, and Ellipse to find the area.

6. Define abstract method area() inside the subclasses and call the constructor of class Shape using
super keyword.

7. In main(), create the objects for all classes and pass values to fields of constructors.

8. Create a reference variable figuref for abstract class.

9. Using reference variable of class Shape, call the method area() of all subclasses

10. Print the areas for all shapes.

11. Stop the program.


Result:
Thus the Dynamic polymorphism was compiled and executed successfully.
Ex.No:5 JAVA INTERFACE FOR ADT STACK
AIM:
To write the java program for ADT stack using interface.
ALGORITHM:
1: Start the program
2: Create an interface which consists of three methods namely PUSH, POP and DISPLAY
3: Create a class which implements the above interface to implement the concept of stack through
Array
4: Define all the methods of the interface to push any element, to pop the to element and to display the
elements present in the stack.
5: Create another class which implements the same interface to implement the concept of stack
through linked list.
6: Repeat STEP 4 for the above said class also.
7: In the main class, get the choice from the user to choose whether array implementation or linked
list implementation of the stack.
8: Call the methods appropriately according to the choices madeby the user in the previous step.
9: Repeat step 6 and step 7 until the user stops his/her execution
10: Stop the program
Result:
Thus the Interface for ADT stack program was compiled and executed successfully.
Ex. No: 6 DNA FILE CREATION
AIM
To write a Java program to read a file that contains DNA sequences of arbitrary length
one per line ,sort the sequences in descending order with respect to the number of 'TATA'
subsequences present and finally write the sequences in sorted order into another file.
ALGORITHM:
1. Start
2. Create an input text file DNA.txt and add the sequence as needed.
3. Read each line from the file to a string array.
4. Count the number of TATA sequence in each line and store the count in another array.
5. Arrange the data in the count array in descending order and also arrange the data in the

string array in parallel with the count array.


6. Write the sorted DNA sequence to the output file File.txt
7. View the output file.
8. Stop.
Result:
Thus the DNA sequences were read sorted and output was given to an output file.
Ex.No:7 DEVELOPING A SIMPLE PAINT LIKE PROGRAM USING APPLET
AIM:
To develop a simple paint like program using applet in java.
ALGORITHM:
1. Import the required class and packages.

2. Create a class Drawtest for creating an applet.

3. Initialize panels and controls in the init() method.

4. Define the destroy() method to destroy the same.

5. Create an instance for draw test class and call the init(0 and start() methods in the main method.

6. Add a new frame to the applet window and resize it to 300x300.

7. Declare a method get applet infor to display the applet information.

8. Declare two constants LINES,POINTS which are going to be the modes.

9. Define the paint method and perform the required operations.

10. Display the result according to the mode selected.


Result:
Thus the Applet-Paint program was compiled and executed successfully.
Ex.No:8 DEVELOPING A SCIENTIFIC CALCULATOR
AIM:
To develop a scientific calculator in java.
ALGORITHM:
1. Import the necessary packages.

2. Create a class calculator JFrame class and ActionListener interface.

3. Create a new font using String name,int style,int size).


4. Set up the JMenu bar and add Mnemenics to them by using setMnemonic() method.

5. Set the frame layout for the applet and set the background color to gray using setBackground()
method .

6. Create a container using JPanel().

7. Create numeric JButtons for operators and numbers using JButtons().

8. Set all the Numbered JButtons to blue .the rest to red usig setForeGround() method.

9. Declare the method getNumberInDisplay() to get by the calculator.

10. Use display result to display the method.

11. Declare the main function and create the instance for calculator and set the attributes
setTitle(),setSize(),setResizable().

12. Stop the program.


Result:
Thus the Scientific calculator program was compiled and executed successfully.
Ex.No:9 DEVELOPING A TEMPLATE FOR LINKED LIST
AIM:
To develop a template for linked list in java.
ALGORITHM:
1. Import the necessary packages.

2. Declare the main function within the class Linked list demo.

3. Insert items in to the list using add() method use addLast() to insert at the end.

4. Display the contents of the lists.

5. Use remove() method to declare a specific element.

6. Use remove() first(0,removeLast() to delete the element at the first and at the last.

7. Display the list and handle the exceptions.


Result:
Thus the Linked list program was compiled and executed successfully
Ex.No:10 DEVELOP A MULTI THREADED PRODUCER CONSUMER APPLICATION
AIM:
To develop a multithreaded producer and consumer application in java.
ALGORITHM:
1. Import the necessary packages.

2. Create two threads producer and consumer.

3. Declare a constant MAXQUEUE in producer thread.

4. Create an instance for vector named messages to implement a queue.

5. In the run() method of producer thread put the messages on the queue using putmessages() and
suspend the thread for one sec using sleep(1000).

6. Declare the getmessage() method and ceck whether there is any message if no wait for one.

7. After receiving the message remove the message and return it.
8. Create a constructor to assign values to them.

9. In the run method of consumer class call the getmessage() method of producer thread and print the
message.

10. Suspend the thread for 2 sec using sleep(2000).

11. Create two instances with different name for consumer thread.

12. Display the message.


Result:
Thus the Multithreaded program was compiled and executed successfully.
Ex.No:11 GENERATING PRIME NUMBERS AND FIBONACCI SERIES
AIM:
To generate prime numbers and fibonacci series using java.
ALGORITHM:
1. Import the necessary packages.

2. Create tow threads MyThread1 and MyThread2.

3. In MyThread1 create instances for piped reader and piped writer.

4. Create a constructor and assign values to them.

5. In mythread2 create instances for pipedreader and piped writer.

6. Create a constructor and assign values to them.

7. Declare a class Multithreaded programming and create two list using ArrayList.

8. Create instances for pipedreader and pipedwriter prl and pwl respectively.

9. Get the Fibonacci series from the stream pr2 and store them in lsit2 by using retainAll() method and
print them.
Result:
Thus the program was compiled and executed successfully.
Ex.No:12 MULTITHREADED GUI APPLICATION
AIM:
To develop a multithreaded GUI application in java.
ALGORITHM:
1. Create the class ball which implements a ball which moves and bounces of the edges of a rectangle.

2. Using the move() method move the ball to the nect postion by reversing the direction if it bits one
of the edges.

3. Get the shapes of the ball at its current position.


4. Invoke the runnable() method to show the animated bouncing balls.
5. Using the sleep() method assign the time for ball to bounce in a given interval of time.
6. Construct the frame with the component for showing bouncing ball and start and close buttons.
7. Add the thread to the frame and button to the container.
8. Create a constructor to assign values to them.

9. Add a bouncing ball to the canvas and starts a thread to make it bounce.

10. Display the output.


Result:
Thus the Multithreaded GUI application was compiled and executed successfully.

S-ar putea să vă placă și