Eit File

You might also like

You are on page 1of 43

Essential of Information Technology

Lab
PC-CS-311LA

Submitted To:- Submitted By:-


Mr. Rajesh Leena(8621114)
Assistant Professor B.Tech CSE 5sem
APIIT SD INDIA Panipat Univ. roll no: 2021218212
INDEX

PROGRAM TITLE DATE PAGE SIGNATURE


NO. NO.

1. Write a java program to find the 09-08-2023 1-2


Fibonacci series using recursive
and non recursive functions
2. Write a java program to multiply 16-08-2023 3
two given matrices
3. Write a java program for 23-08-2023 4
Method overloading

4. Write a java program for 23-08-2023 5


Constructor overloading

5. Write a java program to display 30-08-2023 6


the employee details using
Scanner class

6. Write a Java Package with 04-09-2023 7-11


Stack and queue classes.
7. Design a class for Complex 18-09-2023 12
numbers in Java. In addition to
methods for basic operations
on complex numbers, provide a
method to return the number
of active objects created.
Write a program in 18-09-2023 13
8. java to find how many
characters are
repeated in a string.
9. Design a simple test application 25-09-2023 14
to demonstrate dynamic
polymorphism.
10. Write a Program to find the 25-09-2023 15
Smallest, largest and Second
Largest Element in an Array.
PROGRAM TITLE DATE PAGE SIGN
NO. NO.

11. Develop two different classes 09-10-2023 16-21


that implement this interface.
One using an array and another
using a linked list.
12. Develop a scientific calculator 16-10-2023 22-30
using event programming.

13. Develop a template for linked 16-11-2023 31-35


list class along with its
members in Java.
14. Develop a simple paint like 23-11-2023 36-37
program that can draw basic
graphical primitives
15. Write a program to insert 30-11-2023 38
and view data using
Servlets.
PROGRAM NO:- 1
Aim :-Write a java program to find the Fibonacci series using recursive and
non recursive functions

class fib
{
int a,b,c;
void nonrecursive(int n) //Non recursive function to find the Fibonacci series.
{
a=0;
b=1;
System.out.print(a+ "" + b);
c=a+b;
while(c<=n)
{
System.out.print(c);
a=b;
b=c;
c=a+b;
}
}
int recursive(int n) // Recursive function to find the Fibonacci series.
{
if(n==0)
return (0);
if(n==1)
return (1);
else
return(recursive(n-1)+recursive(n-2));
}
}
// Class that calls recursive and non recursive functions
class fib1
{
public static void main(String args[])
{
int n=5;
System.out.println("The Fibonacci series using non recursive is");
// Creating object for the fib class.
fib f=new fib();
// Calling non recursive function oF fib class.
f.nonrecursive(n);
System.out.println("\n The Fibonacci series using recursive is");
for(int i=0;i<=n;i++)
{
// Calling recursive function of fib class.
int F1=f.recursive(i);
System.out.print(F1);
}
}
}

OUTPUT :-
PROGRAM NO:- 2
Aim :- Write a java program to multiply two given matrices.
public class MatrixEx
{
public static void main(String args[])
{
//creating two matrices
int a[][]={{1,1,1},{2,2,2},{3,3,3}};
int b[][]={{1,1,1},{2,2,2},{3,3,3}};
//creating another matrix to store the multiplication of two matrices
int c[][]=new int[3][3]; //3 rows and 3 columns
//multiplying and printing multiplication of 2 matrices
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
c[i][j]=0;
for(int k=0;k<3;k++)
{
c[i][j]+=a[i][k]*b[k][j];
} //end of k loop
System.out.print(c[i][j]+" "); //printing matrix element
} //end of j loop
System.out.println(); //new line
}
}
}

OUTPUT :-
PROGRAM NO:- 3
Aim :- Write a java program for Method overloading

import java.io.*;
class MethodOverloadingEx {
static int add(int a, int b)
{
return a + b;
}
static int add(int a, int b, int c)
{
return a + b + c;
}
public static void main(String args[])
{
System.out.println("add() with 2 parameters");
System.out.println(add(4, 6));
System.out.println("add() with 3 parameters");
System.out.println(add(4, 6, 7));
}
}

OUTPUT :-
PROGRAM NO:- 4
Aim :- Write a java program for Constructor overloading
public class Student {
//instance variables of the class
int id;
String name;
Student(){
System.out.println("this is default constructor");
}
Student(int i, String n){
id = i;
name = n;
}
public static void main(String[] args) {
//object creation
Student s = new Student();
System.out.println("\nDefault Constructor values: \n");
System.out.println("Student Id : "+s.id + "\nStudent Name : "+s.name);
System.out.println("\nParameterized Constructor values: \n");
Student student = new Student(10, "Kalpana");
System.out.println("Student Id : "+student.id + "\nStudent Name : "+student.name);
}
}

OUTPUT :-
PROGRAM NO:- 5
Aim :- Write a java program to display the employee details using Scanner
class

import java.util.*;
class EmployeeDetails
{
public static void main(String args[])
{
System.out.println("enter name,id,age,salary"); Scanner sc=new Scanner(System.in);
String n=sc.next(); int i=sc.nextInt(); int a=sc.nextInt();
float s=sc.nextFloat();
System.out.println("name is"+n+"idis"+i+"ageis"+a+"salaryis"+s);
}
}

OUTPUT :-
PROGRAM NO:- 6
Aim :- Write a Java Package with Stack and queue classes.
Queue package:
package queue package;
public class queue2
{
private int maxsize;
private long[] queArray;
private int front;
private int rear;
private int nitems;
public queue2(int
s)
{
maxsize=s;
queArray=new long[maxsize];
front=0;
rear=-1;
nitems=0;
}
public void insert(long j)
{
if(rear==maxsize-1)
rear=-1;
queArray[+
+rear]=j; nitems++;
}
public long remove()
{
long temp=queArray[front++];
if(front==maxsize)
front=0;
nitems--;
return temp;}
public long peekFront()
{
return queArray[front];
}
public boolean isEmpty()
{
return(nitems==0);
}
public boolean isFull()
{
return(nitems==maxsize);
}
public int size()
{
return nitems;
}
}

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");
}
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());
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);
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 :-
PROGRAM NO:- 7
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.

public class Complex {


double real;
double imag;

public Complex(double real, double imag) {


this.real = real;
this.imag = imag;
}

public static void main(String[] args) {


Complex n1 = new Complex(3.5, 9.5),
n2 = new Complex(5.4, 6.0),
temp;
temp = add(n1, n2);
System.out.printf("Sum = %.1f + %.1fi", temp.real, temp.imag);
}
public static Complex add(Complex n1, Complex n2)
{
Complex temp = new Complex(0.0, 0.0);
temp.real = n1.real + n2.real;
temp.imag = n1.imag + n2.imag;
return(temp);
}
}

OUTPUT:-
PROGRAM NO:- 8
Aim :- Write a program in java to find how many character are
repeated in a string.

public class Duplicatechar {


public static void main(String[] args) {
findDuplicateChars("How many duplicates in this string");
findDuplicateChars("Hello Welcome to Java");
}
private static void findDuplicateChars(String str) {
System.out.println("Duplicates in- "+ str);
int count;
for(int i = 0; i < str.length(); i++) {
// get a character
char c = str.charAt(i);
//starting count for any character
count = 1;
//ignore spaces
if(c == ' ')
continue;
for(int j = i + 1; j < str.length(); j++) {
if(c == str.charAt(j)) {
count++;
// remove the char which is already counted
str = str.substring(0, j) + str.substring(j+ 1);
}
}
if(count > 1) {
System.out.println(c + " found " + count + " times");
}
}
}

OUTPUT :-
PROGRAM NO:- 9
Aim :- Design a simple test application to demonstrate dynamic
polymorphism.
//parent class
class Demo
{
//method of the parent class
public void display()
{
System.out.println("Overridden Method");
}
}
//derived or child class
public class sample extends Demo
{
//method of child class
public void display()
{
System.out.println("Overriding Method");
}
public static void main(String args[])
{
//assigning a child class object to parent class reference
Demo obj = new sample();
//invoking display() method
obj.display();
}
}

OUTPUT :-
PROGRAM NO:- 10

Aim :- Write a Program to find the Smallest, largest, Second Smallest


and Second Largest Element in an Array.

import java.util.*;
public class Array {
public static void main(String []args){
int a;
int arr[] = {55, 10, 8, 90, 43, 87, 95, 25, 50, 12};
System.out.println("Array = "+Arrays.toString(arr));
int count = arr.length;
for (int i = 0; i < count; i++) {
for (int j = i + 1; j < count; j++) {
if (arr[i] > arr[j]) {
a = arr[i];
arr[i] = arr[j];
arr[j] = a;
}
}
}
System.out.println("Smallest: "+arr[0]);
System.out.println("Largest: "+arr[count-1]);
System.out.println("Second Smallest: "+arr[1]);
System.out.println("Second Largest: "+arr[count-2]);
}
}

OUTPUT:-
PROGRAM NO:- 11
Aim :- Develop two different classes that implement this interface. One using
an array and another using a linked list.

-STACK OPERATION INTERFACE


import java.io.*;
public interface stackoperation {
public void push(int i);
public void pop();
}
-USING STACK
public class Astack implements stackoperation{

int stack[];
int top;
Astack()
{ stack=new int[10];
top=0; }
public void push(int item) {
if(stack[top]==10)
System.out.println("overflow");
Else {
stack[++top]=item;
System.out.println("item pushed"); } }
public void pop() {
if(stack[top]<=0)
System.out.println("underflow");
Else {
stack[top]=top--;
System.out.println("item popped"); } }
public void display() {
for(int i=1;i<=top;i++)
System.out.println("element:"+stack[i]); } }
import java.io.DataInputStream;
import java.io.IOException;

- USING LINKED LIST


public class liststack implements stackoperation {
node top,q;
int count;
public void push(int i) {
node n=new node(i);
n.link=top;
top=n;
count++; }
public void pop()
{ if(top==null)
System.out.println("under flow");
Else {
int
p=top.data;
top=top.link;
count--;
System.out.println("popped element:"+p); } }
void display() {
for(q=top;q!=null;q=q.link) {
System.out.println("the elements are:"+q.data); }}
class node {
int data;
node link;
node(int i) {
data=i;
link=null; } } }
class sample
{
public static void main(String args[])throws IOException {
int ch,x=1,p=0,t=0;
DataInputStream in=new DataInputStream(System.in);
Do {
Try {
System.out.println(" ");
System.out.println("1.Arraystack 2.liststack
3.exit"); System.out.println(" ");
System.out.println("enter ur choice:");
int c=Integer.parseInt(in.readLine());
Astack s=new Astack();
switch(c) {
case 1:
do {
if(p==1)
break;
System.out.println("ARRAY STACK");
System.out.println("1.push 2.pop 3.display 4.exit");
System.out.println("enter ur choice:");
ch=Integer.parseInt(in.readLine());
case 1:System.out switch(ch) {
. println("enter the value to push:");
int
i=Integer.parseInt(in.readLine());
s.push(i);
break;
System.out.println("ARRAY STACK");
System.out.println("1.push 2.pop 3.display 4.exit");
System.out.println("enter ur choice:");
ch=Integer.parseInt(in.readLine());

switch(ch){
case 1:
System.out.println("enter the value to push:");
int i=Integer.parseInt(in.readLine());
s.push(i);
break;
case 2:
s.pop();
break;
case 3:
System.out.println("the elements are:");
s.display();
break;
case 4:
p=1;
continue; }
} while(x!=0);
break;
case 2:
liststack l=new liststack();
do {
if(t==1)
break;
System.out.println("LIST STACK:");
System.out.println("1.push 2.pop 3.display 4.exit");
System.out.println("enter your choice:");
ch=Integer.parseInt(in.readLine());
switch(ch) {
case 1:
Stak;
case 2:
l.pop();
break;
case 3:
l.display();
break;
case 4:
t=1;
continue; } }
while(x!=0);
break;
case 3:
System.exit(0); }}
catch(IOException e) {
System.out.println("io error"); } }
while(x!=0); } }
System.out.println("enter the value for push:");
int a=Integer.parseInt(in.readLine());
l.push(a);
bString s=e.getActionCommand();
if(s.equals("1")) {
if(z==0) {
jtx.setText(jtx.getText()+"1"); }
else {
jtx.setText("");
jtx.setText(jtx.getText()+"1");
z=0; } }
if(s.equals("2")) {
if(z==0) {
jtx.setText(jtx.getText()+"2"); }
else {
jtx.setText("");
jtx.setText(jtx.getText()+"2");
z=0; } }
if(s.equals("3")) {
if(z==0) {
jtx.setText(jtx.getText()+"3"); }
else {
jtx.setText("");
jtx.setText(jtx.getText()+"3");
z=0; } }
if(s.equals("4")) {
if(z==0) {
jtx.setText(jtx.getText()+"4"); }
else {
jtx.setText("");
jtx.setText(jtx.getText()+"4");
z=0; } }
if(s.equals("5")) {
if(z==0) {
jtx.setText(jtx.getText()+"5"); }
else {
jtx.setText("");
jtx.setText(jtx.getText()+"5");
z=0; } }
if(s.equals("6")) {
if(z==0) {
jtx.setText(jtx.getText()+"6"); }
else {
jtx.setText("");
jtx.setText(jtx.getText()+"6");
z=0; } }
if(s.equals("7")) {
if(z==0) {
jtx.setText(jtx.getText()+"7"); }
else {
jtx.setText("");
jtx.setText(jtx.getText()+"7");
z=0; } }
if(s.equals("8")) {
if(z==0) {
jtx.setText(jtx.getText()+"8"); }
else {
jtx.setText("");
jtx.setText(jtx.getText()+"8");
z=0; } }
if(s.equals("9")) {
if(z==0) {
jtx.setText(jtx.getText()+"9"); }
else {
jtx.setText("");
jtx.setText(jtx.getText()+"9");
z=0; } }
if(s.equals("0")) {
if(z==0) {
jtx.setText(jtx.getText()+"0"); }
else {
jtx.setText("");
jtx.setText(jtx.getText()+"0");
z=0; } }
if(s.equals("AC")) {
jtx.setText("");
x=0; y=0; z=0; }

OUTPUT :-
PROGRAM NO:- 12
Aim :- Develop a scientific calculator using event driven
programming.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

public class scientific extends JFrame implements ActionListener


{
JTextField jtx;
double temp,temp1,result,a;
static double m1,m2;
int k=1,x=0,y=0,z=0;
char ch;
JButton
one,two,three,four,five,six,seven,eight,nine,zero,clr,pow2,pow3;
JButton
plus,min,div,lg,rec,mul,eq,plmi,poin,mr,mc,mp,mm,sqrt,sin,cos,tan;
Container cont;
JPanel textPanel,buttonpanel;
scientific()
{
cont=getContentPane();
cont.setLayout(new BorderLayout());
JPanel textpanel=new JPanel();
Font font=new Font("Arial",Font.PLAIN,18);
jtx=new JTextField(25);
jtx.setFont(font);
jtx.setHorizontalAlignment(SwingConstants.RIGHT);
jtx.addKeyListener(new KeyAdapter()
{
public void keyTyped(KeyEvent keyevent)
{
char c=keyevent.getKeyChar();
if(c>='0' && c<='9'){ }
else
{ keyevent.consume(); }
}
});
textpanel.add(jtx);
buttonpanel=new JPanel();
buttonpanel.setLayout(new GridLayout(5,6));
boolean t=true;

sin=new JButton("SIN");
buttonpanel.add(sin);
sin.addActionListener(this);
mr=new JButton("MR");
buttonpanel.add(mr);
mr.addActionListener(this);
seven=new JButton("7");
buttonpanel.add(seven);
seven.addActionListener(this);
eight=new JButton("8");
buttonpanel.add(eight);
eight.addActionListener(this);
nine=new JButton("9");
buttonpanel.add(nine);
nine.addActionListener(this);
clr=new JButton("AC");
buttonpanel.add(clr);
clr.addActionListener(this);

cos=new JButton("COS");
buttonpanel.add(cos);
cos.addActionListener(this);
mc=new JButton("MC");
buttonpanel.add(mc);
mc.addActionListener(this);
four=new JButton("4");
buttonpanel.add(four);
four.addActionListener(this);
five=new JButton("5");
buttonpanel.add(five);
five.addActionListener(this);
six=new JButton("6");
buttonpanel.add(six);
six.addActionListener(this);
mul=new JButton("*");
buttonpanel.add(mul);
mul.addActionListener(this);

tan=new JButton("TAN");
buttonpanel.add(tan);
tan.addActionListener(this);
mp=new JButton("M+");
buttonpanel.add(mp);
mp.addActionListener(this);
one=new JButton("1");
buttonpanel.add(one);
one.addActionListener(this);
two=new JButton("2");
buttonpanel.add(two);
two.addActionListener(this);
three=new JButton("3");
buttonpanel.add(three);
three.addActionListener(this);
min=new JButton("-");
buttonpanel.add(min);
min.addActionListener(this);

pow2=new JButton("x^2");
buttonpanel.add(pow2);
pow2.addActionListener(this);
mm=new JButton("M-");
buttonpanel.add(mm);
mm.addActionListener(this);
zero=new JButton("0");
buttonpanel.add(zero);
zero.addActionListener(this);
plmi=new JButton("+/-");
buttonpanel.add(plmi);
plmi.addActionListener(this);
poin=new JButton(".");
buttonpanel.add(poin);
poin.addActionListener(this);
plus=new JButton("+");
buttonpanel.add(plus);
plus.addActionListener(this);

pow3=new JButton("x^3");
buttonpanel.add(pow3);
pow3.addActionListener(this);
rec=new JButton("1/x");
buttonpanel.add(rec);
rec.addActionListener(this);
sqrt=new JButton("Sqrt");
buttonpanel.add(sqrt);
sqrt.addActionListener(this);
lg=new JButton("log");
buttonpanel.add(lg);
lg.addActionListener(this);
div=new JButton("/");
div.addActionListener(this);
buttonpanel.add(div);
eq=new JButton("=");
buttonpanel.add(eq);
eq.addActionListener(this);

cont.add("Center",buttonpanel);
cont.add("North",textpanel);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e)
{
jtx.setText("");
jtx.setText(jtx.getText() + a);
}
}
if(s.equals("x^3"))
{
if(jtx.getText().equals(""))
{
jtx.setText("");
}
jtx.setText("");
temp=0;
ch='+';
}
else
{
temp=Double.parseDouble(jtx.getText());
jtx.setText("");
ch='+';
y=0;
x=0;
}
jtx.requestFocus();
}
if(s.equals("-"))
{
if(jtx.getText().equals(""))
{
jtx.setText("");
temp=0;
ch='-';
}
else
{ x=
0;
y=0;
temp=Double.parseDouble(jtx.getText());
jtx.setText("");
ch='-';
}
jtx.requestFocus();
}
if(s.equals("/"))
{
if(jtx.getText().equals(""))
{
jtx.setText("");
temp=1;
ch='/';
}
else
{ x=
0;
y=0;
temp=Double.parseDouble(jtx.getText());
ch='/';
jtx.setText("");
}
jtx.requestFocus();
}
if(s.equals("*"))
{
if(jtx.getText().equals(""))
{
jtx.setText("");
temp=1;
ch='*';
}
else
{
x=0; y=0;
temp=Double.parseDouble(jtx.getText());
ch='*';
jtx.setText("");
}
jtx.requestFocus();
}
if(s.equals("MC"))
{ m1=
0;
jtx.setText("");
}
if(s.equals("MR"))
{
jtx.setText("");
jtx.setText(jtx.getText() + m1);
}
if(s.equals("M+"))
{
if(k==1)
{
m1=Double.parseDouble(jtx.getText());
k++;
}
else
{
m1+=Double.parseDouble(jtx.getText());
jtx.setText(""+m1);
}
}
if(s.equals("M-"))
{
if(k==1)
{
m1=Double.parseDouble(jtx.getText());
k++;
}
else
{
m1-=Double.parseDouble(jtx.getText());
jtx.setText(""+m1);
}
}
if(s.equals("Sqrt"))
{
if(jtx.getText().equals(""))
{
jtx.setText("");
}

else
{
a=Math.sqrt(Double.parseDouble(jtx.getText()));
jtx.setText("");
jtx.setText(jtx.getText() + a);
}
}
if(s.equals("SIN"))
{
if(jtx.getText().equals(""))
{
jtx.setText("");
}
else
{
a=Math.sin(Double.parseDouble(jtx.getText()));
jtx.setText("");
jtx.setText(jtx.getText() + a);
}
}
if(s.equals("COS"))
{
if(jtx.getText().equals(""))
{
jtx.setText("");
}
else
{
a=Math.cos(Double.parseDouble(jtx.getText()));
jtx.setText("");
jtx.setText(jtx.getText() + a);
}
}
if(s.equals("TAN"))
{
if(jtx.getText().equals(""))
{
jtx.setText("");
}
else
{
a=Math.tan(Double.parseDouble(jtx.getText()));
jtx.setText("");
jtx.setText(jtx.getText() + a);
}
}
if(s.equals("="))
{
if(jtx.getText().equals(""))
{
jtx.setText("");
}
else
{
temp1 = Double.parseDouble(jtx.getText());
switch(ch)
{
case '+':
result=temp+temp1;
break;
case '-':
result=temp-temp1;
break;else
{
a=Math.pow(Double.parseDouble(jtx.getText()),3);
jtx.setText("");
jtx.setText(jtx.getText() + a);
}
}
if(s.equals("+/-"))
{
if(x==0)
{
jtx.setText("-"+jtx.getText());
x=1;
}
else
{
jtx.setText(jtx.getText());
}
}
if(s.equals("."))
{
if(y==0)
{
jtx.setText(jtx.getText()+".");
y=1;
}
else
{
jtx.setText(jtx.getText());
}
}
if(s.equals("+"))
{
if(jtx.getText().equals(""))
{
case '/':
result=temp/temp1;
break;
case '*':
result=temp*temp1;
break; }
jtx.setText("");
jtx.setText(jtx.getText() + result);
z=1;
}
}
jtx.requestFocus();
}
public static void main(String args[])
{
scientific n=new scientific();
n.setTitle("CALCULATOR");
n.setSize(370,250);
n.setResizable(false);
n.setVisible(true);
}
}

OUTPUT :-

SQUARE ROOT OF 3 = 1.7320508075688772


PROGRAM NO:- 13
Aim :- Develop a template for linked list class along with its members
in Java.

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;
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)
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();
break;
case 4:
p2=1;
continue;
}
}while(c!=0);
break;
case 3:
do{ if(p3==1)br
eak;
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);
}
}

OUTPUT :-
PROGRAM NO:- 14
Aim :- Develop a simple paint like program that can draw basic graphical
primitives
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class SimplePaint {


public static void main(String[] args) {
SwingUtilities.invokeLater(() -> createAndShowGUI());
}

private static void createAndShowGUI() {


JFrame frame = new JFrame("Simple Paint");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

DrawPanel drawPanel = new DrawPanel();


frame.getContentPane().add(drawPanel, BorderLayout.CENTER);

JButton lineButton = new JButton("Line");


lineButton.addActionListener(e -> drawPanel.setCurrentAction(DrawPanel.Action.LINE));

JButton rectangleButton = new JButton("Rectangle");


rectangleButton.addActionListener(e -> drawPanel.setCurrentAction(DrawPanel.Action.RECTANGLE));

JButton circleButton = new JButton("Circle");


circleButton.addActionListener(e -> drawPanel.setCurrentAction(DrawPanel.Action.CIRCLE));

JPanel buttonPanel = new JPanel();


buttonPanel.add(lineButton);
buttonPanel.add(rectangleButton);
buttonPanel.add(circleButton);
frame.getContentPane().add(buttonPanel, BorderLayout.SOUTH);
frame.setSize(600, 400);
frame.setVisible(true);
}
}

class DrawPanel extends JPanel {


enum Action { LINE, RECTANGLE, CIRCLE }
private Action currentAction = Action.LINE;
private Point startPoint;
private Point endPoint;

public DrawPanel() {
setBackground(Color.WHITE);

addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
startPoint = e.getPoint();
}

public void mouseReleased(MouseEvent e) {


endPoint = e.getPoint();
repaint();
}
});
}

public void setCurrentAction(Action action) {


currentAction = action;
}

protected void paintComponent(Graphics g) {


super.paintComponent(g);
if (startPoint != null && endPoint != null) {
switch (currentAction) {
case LINE:
g.drawLine(startPoint.x, startPoint.y, endPoint.x, endPoint.y);
break;
case RECTANGLE:
int width = Math.abs(endPoint.x - startPoint.x);
int height = Math.abs(endPoint.y - startPoint.y);
int x = Math.min(startPoint.x, endPoint.x);
int y = Math.min(startPoint.y, endPoint.y);
g.drawRect(x, y, width, height);
break;
case CIRCLE:
width = Math.abs(endPoint.x - startPoint.x);
height = Math.abs(endPoint.y - startPoint.y);
x = Math.min(startPoint.x, endPoint.x);
y = Math.min(startPoint.y, endPoint.y);
g.drawOval(x, y, width, height);
break;
}
}
}
}
PROGRAM NO:- 15
Aim :- Write a program to insert and view data using Servlets.

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Secured Password</title>
</head>
<body>
<form action="Auth" method ="post">
username : <input type="text" name="txtUnm"/><br>
Password : <input type="password" name="txtPwd"/><br>
<input type="submit" value="login"/><br>
</form>
</body>
</html>

OUTPUT:-

You might also like