EIT Practical
EIT Practical
EIT Practical
[PC-CS-305]
1|Page
Index
2|Page
Program – 1
Stack package:
package stackpackage;
public class stack2
{
int []a;
int top;
public stack2(int n)
{
a=new int[n];
top=-1;
}
public void push(int val)
{
if(top==a.length-1)
{
System.out.println("stack overflow");
}
else
{
top++;
a[top]=val;
}
}
public void pop()
{
if(top==-1)
{
System.out.println("stack underflow");
4|Page
}
else
{
System.out.println("element popped"+a[top]);
top--;
}
}
public void display()
{
if(top==-1)
{
System.out.println("stack empty");
}
else
{
for(int i=top;i>=0;i--)
{
System.out.println("sstack element :"+a[i]);
}
}
}
}
Main program:
import queuepackage.queue2;
import stackpackage.stack2;
import java.io.*;
public class usestackqueue2
{
public static void main(String args[])
{
BufferedReader sc=new BufferedReader(new InputStreamReader(System.in));
int c;
stack2 s;
int n;
try
{
do
{
System.out.println("1.stack 2.queue");
c=Integer.parseInt(sc.readLine());
5|Page
switch(c)
{
case 1:
System.out.println("enter the size of stack");
n=Integer.parseInt(sc.readLine());
s=new stack2(n);
int choice;
do
{
System.out.println("1.push,2.pop,3.display,0.exit,enter your choice:");
choice=Integer.parseInt(sc.readLine());
switch(choice)
{
case 1:
int value;
System.out.println("enter the element to push:");
value=Integer.parseInt(sc.readLine());
s.push(value);
break;
case 2:
s.pop();
break;
case 3:
s.display();
break;
case 0:
break;
default:System.out.println("invalid choice");
}
}while(choice!=0);
break;
case 2:
queue2 thequeue = new queue2(5);
thequeue.insert(10);
thequeue.insert(20);
thequeue.insert(30);
thequeue.insert(40);
thequeue.remove();
thequeue.remove();
thequeue.remove();
thequeue.insert(50);
thequeue.insert(60);
thequeue.insert(70);
6|Page
thequeue.insert(80);
while(!thequeue.isEmpty())
{
long n1= thequeue.remove();
System.out.print(n1);
System.out.print("");
}
System.out.println("");
break;
}
}while(c!=0);
}
catch(Exception e)
{}
}
}
Output:
1.stack 2.queue
1
enter the size of stack
5
1.push,2.pop,3.display,0.exit,enter your choice:
1
enter the element to push:
1
1.push,2.pop,3.display,0.exit,enter your choice:
1
enter the element to push:
2
1.push,2.pop,3.display,0.exit,enter your choice:
1
enter the element to push:
3
1.push,2.pop,3.display,0.exit,enter your choice:
3
sstack element :3
sstack element :2
sstack element :1
1.push,2.pop,3.display,0.exit,enter your choice:
7|Page
2
element popped3
1.push,2.pop,3.display,0.exit,enter your choice:
3
sstack element :2
sstack element :1
1.push,2.pop,3.display,0.exit,enter your choice:
0
1.stack 2.queue
2
4050607080
1.stack 2.queue
0
8|Page
Program – 2
Aim: -Design a class for Complex numbers in Java .In addition to methods for
basic operations on complex numbers, provide a method to return the number of
active objects created.
Program:
// Java program to add and subtract two
// complex numbers using Class
+
import java.util.*;
// Declaring variables
int real, imaginary;
// Empty Constructor
Complex()
{
}
// Constructor to accept
// real and imaginary part
Complex(int tempReal, int tempImaginary)
{
real = tempReal;
imaginary = tempImaginary;
}
9|Page
// adding Imaginary part of complex numbers
temp.imaginary = C1.imaginary + C2.imaginary;
// Main Class
public class GFG {
// Main function
public static void main(String[] args)
{
10 | P a g e
// printing first complex number
C1.printComplexNumber();
Output:
Complex number: 3 + 2i
Complex number: 9 + 5i
Sum of Complex number: 12 + 7i
Difference of Complex number: -6 + -3i
11 | P a g e
Program – 3
Aim: -Develop with suitable hierarchy, class for point, shape rectangle,
square, circle, ellipse, triangle, polygenetic.
Program:
package date;
public class day
{
int day,month,year,y,m,tot_day=0;
int day_mon[]={31,28,31,30,31,30,31,31,30,31,30,31};
String
week[]={"sunday","monday","tuesday","wednesday","thursday","friday","satur
day"};
public void days(int a,int b,int c)
{
valid(a,b,c);
day=a;
month=b;year=c;
for(y=0;y<year;y++)
if(y%4==0)
tot_day+=366;
else
tot_day+=365;
if(month>2 && year%4==0)
day_mon[1]=29;
for(m=0;m<(month-1);m++)
tot_day+=day_mon[m];
tot_day+=day;
System.out.println(day+"-"+month+"-"+year+" this
is :"+"="+week[(tot_day+4)%7]);
}
public void valid(int dd,int mm,int yy)
{
if(yy<1)
{
System.out.println("invalid....");
System.exit(0);
}
switch(mm)
{
12 | P a g e
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
if(dd>31 || dd<1)
{
System.out.println("invalid......");
System.exit(0);
}
break;
case 4:
case 6:
case 9:
case 11:
if(dd>30 || dd<1)
{
System.out.println("invalid......");
System.exit(0);
}
break;
case 2:
if(yy%4!=0 && dd>=29 && dd<1)
{
System.out.println("invalid......");
System.exit(0);
}
else if(yy%4==0 || dd>28 || dd<1)
{
System.out.println("invalid......");
System.exit(0);
}break;
default:
System.out.println("invalid......");
System.exit(0);
}
}
}
Main program:
13 | P a g e
import date.*;
import java.io.*;
class chkd
{
public static void main(String args[])throws IOException
{
DataInputStream in=new DataInputStream(System.in);
day d=new day();
System.out.println("enter the date:(dd mm yyyy):");
int dd=Integer.parseInt(in.readLine());
int mm=Integer.parseInt(in.readLine());
int yy=Integer.parseInt(in.readLine());
d.days(dd,mm,yy);
}
}
Output:
14 | P a g e
Program – 4
15 | P a g e
Program – 5
interface MyInterface {
int n = 20;
public void pop();
public void push();
public void peek();
public void display();
}
16 | P a g e
}
}
public void pop() {
int popper = arr[top];
top--;
System.out.println("popped element " + popper);
}
public void peek() {
int popper = arr[top];
System.out.println("popped element " + popper);
}
public void display() {
if (top < 0) {
System.out.println("Stack is empty");
return;
} else {
String str = " ";
for (int i = 0; i <= top; i++)
str = str + " " + arr[i];
System.out.println("Elements are " + str);
}
}
}
class StackADT {
public static void main(String arg[]) throws IOException {
DataInputStream dis = new DataInputStream(System.in);
StackImplementation stk = new StackImplementation();
17 | P a g e
int menu = 0;
do {
System.out.println("1.push \n2.pop \n3.peek \n4.display \
n5.Exit");
System.out.println();
System.out.print("Enter your choice: ");
menu = Integer.parseInt(dis.readLine());
switch (menu) {
case 1:
stk.push();
break;
case 2:
stk.pop();
break;
case 3:
stk.peek();
break;
case 4:
stk.display();
break;
case 5:
System.exit(0);
}
} while (menu <= 5);
System.out.println();
}
}
Output:
18 | P a g e
1.push
2.pop
3.peek
4.display
5.Exit
Enter your choice: 1
Enter Element5
1.push
2.pop
3.peek
4.display
5.Exit
19 | P a g e
Program – 6
Aim: - Develop two different classes that implement this interface. One using
array and other using linked list.
Program:
import java.io.*;
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(System.in));
if(top==(n-1))
{
System.out.println(" Stack Overflow");
return;
}
else
{
System.out.println("Enter the element");
int ele=Integer.parseInt(br.readLine());
stack[++top]=ele;
}
}
catch(IOException e)
{
System.out.println("e");
}
20 | P a g e
}
public void pop()
{
if(top<0)
{
System.out.println("Stack underflow");
return;
}
else
{
int popper=stack[top];
top--;
System.out.println("Popped element:" +popper);
}
}
21 | P a g e
System.out.print(" --> "+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(System.in));
System.out.println("Enter the element");
int ele=Integer.parseInt(br.readLine());
Link link = new Link(ele);
link.nextLink = first;
first = link;
}
catch(IOException e)
{
System.err.println(e);
}
}
public Link delete()
{
Link temp = first;
try
{
first = first.nextLink;
}
catch(NullPointerException e)
{
throw e;
}
return temp;
22 | P a g e
}
public void pop()
{
try
{
Link deletedLink = delete();
System.out.println("Popped: "+deletedLink.data);
}
catch(NullPointerException e)
{
throw e;
}
}
public void display()
{
if(first==null)
System.out.println("Stack is empty");
else
{
Link currentLink = first;
System.out.print("Elements are: ");
while(currentLink != null)
{
currentLink.printLink();
currentLink = currentLink.nextLink;
}
System.out.println("");
}
}
}
class StackADT
{
public static void main(String arg[])throws IOException
{
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
System.out.println("Implementation of Stack using Array");
Stack_array stk=new Stack_array();
int ch=0;
do
{
System.out.println("1.Push 2.Pop 3.Display 4.Exit 5.Use Linked List");
System.out.println("Enter your choice:");
23 | P a g e
ch=Integer.parseInt(br.readLine());
switch(ch)
{
case 1:
stk.push();
break;
case 2:
stk.pop();
break;
case 3:
stk.display();
break;
case 4:
System.exit(0);
}
}
while(ch<5);
System.out.println("Implementation of Stack using Linked List");
Stack_List stk1=new Stack_List();
ch=0;
do
{
System.out.println("1.Push 2.Pop 3.Display 4.Exit");
System.out.println("Enter your choice:");
ch=Integer.parseInt(br.readLine());
switch(ch)
{
case 1:
stk1.push();
break;
case 2:
try
{
stk1.pop();
}
catch(NullPointerException e)
{
System.out.println("Stack underflown");
}
break;
case 3:
stk1.display();
break;
24 | P a g e
default:
System.exit(0);
}
}
while(ch<5);
}
}
Output:
Implementation of Stack using Array
1.Push 2.Pop 3.Display 4.Exit 5.Use Linked List
Enter your choice:
1
Enter the element
10
1.Push 2.Pop 3.Display 4.Exit 5.Use Linked List
Enter your choice:
1
Enter the element
15
1.Push 2.Pop 3.Display 4.Exit 5.Use Linked List
Enter your choice:
1
Enter the element
25
1.Push 2.Pop 3.Display 4.Exit 5.Use Linked List
Enter your choice:
3
Elements are: 10 <-- 15 <-- 25 <--
25 | P a g e
1.Push 2.Pop 3.Display 4.Exit 5.Use Linked List
Enter your choice:
5
Implementation of Stack using Linked List
1.Push 2.Pop 3.Display 4.Exit
Enter your choice:
1
Enter the element
10
1.Push 2.Pop 3.Display 4.Exit
Enter your choice:
1
Enter the element
15
1.Push 2.Pop 3.Display 4.Exit
Enter your choice:
1
Enter the element
20
1.Push 2.Pop 3.Display 4.Exit
Enter your choice:
3
Elements are: --> 20 --> 15 --> 10
1.Push 2.Pop 3.Display 4.Exit
Enter your choice:
2
Popped: 20
26 | P a g e
1.Push 2.Pop 3.Display 4.Exit
Enter your choice:
3
Elements are: --> 15 --> 10
1.Push 2.Pop 3.Display 4.Exit
Enter your choice:
4
27 | P a g e
Program – 7
Aim: - Develop a simple paint like program that can draw basic graphical
primitives.
Program:
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.util.Random;
28 | P a g e
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
doDrawing(g);
}
}
public class PointsEx extends JFrame {
public PointsEx()
initUI();
}
private void initUI() {
var drawPanel = new DrawPanel();
add(drawPanel);
setSize(350, 250);
setTitle("Points");
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
EventQueue.invokeLater(() -> {
var ex = new PointsEx();
ex.setVisible(true);
});
}
}
29 | P a g e
Output:
30 | P a g e
Program – 8
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;
JTextField tfield;
int k = 1, x = 0, y = 0, z = 0;
char ch;
JButton b1, b2, b3, b4, b5, b6, b7, b8, b9, zero, clr, pow2, pow3, exp,
fac, plus, min, div, log, rec, mul, eq, addSub, dot, mr, mc, mp,
Container cont;
ScientificCalculator()
31 | P a g e
{
cont = getContentPane();
cont.setLayout(new BorderLayout());
tfield.setHorizontalAlignment(SwingConstants.RIGHT);
tfield.addKeyListener(new KeyAdapter() {
char c = keyevent.getKeyChar();
else
keyevent.consume();
});
textpanel.add(tfield);
32 | P a g e
boolean t = true;
mr = new JButton("MR");
buttonpanel.add(mr);
mr.addActionListener(this);
mc = new JButton("MC");
buttonpanel.add(mc);
mc.addActionListener(this);
mp = new JButton("M+");
buttonpanel.add(mp);
mp.addActionListener(this);
mm = new JButton("M-");
buttonpanel.add(mm);
mm.addActionListener(this);
b1 = new JButton("1");
buttonpanel.add(b1);
b1.addActionListener(this);
b2 = new JButton("2");
buttonpanel.add(b2);
b2.addActionListener(this);
b3 = new JButton("3");
33 | P a g e
buttonpanel.add(b3);
b3.addActionListener(this);
b4 = new JButton("4");
buttonpanel.add(b4);
b4.addActionListener(this);
b5 = new JButton("5");
buttonpanel.add(b5);
b5.addActionListener(this);
b6 = new JButton("6");
buttonpanel.add(b6);
b6.addActionListener(this);
b7 = new JButton("7");
buttonpanel.add(b7);
b7.addActionListener(this);
b8 = new JButton("8");
buttonpanel.add(b8);
b8.addActionListener(this);
b9 = new JButton("9");
buttonpanel.add(b9);
b9.addActionListener(this);
34 | P a g e
zero = new JButton("0");
buttonpanel.add(zero);
zero.addActionListener(this);
buttonpanel.add(plus);
plus.addActionListener(this);
buttonpanel.add(min);
min.addActionListener(this);
buttonpanel.add(mul);
mul.addActionListener(this);
div.addActionListener(this);
buttonpanel.add(div);
buttonpanel.add(addSub);
addSub.addActionListener(this);
buttonpanel.add(dot);
35 | P a g e
dot.addActionListener(this);
eq = new JButton("=");
buttonpanel.add(eq);
eq.addActionListener(this);
buttonpanel.add(rec);
rec.addActionListener(this);
buttonpanel.add(sqrt);
sqrt.addActionListener(this);
buttonpanel.add(log);
log.addActionListener(this);
buttonpanel.add(sin);
sin.addActionListener(this);
buttonpanel.add(cos);
cos.addActionListener(this);
36 | P a g e
buttonpanel.add(tan);
tan.addActionListener(this);
buttonpanel.add(pow2);
pow2.addActionListener(this);
buttonpanel.add(pow3);
pow3.addActionListener(this);
exp.addActionListener(this);
buttonpanel.add(exp);
fac.addActionListener(this);
buttonpanel.add(fac);
buttonpanel.add(clr);
clr.addActionListener(this);
cont.add("Center", buttonpanel);
cont.add("North", textpanel);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
37 | P a g e
}
String s = e.getActionCommand();
if (s.equals("1"))
if (z == 0)
tfield.setText(tfield.getText() + "1");
else
tfield.setText("");
tfield.setText(tfield.getText() + "1");
z = 0;
if (s.equals("2")) {
if (z == 0) {
tfield.setText(tfield.getText() + "2");
38 | P a g e
}
else
tfield.setText("");
tfield.setText(tfield.getText() + "2");
z = 0;
if (s.equals("3")) {
if (z == 0) {
tfield.setText(tfield.getText() + "3");
else
tfield.setText("");
tfield.setText(tfield.getText() + "3");
z = 0;
if (s.equals("4")) {
39 | P a g e
if (z == 0) {
tfield.setText(tfield.getText() + "4");
else
tfield.setText("");
tfield.setText(tfield.getText() + "4");
z = 0;
if (s.equals("5")) {
if (z == 0) {
tfield.setText(tfield.getText() + "5");
else
tfield.setText("");
tfield.setText(tfield.getText() + "5");
z = 0;
40 | P a g e
}
if (s.equals("6")) {
if (z == 0) {
tfield.setText(tfield.getText() + "6");
else
tfield.setText("");
tfield.setText(tfield.getText() + "6");
z = 0;
if (s.equals("7")) {
if (z == 0) {
tfield.setText(tfield.getText() + "7");
else
tfield.setText("");
tfield.setText(tfield.getText() + "7");
41 | P a g e
z = 0;
if (s.equals("8")) {
if (z == 0) {
tfield.setText(tfield.getText() + "8");
else
tfield.setText("");
tfield.setText(tfield.getText() + "8");
z = 0;
if (s.equals("9")) {
if (z == 0) {
tfield.setText(tfield.getText() + "9");
else
42 | P a g e
tfield.setText("");
tfield.setText(tfield.getText() + "9");
z = 0;
if (s.equals("0"))
if (z == 0) {
tfield.setText(tfield.getText() + "0");
else
tfield.setText("");
tfield.setText(tfield.getText() + "0");
z = 0;
if (s.equals("AC")) {
tfield.setText("");
x = 0;
43 | P a g e
y = 0;
z = 0;
if (s.equals("log"))
if (tfield.getText().equals("")) {
tfield.setText("");
else
a = Math.log(Double.parseDouble(tfield.getText()));
tfield.setText("");
tfield.setText(tfield.getText() + a);
if (s.equals("1/x")) {
if (tfield.getText().equals("")) {
tfield.setText("");
else
44 | P a g e
{
a = 1 / Double.parseDouble(tfield.getText());
tfield.setText("");
tfield.setText(tfield.getText() + a);
if (s.equals("Exp")) {
if (tfield.getText().equals("")) {
tfield.setText("");
else
a = Math.exp(Double.parseDouble(tfield.getText()));
tfield.setText("");
tfield.setText(tfield.getText() + a);
if (s.equals("x^2")) {
if (tfield.getText().equals("")) {
tfield.setText("");
45 | P a g e
}
else
a = Math.pow(Double.parseDouble(tfield.getText()), 2);
tfield.setText("");
tfield.setText(tfield.getText() + a);
if (s.equals("x^3")) {
if (tfield.getText().equals("")) {
tfield.setText("");
else
a = Math.pow(Double.parseDouble(tfield.getText()), 3);
tfield.setText("");
tfield.setText(tfield.getText() + a);
if (s.equals("+/-")) {
46 | P a g e
if (x == 0) {
tfield.setText("-" + tfield.getText());
x = 1;
else
tfield.setText(tfield.getText());
if (s.equals(".")) {
if (y == 0) {
tfield.setText(tfield.getText() + ".");
y = 1;
else
tfield.setText(tfield.getText());
if (s.equals("+"))
47 | P a g e
{
if (tfield.getText().equals(""))
tfield.setText("");
temp = 0;
ch = '+';
else
temp = Double.parseDouble(tfield.getText());
tfield.setText("");
ch = '+';
y = 0;
x = 0;
tfield.requestFocus();
if (s.equals("-"))
if (tfield.getText().equals(""))
48 | P a g e
{
tfield.setText("");
temp = 0;
ch = '-';
else
x = 0;
y = 0;
temp = Double.parseDouble(tfield.getText());
tfield.setText("");
ch = '-';
tfield.requestFocus();
if (s.equals("/")) {
if (tfield.getText().equals(""))
tfield.setText("");
temp = 1;
49 | P a g e
ch = '/';
else
x = 0;
y = 0;
temp = Double.parseDouble(tfield.getText());
ch = '/';
tfield.setText("");
tfield.requestFocus();
if (s.equals("*")) {
if (tfield.getText().equals(""))
tfield.setText("");
temp = 1;
ch = '*';
else
50 | P a g e
{
x = 0;
y = 0;
temp = Double.parseDouble(tfield.getText());
ch = '*';
tfield.setText("");
tfield.requestFocus();
if (s.equals("MC"))
m1 = 0;
tfield.setText("");
if (s.equals("MR"))
tfield.setText("");
tfield.setText(tfield.getText() + m1);
if (s.equals("M+"))
51 | P a g e
{
if (k == 1) {
m1 = Double.parseDouble(tfield.getText());
k++;
else
m1 += Double.parseDouble(tfield.getText());
tfield.setText("" + m1);
if (s.equals("M-"))
if (k == 1) {
m1 = Double.parseDouble(tfield.getText());
k++;
else
m1 -= Double.parseDouble(tfield.getText());
52 | P a g e
tfield.setText("" + m1);
if (s.equals("Sqrt"))
if (tfield.getText().equals(""))
tfield.setText("");
else
a = Math.sqrt(Double.parseDouble(tfield.getText()));
tfield.setText("");
field.setText(tfield.getText() + a);
if (s.equals("SIN"))
if (tfield.getText().equals(""))
53 | P a g e
tfield.setText("");
else
a = Math.sin(Double.parseDouble(tfield.getText()));
tfield.setText("");
tfield.setText(tfield.getText() + a);
if (s.equals("COS"))
if (tfield.getText().equals(""))
tfield.setText("");
else
a = Math.cos(Double.parseDouble(tfield.getText()));
tfield.setText("");
tfield.setText(tfield.getText() + a);
54 | P a g e
}
if (s.equals("TAN")) {
if (tfield.getText().equals("")) {
tfield.setText("");
else
a = Math.tan(Double.parseDouble(tfield.getText()));
tfield.setText("");
tfield.setText(tfield.getText() + a);
if (s.equals("="))
if (tfield.getText().equals(""))
tfield.setText("");
else
55 | P a g e
{
temp1 = Double.parseDouble(tfield.getText());
switch (ch)
case '+':
break;
case '-':
break;
case '/':
break;
case '*':
break;
tfield.setText("");
tfield.setText(tfield.getText() + result);
z = 1;
56 | P a g e
}
if (s.equals("n!"))
if (tfield.getText().equals(""))
tfield.setText("");
else
a = fact(Double.parseDouble(tfield.getText()));
tfield.setText("");
tfield.setText(tfield.getText() + a);
tfield.requestFocus();
double fact(double x)
int er = 0;
57 | P a g e
if (x < 0)
er = 20;
return 0;
double i, s = 1;
s *= i;
return s;
try
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLook
AndFeel");
catch (Exception e)
58 | P a g e
f.setTitle("ScientificCalculator");
f.pack();
f.setVisible(true);
Output:
59 | P a g e
Program – 9
Aim: - Develop a template for linked list class along with its members in Java.
Program:
import java.io.*;
import java.util.*;
class Link<T>
{
public T data;
public Link nextLink;
public Link(T d) {
data = d;
}
public void printLink() {
System.out.println("item:"+data);
}
}
class LinkList<T>
{
private Link first;
private Link last;
public LinkList() {
first = null;
}
public boolean isEmpty() {
return first == null;
}
public void insert(T d){
Link link = new Link(d);
if(first==null){
link.nextLink = null;
first = link;
last=link;
}
else{
last.nextLink=link;
link.nextLink=null;
60 | P a g e
last=link;
}
}
public Link delete() {
Link temp = first;
first = first.nextLink;
return temp;
}
public void printList() {
Link currentLink = first;
while(currentLink != null) {
currentLink.printLink();
currentLink = currentLink.nextLink;
}
System.out.println("");
}
}
class template {
public static void main(String[] args)
{
int i,c=1,ch,p1=0,p2=0,p3=0;
Scanner in=new Scanner(System.in);
LinkList<Integer> l = new LinkList();
LinkList<String> s=new LinkList();
LinkList<Double> d=new LinkList();
do {
System.out.println("1.INTEGER 2.STRING 3.DOUBLE 4.exit");
System.out.println("enter ur choice:");
c=in.nextInt();
switch(c)
{
case 1:
do {
if(p1==1)break;
System.out.println("1.insert 2.delete 3.display 4.exit");
System.out.println("enter ur choice:");
ch=in.nextInt();
switch(ch)
{
case 1:
61 | P a g e
System.out.println("Integer list");
System.out.println("enter the insert value:");
i=in.nextInt();
l.insert(i);
break;
case 2:
l.delete();
System.out.println("data deleted:");
break;
case 3:
System.out.println("elements are :");
l.printList();
break;
case 4:
p1=1;
continue;
}
}while(c!=0);
break;
case 2:
do {
if(p2==1)break;
System.out.println("1.insert 2.delete 3.display 4.exit");
System.out.println("enter ur choice:");
ch=in.nextInt();
switch(ch)
{
case 1:
System.out.println("STRING list");
System.out.println("enter the insert value:");
String a=in.next();
s.insert(a);
break;
case 2:
s.delete();
System.out.println("data deleted:");
break;
case 3:
System.out.println("elements are :");
s.printList();
62 | P a g e
break;
case 4:
p2=1;
continue;
}
}while(c!=0);
break;
case 3:
do{
if(p3==1)break;
System.out.println("1.insert 2.delete 3.display 4.exit");
System.out.println("enter ur choice:");
ch=in.nextInt();
switch(ch)
{
case 1:
System.out.println("DOUBLE list");
System.out.println("enter the insert value:");
double x=in.nextDouble();
d.insert(x);
break;
case 2:
d.delete();
System.out.println("data deleted:");
break;
case 3:
System.out.println("elements are :");
d.printList();
break;
case 4:
p3=1;
continue;
}
}while(c!=0);
break;
case 4:
System.exit(0);
}
}while(c!=0);
63 | P a g e
}
}
Output:
1.INTEGER 2.STRING 3.DOUBLE 4.exit
enter ur choice:
1
1.insert 2.delete 3.display 4.exit
enter ur choice:
1
Integer list
enter the insert value:
1
1.insert 2.delete 3.display 4.exit
enter ur choice:
1
Integer list
enter the insert value:
2
1.insert 2.delete 3.display 4.exit
enter ur choice:
1
Integer list
enter the insert value:
3
1.insert 2.delete 3.display 4.exit
enter ur choice:
3
64 | P a g e
elements are :
item:1
item:2
item:3
65 | P a g e
niren
1.insert 2.delete 3.display 4.exit
enter ur choice:
1
STRING list
enter the insert value:
kumar
1.insert 2.delete 3.display 4.exit
enter ur choice:
1
STRING list
enter the insert value:
raj
1.insert 2.delete 3.display 4.exit
enter ur choice:
3
elements are :
item:niren
item:kumar
item:raj
66 | P a g e
3
elements are :
item:kumar
item:raj
67 | P a g e
Program – 10
69 | P a g e
}
catch (Exception e)
{
out.println("error");
}
}
}
web.xml setting: -
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more contribu
tor license agreements. See the NOTICE file distributed with this work for addit
ional information regarding copyright ownership. The ASF licenses this file to
You under the Apache License, Version 2.0 (the "License"); you may not use th
is file except in compliance with the License. You may obtain a copy of the Lic
ense at
http://www.apache.org/licenses/LICENSE-2.0
70 | P a g e
<servlet>
<servlet-name>display</servlet-name>
<servlet-class>display</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>display</servlet-name>
<url-pattern>/display</url-pattern>
</servlet-mapping>
</web-app>
Output:
72 | P a g e