EIT 145 - Completefile
EIT 145 - Completefile
Samalkha
Computer Science & Engineering Department
Affiliated to
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);
System.out.printf("Sum is : %.1f + %.1fi",temp.real,temp.imag);
}
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.awt.*;
import java.awt.event.*;
import javax.swing.*;
SwingUtilities.invokeLater(() -> {
window.setContentPane(content);
window.setSize(600, 480);
window.setLocation(100, 100);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setVisible(true);
});
private final static int BLACK = 0, RED = 1, GREEN = 2, BLUE = 3, CYAN = 4, MAGENTA =
5, YELLOW = 6;
public SimplePaintPanel() {
setBackground(Color.WHITE);
addMouseListener(this);
addMouseMotionListener(this);
super.paintComponent(g);
g.setColor(getColorByIndex(i));
g.setColor(Color.WHITE);
}
private Color getColorByIndex(int index) {
switch (index) {
case BLACK:
return Color.BLACK;
case RED:
return Color.RED;
case GREEN:
return Color.GREEN;
case BLUE:
return Color.BLUE;
case CYAN:
return Color.CYAN;
case MAGENTA:
return Color.MAGENTA;
case YELLOW:
return Color.YELLOW;
default:
return Color.BLACK;
repaint();
void setUpDrawingGraphics() {
graphicsForDrawing = getGraphics();
graphicsForDrawing.setColor(getColorByIndex(currentColor));
int x = evt.getX();
int y = evt.getY();
if (dragging) {
return;
repaint();
} else {
changeColor(y);
} else if (x > 3 && x < width - 56 && y > 3 && y < height - 3) {
prevX = x;
prevY = y;
dragging = true;
setUpDrawingGraphics();
if (!dragging) {
return;
dragging = false;
graphicsForDrawing.dispose();
graphicsForDrawing = null;
if (!dragging) {
return;
int x = evt.getX();
int y = evt.getY();
prevX = x;
prevY = y;
}
OUTPUT
PRACTICAL NO. 08
if(opf==false)
{
for(i=0;i<10;i++)
{
if(pb==b[i])
{
String t=res.getText();
t+=i;
res.setText(t);
}
}
}
else
{
n1=Integer.parseInt(res.getText());
res.setText("");
}
}
}
int eval()
{
switch(op)
{
case '+': r=n1+n2; break;
case '-': r=n1-n2; break;
case '*': r=n1*n2; break;
case '/': r=n1/n2; break;
}
return 0;
}
public static void main(String arg[])
{
new Calculator();
}
}
OUTPUT-
PRACTICAL NO. 09
Problem Statement – Develop a template for linked list class along with its members.
import java.io.*;
Node head;
int data;
Node next;
Node(int d)
{
data = d;
next = null;
}
}
if (list.head == null) {
list.head = new_node;
}
else {
Node last = list.head;
while (last.next != null) {
last = last.next;
}
last.next = new_node;
}
return list;
}
System.out.print("LinkedList: ");
currNode = currNode.next;
}
}
printList(list);
}
}
OUTPUT-
PRACTICAL NO. 10
JAVA code-
// Import required java libraries
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
// Extend HttpServlet class
public class HelloWorld extends HttpServlet {
private String message;
public void init() throws ServletException {
// Do required initialization
message = "Hello World";
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// Set response content type
response.setContentType("text/html");
// Actual logic goes here.
PrintWriter out = response.getWriter();
out.println("<h1>" + message + "</h1>");
}
public void destroy() {
// do nothing.
}}
HTML Code-
<servlet>
<servlet-name>HelloWorld</servlet-name>
<servlet-class>HelloWorld</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloWorld</servlet-name>
<url-pattern>/HelloWorld</url-pattern>
</servlet-mapping>
OUTPUT-