PANIPAT INSTITUTE OF ENGINEERING AND
TECHNOLOGY
SAMALAKHA , PANIPAT
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
Practical lab file for EIT
(Essentials of Information Technology)
CODE : PC-CS-311LA
INDEX
S. No. Name of practical Date of practical Signature
PRACTICAL NO. 01
Problem Statement – Write a Java package with stack and queue classes.
(i) In [Link]
import [Link];
public class StackDemo extends Stack {
static void stack_push(Stack stack, int i){
[Link](i);
[Link]("Element "+i+" pushed in stack.");
static void stack_pop(Stack stack){
[Link]("Pop operation: ");
int x=(int)[Link]();
[Link]("Element "+x+" popped");
static void stack_search(Stack stack, int elem){
int pos= (int)[Link](elem);
if(pos==-1)
[Link]("Element "+elem+" not found");
else
[Link]("Element "+elem+" found at position "+ pos);
public static void main(String args[]){
Stack s = new Stack();
[Link]("Lakshraj - 2821145");
[Link]("Push operation: ");
stack_push(s,10);
stack_push(s,20);
stack_push(s,30);
stack_search(s,10);
stack_pop(s);
stack_search(s,30);
stack_search(s,20); }
}
OUTPUT-
(ii) In [Link]\
import [Link];
import [Link];
public class QueueDemo {
static void queue_add(PriorityQueue q, int i)
{
[Link](i);
[Link]("Element "+i+" added in queue.");
}
static void queue_find(PriorityQueue q,int elem)
{
if([Link](elem) )
[Link](" Element "+elem+" present in queue");
else
[Link](" Element "+elem+" not present in queue");
}
public static void main(String args[])
{
[Link]("Lakshraj 2821145");
PriorityQueue q=new PriorityQueue();
for(int i=1; i<6 ; i++)
queue_add(q,i);
Iterator itr= [Link]();
while([Link]())
{
[Link]([Link]()+" \n");
}
queue_find(q,3);
queue_find(q,6);
[Link]("head :"+[Link]());
[Link]();
[Link]();
[Link]("after removing two elements, queue:");
Iterator itr2= [Link]();
while([Link]())
{
[Link]([Link]()+" ");
}
[Link]();
}
}
OUTPUT-
PRACTICAL NO. 02
Problem Statement – Design a class for complex numbers in JAVA. In addition
to methods of basic operations on complex numbers, provide a method to return
the number of active objects created in [Link]
Package complex;
public class Complex{
double real, imag;
Complex(double real, double imag){ [Link]=real; [Link]=imag;
[Link](" Real part: "+[Link]+" Complex part: "+[Link]);
static Complex add(Complex c1, Complex c2)
{ Complex temp=new
Complex(0,0); [Link]=[Link] +
[Link]; [Link]=[Link] +
[Link]; return temp;
public static void main(String args[]){
[Link]("Lakshraj Chauhan -
2821145"); [Link]("First Complex
number: "); Complex c1=new
Complex(3.15,22.6); [Link]("Second
Complex number: ");
Complex c2=new Complex(6.35,16.32);
[Link]("Temporary number: ");
Complex temp=add(c1,c2);
[Link]("Sum is : %.1f + %.1fi",[Link],[Link]);
}
OUTPUT-
PRACTICAL NO. 03
Problem Statement – Develop with suitable hierarchy, class for point, shape,
rectangle, square, circle, ellipse, triangle, polygenetic.
abstract class Shape
double dim1;
double dim2;
double PI=3.14;
Shape(double a, double b)
dim1 = a;
dim2 = b;
abstract double area();
class Rectangle extends Shape
Rectangle(double a, double b)
super(a, b);
double area()
[Link]("Area for Rectangle.");
return dim1 * dim2;
}
class Triangle extends Shape
Triangle(double a, double b)
super(a, b);
double area()
[Link]("Area for Triangle.");
return dim1 * dim2 / 2;
class Circle extends Shape
Circle(double a, double b)
super(a, b);
double area()
[Link]("Area for Circle.");
return PI * dim1 * dim1;
class Ellipse extends Shape
Ellipse(double a, double b)
{
super(a, b);
double area() {
[Link]("Area for Ellipse.");
return PI * dim1 * dim2;
class Square extends Shape
Square(double a, double b)
super(a, b);
double area() {
[Link]("Area for Square.");
return dim1 * dim1;
public class AbstractAreas {
public static void main (String[] args) {
[Link]("Gurjot Singh - 2821042");
Rectangle r = new Rectangle(9, 5);
Triangle t = new Triangle(10, 8);
Circle c=new Circle(5,5);
Ellipse e=new Ellipse(7,7);
Square s=new Square(6,6);
Shape figref; // this is OK, no object is created
figref = r;
[Link]("Area is " + [Link]());
figref = t;
[Link]("Area is " + [Link]());
figref = c;
[Link]("Area is " + [Link]());
figref = e;
[Link]("Area is " + [Link]());
figref = s;
[Link]("Area is " + [Link]());
}
OUTPUT-
PRACTICAL NO. 04
Problem Statement – Design a simple test application to demonstrate dynamic
polymorphism.
class Bike{
void run(){
[Link]("running");}
}
class Splendor extends Bike{
void run(){
[Link]("running safely with 60km");}
public static void main(String args[]){
[Link]("Lakshraj Chauhan 2821145\n");
Bike b = new Splendor();//upcasting
[Link]();
}
}
OUTPUT-
PRACTICAL NO. 05
Problem Statement – Design a java interface for ADT stack.
import [Link].*;
interface StackOperation
{
public void push(int i);
public void pop();
}
class StackDemo implements StackOperation
{
int stack[]=new int[5];
int top=-1;
int i;
public void push(int item)
{
if(top>=4)
{
[Link]("overflow");
}
else
{
top=top+1;
stack[top]=item;
[Link]("item pushed"+stack[top]);
}
}
public void pop()
{
if(top<0)
[Link]("underflow");
else
{
[Link]("item popped"+stack[top]); top=top-1;
}
}
public void display()
{
if(top<0)
[Link]("No Element in stack"); else
{
for(i=0;i<=top;i++)
[Link]("element:"+stack[i]);
}
}
}
class TestStack
{
public static void main(String args[])throws IOException
{
[Link]("--Lakshraj Chauhan--");
int ch,c; int i;
StackDemo s=new StackDemo();
DataInputStream in=new DataInputStream([Link]);
do
{
try
{
[Link]("ARRAY STACK");
[Link]("[Link] [Link] [Link] [Link]");
[Link]("enter ur choice:");
ch=[Link]([Link]());
switch(ch)
{
case 1:
[Link]("enter the value to push:");
i=[Link]([Link]());
[Link](i);
break;
case 2:
[Link]();
break;
case 3:
[Link]("the elements are:");
[Link]();
break;
default:
break;
}
}
catch(IOException e)
{
[Link]("io error");
}
[Link]("Do u want to continue 0 to quit and 1 to continue ");
c=[Link]([Link]());
}while(c==1);
}
}
OUTPUT-
PRACTICAL NO. 06
Problem Statement – Develop two different classes that implement this interface.
One using array and other using linked list.
import [Link].*;
interface Mystack
{
public void pop();
public void push();
public void display();
}
class Stack_array implements Mystack
{
final static int n=5;
int stack[]=new int[n];
int top=-1;
public void push()
{
try
{
BufferedReader br=new BufferedReader(new InputStreamReader([Link]));
if(top==(n-1))
{
[Link](" Stack Overflow");
return;
}
else
{
[Link]("Enter the element"); int ele=[Link]([Link]());
stack[++top]=ele;
}
}
catch(IOException e)
{
[Link]("e");
}
}
public void pop()
{
if(top<0)
{
[Link]("Stack underflow"); return;
}
else
{
int popper=stack[top]; top--;
[Link]("Popped element:"+popper);
}
}
public void display()
{
if(top<0)
{
[Link]("Stack is empty"); return;
}
else
{
String str=" ";
for(int i=0; i<=top; i++) str=str+" "+stack[i]+" <--";
[Link]("Elements are:"+str);
}
}
}
class Link
{
public int data;
public Link nextLink;
public Link(int d)
{
data= d;
nextLink=null;
}
public void printLink()
{
[Link](" --> "+data);
}
}
class Stack_List implements Mystack
{
private Link first; public Stack_List()
{
first = null;
}
public boolean isEmpty()
{
return first == null;
}
public void push()
{
try
{
BufferedReader br=new BufferedReader(new InputStreamReader([Link]));
[Link]("Enter the element");
int ele=[Link]([Link]());
Link link = new Link(ele);
[Link] = first; first = link;
}
catch(IOException e)
{
[Link](e);
}
}
public Link delete()
{
Link temp =first;
try
{
first = [Link];
}
catch(NullPointerException e)
{
throw e;
}
return temp;
}
public void pop()
{
try
{
Link deletedLink = delete(); [Link]("Popped:"+[Link]);
}
catch(NullPointerException e)
{
throw e;
}
}
public void display()
{
if(first==null)
[Link]("Stack is empty"); else
{
Link currentLink = first;
[Link]("Elements are: ");
while(currentLink != null)
{
[Link](); currentLink =[Link];
}
[Link]("");
}
}
}
class StackADT
{
public static void main(String arg[])throws IOException
{
[Link]("--Lakshraj Chauhan 2821145--");
BufferedReader br=new BufferedReader(new InputStreamReader([Link]));
[Link]("Implementation of Stack using Array");
Stack_array stk=new Stack_array(); int ch=0;
do
{
[Link]("[Link] [Link] [Link] [Link] [Link] Linked List");
[Link]("Enter your choice:");
ch=[Link]([Link]());
switch(ch)
{
case 1:
[Link]();
break;
case 2:
[Link]();
break;
case 3:
[Link]();
break;
case 4:
[Link](0);
}
}
while(ch<5);
[Link]("Implementation of Stack using Linked List");
Stack_List stk1=new Stack_List(); ch=0;
do
{
[Link]("[Link] [Link] [Link] [Link]");
[Link]("Enter your choice:");
ch=[Link]([Link]());
switch(ch)
{
case 1:
[Link]();
break;
case 2:
try
{
[Link]();
}
catch(NullPointerException e)
{
[Link]("Stack underflown");
}
break;
case 3:
[Link]();
break;
default:
[Link](0);
}
}
while(ch<5);
}
}
OUTPUT
PRACTICAL NO. 07
Problem Statement – Develop a simple paint like program that can draw basic
graphical primitives.
import [Link].*;
interface Mystack
{
public void pop();
public void push();
public void display();
}
class Stack_array implements Mystack
{
final static int n=5;
int stack[]=new int[n];
int top=-1;
public void push()
{
try
{
BufferedReader br=new BufferedReader(new InputStreamReader([Link]));
if(top==(n-1))
{
[Link](" Stack Overflow");
return;
}
else
{
[Link]("Enter the element"); int ele=[Link]([Link]());
stack[++top]=ele;
}
}
catch(IOException e)
{
[Link]("e");
}
}
public void pop()
{
if(top<0)
{
[Link]("Stack underflow"); return;
}
else
{
int popper=stack[top]; top--;
[Link]("Popped element:"+popper);
}
}