Java
Java
TECHNOLOGY
SAMALAKHA , PANIPAT
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 StackDemo.java
import java.util.Stack;
stack.push(i);
int x=(int)stack.pop();
if(pos==-1)
else
System.out.println("Lakshraj - 2821145");
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 QueueDemo.java\
import java.util.PriorityQueue;
import java.util.Iterator;
public class QueueDemo {
static void queue_add(PriorityQueue q, int i)
{
q.add(i);
System.out.println("Element "+i+" added in queue.");
}
static void queue_find(PriorityQueue q,int elem)
{
if(q.contains(elem) )
System.out.println(" Element "+elem+" present in queue");
else
System.out.println(" Element "+elem+" not present in queue");
}
Package complex;
{ Complex temp=new
Complex(0,0); temp.real=c1.real +
c2.real; temp.imag=c1.imag +
System.out.println("Lakshraj Chauhan -
Complex(3.15,22.6); System.out.println("Second
Complex temp=add(c1,c2);
}
OUTPUT-
PRACTICAL NO. 03
Problem Statement – Develop with suitable hierarchy, class for point, shape,
rectangle, square, circle, ellipse, triangle, polygenetic.
double dim1;
double dim2;
double PI=3.14;
Shape(double a, double b)
dim1 = a;
dim2 = b;
Rectangle(double a, double b)
super(a, b);
double area()
}
class Triangle extends Shape
Triangle(double a, double b)
super(a, b);
double area()
Circle(double a, double b)
super(a, b);
double area()
Ellipse(double a, double b)
{
super(a, b);
double area() {
Square(double a, double b)
super(a, b);
double area() {
figref = r;
System.out.println("Area is " + figref.area());
figref = t;
figref = c;
figref = e;
figref = s;
}
OUTPUT-
PRACTICAL NO. 04
Problem Statement – Design a simple test application to demonstrate dynamic
polymorphism.
class Bike{
void run(){
System.out.println("running");}
}
class Splendor extends Bike{
void run(){
System.out.println("running safely with 60km");}
public static void main(String args[]){
System.out.println("Lakshraj Chauhan 2821145\n");
Bike b = new Splendor();//upcasting
b.run();
}
}
OUTPUT-
PRACTICAL NO. 05
Problem Statement – Design a java interface for ADT stack.
import java.io.*;
interface StackOperation
{
public void push(int i);
public void pop();
}
class TestStack
{
public static void main(String args[])throws IOException
{
System.out.println("--Lakshraj Chauhan--");
catch(IOException e)
{
System.out.println("io error");
}
System.out.println("Do u want to continue 0 to quit and 1 to continue ");
c=Integer.parseInt(in.readLine());
}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 java.io.*;
interface Mystack
{
public void pop();
public void push();
public void display();
}
class Link
{
public int data;
public Link nextLink;
public Link(int d)
{
data= d;
nextLink=null;
}
public void printLink()
{
System.out.print(" --> "+data);
}
}
class StackADT
{
public static void main(String arg[])throws IOException
{
System.out.println("--Lakshraj Chauhan 2821145--");
break;
case 3:
stk1.display();
break;
default:
System.exit(0);
}
}
while(ch<5);
}
}
OUTPUT
PRACTICAL NO. 07
Problem Statement – Develop a simple paint like program that can draw basic
graphical primitives.
import java.io.*;
interface Mystack
{
public void pop();
public void push();
public void display();
}