You are on page 1of 99

EXP.

NO:-01 PRELAB EXERCISE:-

BOOKDEMO:-

import java.lang.*;
import java.util.*;
class Book
{
String BKname;
int BKid;
String BKauthor;
Book(String name,int id,String author)
{
BKname = name;
BKid =id;
BKauthor = author;
}
void BKupdatedetails(String name,int id,String author)
{
BKname = name;
BKid =id;
BKauthor = author;
}
void BKdisplay()
{
System.out.println("BOOK NAME :"+BKname);
System.out.println("BOOK ID :"+BKid);
System.out.println("BOOK AUTHOR :"+BKauthor);
}
}
class BookDemo
{
public static void main(String arg[])
{
Book ob=new Book("the yogi",111,"baba");
ob.BKdisplay();
ob.BKupdatedetails("titanic",222,"cameroon james");
System.out.println("the updated details");
ob.BKdisplay();
}
}

E:\java programing>javac BookDemo.java


E:\java programing>java BookDemo
BOOK NAME :the yogi
BOOK ID :111
BOOK AUTHOR :baba
Updated details are :
BOOK NAME :titanic
BOOK ID :222
BOOK AUTHOR :cameroon james
EXP.NO:-01 LAB EXERCISE:-

import java.lang.*;
import java.util.*;
class Point
{
double x,y;
Point()
{
x=y=0;
}
Point(double a,double b)
{
x=a;y=b;
}
Point(Point l)
{
x=l.x;
y=l.y;
}
double Finddistance(double a,double b)
{
return (Math.sqrt((x-a)*(x-a)+(y-b)*(y-b)));
}
double Finddistance(Point l)
{
return (Math.sqrt((x-l.x)*(x-l.x)+(y-l.y)*(y-l.y)));
}
void display()
{
System.out.println("("+x+ ","+y+ ")");
}
public static void main(String args[])
{
Point p1=new Point(3.25,7.89);
Point p2=new Point(5.37,18.12);
Point p3=new Point(p2);
p1.display();
p2.display();
p3.display();
double c=p1.Finddistance(7.9,16.25);
System.out.println("distance between given points and p1 is:"+c);
c=p1.Finddistance(p3);
System.out.println("distance between p1 and p3 is:"+c);
}
}

E:\java programing>javac Point.java


E:\java programing>java Point
(3.25,7.89)
(5.37,18.12)
(5.37,18.12)
distance between given points and p1 is:9.566195691078036
distance between p1 and p3 is:10.447358517826409
EXP.NO:-02 PRELAB EXERCISE:-

SHAPE2D:-
import java.lang.*;
import java.util.*;
abstract class Shape2d
{
double x,y;
Shape2d(double a,double b)
{
x=a;y=b;
}
abstract double area();
abstract void display();
}
class Rectangle extends Shape2d
{
Rectangle(double a,double b)
{
super(a,b);
}
double area()
{
return(x*y);
}
void display()
{
System.out.println("length="+x+"breadth="+y+"Area of rectangle="+area());
}
}
class Triangle extends Shape2d
{
Triangle(double a,double b)
{
super(a,b);
}
double area()
{
return(0.5*x*y);
}
void display()
{
System.out.println("length="+x+"breadth="+y+"Area of triangle="+area());
}
}
class Shape2dDemo
{
public static void main(String args[])
{
Shape2d s=new Rectangle(1,2);
s.display();
s=new Triangle(1,2);
s.display();
}
}

E:\java programing>javac Shape2dDemo.java


E:\java programing>java Shape2dDemo
length=1.0breadth=2.0Area of rectangle=2.0
length=1.0breadth=2.0Area of triangle=1.0
EXP.NO:-02 LAB EXERCISE:-

import java.lang.*;
import java.util.*;
class Account
{
protected double balance;
protected int accnumber;
Account(int acn,double bal)
{
balance= bal;
accnumber=acn;
}
}

class SBAccount extends Account


{
SBAccount(int acno,double init_bal)
{
super(acno,init_bal);
}
void deposit(double amount)
{
if(amount>0)
{
balance+=amount;
System.out.println("current balance="+balance+"amount deposited="+amount);
}
}
void withdraw(double amount)
{
if((balance-amount)>1000)
{
balance-=amount;
System.out.println("current balance="+balance+"amount withdrawed="+amount);
}
else
System.out.println("insufficient balance found "+"current balance="+balance+"amount
withdraw request="+amount);
}
void calc_interest()
{
balance+=(0.04*balance);
System.out.println("current balance with one year interest="+balance);
}
}

class Customer
{
int custid;String name,address;
SBAccount m;
Customer(int id,String cname,String caddress,int accno,double initialbalance)
{
custid=id;
name=cname;
address=caddress;
m=new SBAccount(accno,initialbalance);
System.out.println("custid="+id+"\n name="+cname+"\n address="+caddress + "\n
accountno=" +accno +"\n balance="+initialbalance);
}
void transaction(int a)
{
Scanner s= new Scanner(System.in);
switch(a)
{
case 1:
System.out.println("enter the amount=");
a=s.nextInt();
m.deposit(a);
break;
case 2:
System.out.println("enter the amount=");
a=s.nextInt();
m.withdraw(a);
break;
case 3:
m.calc_interest();
break;
}
}
}

class BankDemo
{

public static void main(String args[])


{
Scanner s= new Scanner(System.in);
int i=0;
Customer c=new Customer(1,"harry","12,herbert town,mars",221003116,50000.00);
while(i!=1)
{
System.out.println("enter 1 for deposit ,\n enter 2 for withdraw,\n enter 3 for calculating
interest ,\n enter 4 for exit :");
int b=s.nextInt();
if(b==4)
{
i=1;
System.out.println("visit again");
}
else
c.transaction(b);
}
}
}

E:\java programing>javac BankDemo.java


E:\java programing>java BankDemo
custid=1
name=harry
address=12,herbert town,mars
accountno=221003116
balance=50000.0
enter 1 for deposit ,
enter 2 for withdraw,
enter 3 for calculating interest ,
enter 4 for exit :
1
enter the amount=
500
current balance=50500.0amount deposited=500.0
enter 1 for deposit ,
enter 2 for withdraw,
enter 3 for calculating interest ,
enter 4 for exit :
2
enter the amount=
300
current balance=50200.0amount withdrawed=300.0
enter 1 for deposit ,
enter 2 for withdraw,
enter 3 for calculating interest ,
enter 4 for exit :
3
current balance with one year interest=52208.0
enter 1 for deposit ,
enter 2 for withdraw,
enter 3 for calculating interest ,
enter 4 for exit :
4
visit again
EXP.NO:-03 PRELAB EXERCISE:-

package shape2d;
import java.lang.*;
import java.util.*;
public interface twod
{
double area();
double perimeter();
}

package shape2d;
import java.lang.*;
import java.util.*;
public class Circle implements twod
{
double r;
public Circle(double a)
{
r=a;
}
public double area()
{
return (3.14*r*r);
}
public double perimeter()
{
return (2*3.14*r);
}
}

package shape2d;
import java.lang.*;
import java.util.*;
public class Rectangle implements twod
{
double l,br;
public Rectangle(double a,double b)
{
l=a;br=b;
}
public double area()
{
return (l*br);
}
public double perimeter()
{
return (2*(l+br));
}
}

package shape2d;
import java.lang.*;
import java.util.*;
public class Square implements twod
{
double side;
public Square(double x)
{
side=x;
}
public double area()
{
return (side*side);
}
public double perimeter()
{
return (4*side);
}
}

import java.lang.*;
import java.util.*;
import shape2d.*;
class ShapeDemo
{
public static void main(String args[])
{
Circle f=new Circle(1.0);
System.out.println("Area of Circle="+f.area());
System.out.println("Perimeter of Circle="+f.perimeter());
Square g=new Square(2.0);
System.out.println("Area of Square="+g.area());
System.out.println("Perimeter of Square ="+g.perimeter());
Rectangle c=new Rectangle(1.0,2.0);
System.out.println("Area of Rectangle="+c.area());
System.out.println("Perimeter of Rectangle="+c.perimeter());
}
}

E:\java programing>javac shape2d\twod.java


E:\java programing>javac shape2d\Square.java
E:\java programing>javac shape2d\Rectangle.java
E:\java programing>javac shape2d\Circle.java
E:\java programing>javac ShapeDemo.java
E:\java programing>java ShapeDemo
Area of Circle=3.14
Perimeter of Circle=6.28
Area of Square=4.0
Perimeter of Square =8.0
Area of Rectangle=2.0
Perimeter of Rectangle=6.0
EXP.NO:-03 LAB EXERCISE:-

package pkbanking.pkinterface;
import java.lang.*;
import java.util.*;
public interface InterestRate
{
double sbrate=0.04;
}

package pkbanking.pkinterface;
import java.lang.*;
import java.util.*;
public interface Transaction
{
double min_balance=500.0;
void withdraw(double a);
public void deposit(double a);
}

package pkaccount;
import java.lang.*;
import java.util.*;
abstract public class Account
{
protected int accnumber;
protected double balance;
public Account(int a,double b)
{
accnumber=a;
balance=b;
}
}

package pkaccount.sb;
import java.lang.*;
import pkaccount.*;
import pkbanking.pkinterface.*;
import java.util.*;
public class SBAccount extends Account implements Transaction,InterestRate
{
public SBAccount(int an,double ib)
{
super(an,ib);
}
public void deposit(double amount)
{
if(amount>0)
{
balance+=amount;
System.out.println("current balance="+balance+"amount deposited="+amount);
}
}

public void withdraw(double amount)


{
if((balance-amount)>min_balance)
{
balance-=amount;
System.out.println("current balance="+balance+"amount withdrawed="+amount);
}
else
System.out.println("insufficient balance found "+"current balance="+balance+"amount
withdraw request="+amount);
}
public void calc_interest()
{
balance+=(sbrate*balance);
System.out.println("current balance with one year interest="+balance);
}
}

package pkcustomer;
import pkaccount.sb.*;
import java.lang.*;
import java.util.*;
public class Customer
{
int custid;
String name,address;
SBAccount m;
public Customer(int id,String cname,String caddress,int accno,double initialbalance)
{
custid=id;
name=cname;
address=caddress;
m=new SBAccount(accno,initialbalance);
System.out.println("custid="+id+"\n name="+cname+"\n address="+caddress + "\n
accountno=" +accno +"\n balance="+initialbalance);
}
public void transaction(int a)
{
Scanner s= new Scanner(System.in);
switch(a)
{
case 1:
System.out.println("enter the amount=");
a=s.nextInt();
m.deposit(a);
break;
case 2:
System.out.println("enter the amount=");
a=s.nextInt();
m.withdraw(a);
break;
case 3:
m.calc_interest();
break;
}
}
}

import java.lang.*;
import pkcustomer.*;
import java.util.*;
class BankDemo
{
public static void main(String args[])
{
Scanner s= new Scanner(System.in);
int i=0;
Customer c=new Customer(1,"harry","12,herbert town,mars",221003116,50000.00);
while(i!=1)
{
System.out.println("enter 1 for deposit ,\n enter 2 for withdraw,\n enter 3 for calculating
interest ,\n enter 4 for exit :");
int b=s.nextInt();
if(b==4)
{
i=1;
System.out.println("visit again");
}
else
c.transaction(b);
}
}
}

E:\java programing>javac pkbanking\pkinterface\InterestRate.java


E:\java programing>javac pkbanking\pkinterface\Transaction.java
E:\java programing>javac pkaccount\Account.java
E:\java programing>javac pkaccount\sb\SBAccount.java
E:\java programing>javac pkcustomer\Customer.java
E:\java programing>javac BankDemo.java
E:\java programing>java BankDemo
custid=1
name=harry
address=12,herbert town,mars
accountno=221003116
balance=50000.0
enter 1 for deposit ,
enter 2 for withdraw,
enter 3 for calculating interest ,
enter 4 for exit :
1
enter the amount=
500
current balance=50500.0amount deposited=500.0
enter 1 for deposit ,
enter 2 for withdraw,
enter 3 for calculating interest ,
enter 4 for exit :
2
enter the amount=
300
current balance=50200.0amount withdrawed=300.0
enter 1 for deposit ,
enter 2 for withdraw,
enter 3 for calculating interest ,
enter 4 for exit :
3
current balance with one year interest=52208.0
enter 1 for deposit ,
enter 2 for withdraw,
enter 3 for calculating interest ,
enter 4 for exit :
4
visit again
EXP.NO:-04 PRELAB EXERCISE:-
import java.io.*;
import java.lang.*;
import java.util.*;

class Book
{
String BKauthor;
String BKtitle;
double BKprice;
String BKpublisher;
int stockposition;
Book(String BKauthor,String BKtitle,double BKprice,String BKpublisher,int stockposition)
{
this.BKauthor=BKauthor;
this.BKtitle=BKtitle;
this.BKprice=BKprice;
this.BKpublisher=BKpublisher;
this.stockposition=stockposition;
}
int StockPos()
{return stockposition;}
String Author()
{return BKauthor;}
String Title()
{return BKtitle;}
double Price()
{return BKprice;}
void display()
{
System.out.println("\nBOOK AUTHOR :"+BKauthor);
System.out.println("BOOK TITLE :"+BKtitle);
System.out.println("BOOK PRICE :"+BKprice+ "rupees");
System.out.println("BOOK PUBLISHER :"+BKpublisher);
System.out.println("BOOK STOCK POSITION :"+stockposition+" no.s\n");
}
}
BOOKDEMO
class BookDemo
{
public static void main(String arg[])
{
try {
int i,y=0,z;Book ob[]=new Book[5];char c;String m,n;
DataInputStream obe=new DataInputStream(System.in);Scanner s=new Scanner(System.in);
ob[0]=new Book("Stephen Hawking","The Nature of Space and Time",1500.00,"Princeton
University Press",1);
ob[1]=new Book("Mazidi","8051microcontroller",600.00,"Dorling Kindersley",4);
ob[2]=new Book("Ali Bahrami","OOSD",300.00,"Tata McGraw Hill",10);
ob[3]=new Book("Rabindranath Tagore","Gitanjali",800.00,"Scribner",8);
ob[4]=new Book("Rabindranath Tagore","The Heart of God",1000.00,"Tuttle Publishing",3);
System.out.println("\tDetails of the books are :\n ");
for(i=0;i<5;i++)
{
ob[i].display();
}
do{
System.out.println("Enter the Author and Title of the Book : ");
m=obe.readLine();
n=obe.readLine();
for(i=0;i<5;i++)
{
if(ob[i].Author().equals(m))
{
if(ob[i].Title().equals(n))
{
y=1;ob[i].display();
System.out.println("\n\tEnter the number of copies required :");
z=Integer.parseInt(obe.readLine());
if(z<=ob[i].StockPos()&&z>0)
{System.out.println("Total amount for "+z+" copies of "+n+"Book is="+(z*ob[i].Price()));}
else if(z>ob[i].StockPos())
{ System.out.println("Required copies not in stock");}
else if(z<0)
{throw new IllegalArgumentException("Negative Number is Entered"); }
else if(z==0)
{System.out.println("Have you wont need the Book!");}
}
else
y=0;
}
}
if(y==0)System.out.println("Requested Book is not available in the BookShop");
System.out.println("Do You Wish To Buy The Book! [ Press 'n' to come out to the Book Shop
]");
c=s.next().charAt(0);
}while(c!='n');
System.out.println("\tVisit Again");
}
catch(Exception e){System.out.println(e.getMessage());}
}
}

C:\app>javac BookDemo.java
C:\app>java BookDemo
Details of the books are :

BOOK AUTHOR :Stephen Hawking


BOOK TITLE :The Nature of Space and Time
BOOK PRICE :1500.0rupees
BOOK PUBLISHER :Princeton University Press
BOOK STOCK POSITION :1 no.s

BOOK AUTHOR :Mazidi


BOOK TITLE :8051microcontroller
BOOK PRICE :600.0rupees
BOOK PUBLISHER :Dorling Kindersley
BOOK STOCK POSITION :4 no.s

BOOK AUTHOR :Ali Bahrami


BOOK TITLE :OOSD
BOOK PRICE :300.0rupees
BOOK PUBLISHER :Tata McGraw Hill
BOOK STOCK POSITION :10 no.s

BOOK AUTHOR :Rabindranath Tagore


BOOK TITLE :Gitanjali
BOOK PRICE :800.0rupees
BOOK PUBLISHER :Scribner
BOOK STOCK POSITION :8 no.s

BOOK AUTHOR :Rabindranath Tagore


BOOK TITLE :The Heart of God
BOOK PRICE :1000.0rupees
BOOK PUBLISHER :Tuttle Publishing
BOOK STOCK POSITION :3 no.s

Enter the Author and Title of the Book :


Mazidi
8051microcontroller

BOOK AUTHOR :Mazidi


BOOK TITLE :8051microcontroller
BOOK PRICE :600.0rupees
BOOK PUBLISHER :Dorling Kindersley
BOOK STOCK POSITION :4 no.s

Enter the number of copies required :


3
Total amount for 3 copies of 8051microcontrollerBook is=1800.0
Do You Wish To Buy The Book! [ Press 'n' to come out to the Book Shop ]
k
Enter the Author and Title of the Book :
Mazidi
8051microcontroller

BOOK AUTHOR :Mazidi


BOOK TITLE :8051microcontroller
BOOK PRICE :600.0rupees
BOOK PUBLISHER :Dorling Kindersley
BOOK STOCK POSITION :4 no.s

Enter the number of copies required :


5
Required copies not in stock
Do You Wish To Buy The Book! [ Press 'n' to come out to the Book Shop ]
l
Enter the Author and Title of the Book :
Mazidi
8051microcontroller

BOOK AUTHOR :Mazidi


BOOK TITLE :8051microcontroller
BOOK PRICE :600.0rupees
BOOK PUBLISHER :Dorling Kindersley
BOOK STOCK POSITION :4 no.s

Enter the number of copies required :


-1
Negative Number is Entered
EXP.NO:-04 LAB EXERCISE:-

import java.util.*;

class OperationFailedException extends Exception{


String des;

public OperationFailedException(String d) {
des=d;
}
public OperationFailedException(String d,Throwable e) {
des=d;
System.out.println(" " + ((OperationFailedException)e).des);
}
public String toString(){
return ("Output character = "+des ) ;
}
}

class BadOperandException extends Exception{


int op;
public BadOperandException(int op1) {
op=op1;
}
public String toString(){
return ("Output character = "+op) ;
}
}

class BadOperatorException extends Exception{


char opr;
public BadOperatorException(char opr1) {
opr=opr1;
}
public String toString(){
return ("Output character = "+opr) ;
}
}

class main1
{
public static void main(String args[])
{
char s;String s1;
int i,j,res;
Scanner in=new Scanner(System.in);
System.out.println("Enter two operands and operator as input:");
i=in.nextInt();
j=in.nextInt();
s1=in.next();
s= s1.charAt(0);
try
{
if(i>10000&&i<50000)
{
try
{
if(j>500&&j<5000)
{
try{
if(s=='*')
{res=i*j;System.out.println(res);}
else if(s=='+')
{res=i+j;System.out.println(res);}
else if(s=='-')
{res=i-j;System.out.println(res);}
else if(s=='/')
{res=i/j;System.out.println(res);}
else{
OperationFailedException e=new
OperationFailedException("INVALID OPERATOR");
e.initCause(new BadOperatorException(s));
throw e;
}
}catch(OperationFailedException e)
{
System.out.println("Caught:"+e);
System.out.println("Caught:"+e.getCause());
}
}
else{
OperationFailedException e2=new OperationFailedException("INVALID
SECOND OPERAND");
OperationFailedException e1=new OperationFailedException("INVALID
OPERAND",e2);
e1.initCause(new BadOperandException(j));
throw e1;}
}
catch(OperationFailedException f)
{
System.out.println("Caught:"+f);
System.out.println("Caught:"+f.getCause());
}
}
else{
OperationFailedException e2=new OperationFailedException("INVALID FIRST
OPERAND");
OperationFailedException e1=new OperationFailedException("INVALID
OPERAND",e2);
e1.initCause(new BadOperandException(i));
throw e1;}
}
catch(OperationFailedException f)
{
System.out.println("Caught:"+f);
System.out.println("Caught:"+f.getCause());
}
}
}

C:\app>javac main1.java

C:\app>java main1

Enter two operands and operator as input:

20000

1000

20000000
C:\app>java main1

Enter two operands and operator as input:

1000

1000

INVALID FIRST OPERAND

Caught:Output character = INVALID OPERAND

Caught:Output character = 1000

C:\app>java main1

Enter two operands and operator as input:

20000

1000

Caught:Output character = INVALID OPERATOR

Caught:Output character = $

C:\app>java main1

Enter two operands and operator as input:

20000

100

INVALID SECOND OPERAND

Caught:Output character = INVALID OPERAND

Caught:Output character = 100


EXP.NO:-05 PRELAB EXERCISE:-
import java.lang.*;
import java.util.*;

class factorial extends Thread


{
public void run()
{
try
{
System.out.println("FACTORIAL THREAD PRIORITY = "+this.getPriority());
Scanner s= new Scanner(System.in);
System.out.println("status of multab while completing task is:"+this.isAlive());
System.out.println("Enter the limit of factorial: ");
int n=s.nextInt();
int j=1;
for(int i=1;i<=n;i++)
{
j=j*i;
}
System.out.println("factorial of "+n+"is"+j);
Thread.sleep(500);
}
catch(InterruptedException e){}
}
}

class sum extends Thread


{
public void run()
{
System.out.println("SUM THREAD PRIORITY = "+this.getPriority());
try
{
Scanner s= new Scanner(System.in);
System.out.println("Enter the limit of sum of the series: ");
int n=s.nextInt();
int j=0;
for(int i=1;i<=n;i++)
{
j=j+i;
}
System.out.println("sum of the 1 to "+n+" numbers is"+j);
Thread.sleep(500);
}
catch(InterruptedException e){}
}
}

class multab extends Thread


{
public void run()
{
System.out.println("MULTAB THREAD PRIORITY = "+this.getPriority());
try
{
Scanner s= new Scanner(System.in);
System.out.println("Enter the limit of multiplication table: ");
int n=s.nextInt();
System.out.println("Enter the number which has to be multiplied: ");
int k=s.nextInt();
for(int i=1;i<=n;i++)
{
System.out.println(i+"*"+k+"="+(k*i));
Thread.sleep(500);
}
}
catch(InterruptedException e){}
}
}

class ThreadBasic
{
public static void main(String args[]) throws Exception
{
factorial t1=new factorial();
sum t2=new sum();
multab t3=new multab();
t1.setPriority(10);
t2.setPriority(5);
t3.setPriority(2);
t1.start();
t1.join();
System.out.println("status of multab after completing task is:"+t1.isAlive());
t2.start();
t2.join();
t3.start();
}
}

E:\java programing>javac ThreadBasic.java


E:\java programing>java ThreadBasic
FACTORIAL THREAD PRIORITY = 10
status of multab while completing task is:true
Enter the limit of factorial:
5
factorial of 5 is 120
status of multab after completing task is:false
SUM THREAD PRIORITY = 5
Enter the limit of sum of the series:
3
sum of the 1 to 3 numbers is 6
MULTAB THREAD PRIORITY = 2
Enter the limit of multiplication table:
2
Enter the number which has to be multiplied:
3
1*3=3
2*3=6
EXP.NO:-05 LAB EXERCISE:-

import java.util.*;
import java.lang.*;

class Queue
{
int q[],front, rear, size, len,m;
public Queue(int n)
{
size=n;
len = 0;
q = new int[size];
front =rear = -1;
}
public boolean isEmpty()
{
return front == -1;
}
public int size()
{
return len ;
}
public void add(int i)
{
if (rear == -1)
{
front = rear = 0;
q[rear] = i;
}
else if ( rear + 1 < size)
q[++rear] = i;
len++ ;
}
public int remove()
{
if (!isEmpty())
{
len-- ;
m = q[front];
if ( front == rear)
{
front = rear = -1;
}
else
front++;
} return m;
}
synchronized void get() throws InterruptedException
{
while (isEmpty())
{
Thread.sleep(1000);
System.out.println("Queue is empty " + Thread.currentThread().getName() + " is waiting
, size: " + size());
wait();
}
Thread.sleep(1000);
int i = (Integer) remove();
System.out.println("Consumed: " + i);
notify();
}
synchronized void put(int i) throws InterruptedException
{
while (size() == size)
{
Thread.sleep(1000);
System.out.println("Queue is full " + Thread.currentThread().getName() + " is waiting ,
size: " +size());
wait();
}
Thread.sleep(1000);
add(i);
System.out.println("Produced: " + i);
notify();
}
}

class Producer implements Runnable


{
Queue Qobj;
public Producer(Queue obj)
{
this.Qobj = obj;
}
public void run()
{
int counter = 0;
while (true)
{
try{ Qobj.put(counter++); }catch(Exception e){}
}
}
}

class Consumer implements Runnable


{
Queue Qobj;
public Consumer(Queue obj)
{
this.Qobj = obj;
}
public void run()
{
while (true)
{
try{ Qobj.get(); }catch(Exception e){}
}
}
}

public class ProducerConsumer


{
public static void main(String[] args)
{
int QSize = 5;
Queue q=new Queue(QSize);
new Thread(new Producer(q), "Producer").start();
new Thread(new Consumer(q), "Consumer").start();
}
}
E:\java programing>javac ProducerConsumer.java
E:\java programing>java ProducerConsumer
Produced: 0
Produced: 1
Produced: 2
Produced: 3
Produced: 4
Queue is full Producer is waiting , size: 5
Consumed: 0
Consumed: 1
Consumed: 2
Consumed: 3
Consumed: 4
Queue is empty Consumer is waiting , size: 0
Produced: 5
Produced: 6
Produced: 7
Produced: 8
Produced: 9
Queue is full Producer is waiting , size: 5
Consumed: 5
Consumed: 6
Consumed: 7
Consumed: 8
Consumed: 9
Queue is empty Consumer is waiting , size: 0
Produced: 10
Produced: 11
Produced: 12
Produced: 13
Produced: 14
Queue is full Producer is waiting , size: 5
Consumed: 10
.
.
.
EXP.NO:-06 PRELAB EXERCISE:-

import java.util.*;
import java.lang.*;
import java.io.*;
class ArrayList11
{
public static void main(String a[])
{
ArrayList<String> a1=new ArrayList<String>();
a1.add("hello");
a1.add("photons");
a1.add("sorry");
a1.add("space");
a1.add("comics");
ArrayList11 k=new ArrayList11();
System.out.println("Original String ArrayList=\t"+a1);
k.capitalizePlurals(a1);
System.out.println("ArrayList after capitalizePlurals=\t"+a1);
k.removePlurals(a1);
System.out.println("ArrayList after removing Plural words=\t"+a1);
k.reverse(a1);
System.out.println("ArrayList after reversing the order of the elements in words=\t"+a1);
}
public void reverse(ArrayList<String> a1)
{
Collections.reverse(a1);
}
public void capitalizePlurals(ArrayList<String> a1)
{
for(int i=0;i<a1.size();i++)
{
String s=a1.get(i);
if(s.charAt(s.length()-1)=='s')
{
a1.set(i,s.toUpperCase());
}
}
}
public void removePlurals(ArrayList<String> a1)
{
for(int i=0;i<a1.size();i++)
{
String s=a1.get(i);
if((s.charAt(s.length()-1)=='s' )||(s.charAt(s.length()-1)=='S'))
a1.remove(i);
}
}
}

E:\java programing>javac ArrayList11.java


E:\java programing>java ArrayList11
Original String ArrayList= [hello, photons, sorry, space, comics]
ArrayList after capitalizePlurals= [hello, PHOTONS, sorry, space, COMICS]
ArrayList after removing Plural words= [hello, sorry, space]
ArrayList after reversing the order of the elements in words= [space, sorry, hello]
EXP.NO:-06 LAB EXERCISE:-

import java.lang.*;
import java.util.*;
class Point
{
double x,y;
Point()
{
x=y=0;
}
Point(double a,double b)
{
x=a;y=b;
}
Point(Point l)
{
x=l.x;
y=l.y;
}
double Finddistance(double a,double b)
{
return (Math.sqrt((x-a)*(x-a)+(y-b)*(y-b)));
}
double Finddistance(Point l)
{
return (Math.sqrt((x-l.x)*(x-l.x)+(y-l.y)*(y-l.y)));
}
void display()
{
System.out.println("("+x+ ","+y+ ")");
}

public static void main(String args[])


{
Point p1=new Point(3.25,7.89);
Point p2=new Point(5.37,18.12);
Point p3=new Point(p2);
Point p4=new Point();
double c=p1.Finddistance(7.9,16.25);
ArrayList<Point>a1=new ArrayList<Point>();
a1.add(p1);
a1.add(p2);
a1.add(p3);
a1.add(p4);
Iterator itr=a1.iterator();
Iterator it=a1.iterator();int i=0;
while(it.hasNext())
{
i++;
Point t1,t2;
t1=(Point)it.next();
t2=(Point)it.next();
System.out.println("p[" +i+"]= ");
t1.display();
System.out.println("p["+(i+1)+"]= ");
t2.display();
double d=t1.Finddistance(t2);
System.out.println("distance between p[" +i+"]"+" and p["+(i+1)+"]"+"points are:"+d);
i++;
}
double d=p2.Finddistance(7.9,16.25);
System.out.println("given points are: ");
p2.display();
System.out.println("distance between given points and p2 is:"+d);
}
}

E:\java programing>javac Point.java


E:\java programing>java Point
p[1]= (3.25,7.89)
p[2]= (5.37,18.12)
distance between p[1] and p[2]points are:10.447358517826409
p[3]= (5.37,18.12)
p[4]= (0.0,0.0)
distance between p[3] and p[4]points are:18.8989761627449
given points are: (5.37,18.12)
distance between given points and p2 is: 3.146076922136521

EXP.NO:-07 PRELAB EXERCISE:-

import java.util.*;
import java.lang.*;
class TREESET
{
public static void main(String a[])
{
TreeSet<String> a1=new TreeSet<String>();
a1.add("hello");
a1.add("photons");
a1.add("sorry");
a1.add("space");
a1.add("comics");
TREESET k=new TREESET();
System.out.println("Original String TREESET=\t"+a1);
k.capitalizePlurals(a1);
k.removePlurals(a1);
k.reverse(a1);
}
public void reverse(TreeSet<String> a1)
{
TreeSet <String>treereverse = new TreeSet<String>();
treereverse = (TreeSet)a1.descendingSet();
System.out.println("TREESET after reversing the order of the elements in
words=\t"+treereverse);
}
public void capitalizePlurals(TreeSet<String> a1)
{
List<String> list = new ArrayList<String>(a1);
for(int i=0;i<list.size();i++)
{
String s=list.get(i);
if(s.charAt(s.length()-1)=='s')
{
list.set(i,s.toUpperCase());
}
}
a1 = new TreeSet<String>(list);
System.out.println("TREESET after capitalizePlurals = "+a1);
}
public void removePlurals(TreeSet<String> a1)
{
List<String> list = new ArrayList<String>(a1);
for(int i=0;i<list.size();i++)
{
String str=list.get(i);
if(str.charAt(str.length()-1)=='s'|| str.charAt(str.length()-1)=='S')
{
a1.remove(str);
}
}
System.out.println("TREESET after removing plurals = "+a1);
}
}
E:\java programing>javac TREESET.java
Note: TREESET.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
E:\java programing>java KOPT
Original String TREESET= [comics, hello, photons, sorry, space]
TREESET after capitalizePlurals = [COMICS, PHOTONS, hello, sorry, space]
TREESET after removing plurals = [hello, sorry, space]
TREESET after reversing the order of the elements in words= [space, sorry, hello]

EXP.NO:-07 LAB EXERCISE:-

import java.util.*;
import java.lang.*;
class point
{
double x,y;
point(double a,double b)
{
x=a;
y=b;
}
double find_distance(point p)
{
double dis,xd,yd;
xd=x-p.x;
yd=y-p.y;
dis=Math.sqrt(xd*xd+yd*yd);
return(dis);
}
void display()
{
System.out.print("("+x+","+y+") ");
}
}

class ComparePts implements Comparator<point>


{
public int compare(point p1,point p2)
{
point org=new point(0,0);
double d1=p1.find_distance(org);
double d2=p2.find_distance(org);
if(d1<d2)return(-1);
if(d1>d2)return(1);
else return(0);
}
}

class HPoint
{
public static void main(String a[])
{
int i;
double x,y,d1;
Scanner s=new Scanner(System.in);
point p[]=new point[10];
HashSet<point> hs=new HashSet<point>();
for(i=0;i<10;i++)
{
System.out.println("Enter x & y for point "+(i+1));
x=s.nextDouble();
y=s.nextDouble();
p[i]=new point(x,y);
hs.add(p[i]);
}
TreeSet<point> ts=new TreeSet<point>(new ComparePts());

Iterator t=hs.iterator();
while(t.hasNext())
{
point pt=(point)t.next();
ts.add(pt);
}
System.out.println("Points in ascending Order:");
Iterator t1=ts.iterator();
while(t1.hasNext())
{
point pt=(point)t1.next();
pt.display();
System.out.println();
}
System.out.println("Distance between every pair:");
Iterator it=hs.iterator();
while(it.hasNext())
{
point t3,t2;
t3=(point)it.next();
t2=(point)it.next();
d1=t3.find_distance(t2);
System.out.print("Distance between the points:");
t3.display();
t2.display();
System.out.println(" = "+d1);
}
}
}

E:\java programing>javac HPoint.java


E:\java programing>java HPoint
Enter x & y for point 1 1 2
Enter x & y for point 2 2 3
Enter x & y for point 3 3 4
Enter x & y for point 4 4 5
Enter x & y for point 5 5 6
Enter x & y for point 6 6 7
Enter x & y for point 7 7 8
Enter x & y for point 8 8 9
Enter x & y for point 9 9 10
Enter x & y for point 10 10 11
Points in ascending Order:
(1.0,2.0)
(2.0,3.0)
(3.0,4.0)
(4.0,5.0)
(5.0,6.0)
(6.0,7.0)
(7.0,8.0)
(8.0,9.0)
(9.0,10.0)
(10.0,11.0)
Distance between every pair:
Distance between the points:(5.0,6.0) (1.0,2.0) = 5.656854249492381
Distance between the points:(2.0,3.0) (7.0,8.0) = 7.0710678118654755
Distance between the points:(3.0,4.0) (6.0,7.0) = 4.242640687119285
Distance between the points:(10.0,11.0) (8.0,9.0) = 2.8284271247461903
Distance between the points:(9.0,10.0) (4.0,5.0) = 7.0710678118654755

EXP.NO:-08 LAB EXERCISE:-

import java.awt.*;
import java.awt.event.*;
import java.applet.*;

public class tank extends Applet implements Runnable,ActionListener


{
int y=200,sf=0,rf=0;
Thread t;
Button b1,b2,b3,b4;

public void init()


{
b1=new Button("Start");
b2=new Button("Stop");
b3=new Button("Resume");
b4=new Button("Suspend");
add(b1);
add(b2);
add(b3);
add(b4);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
}
public void run()
{
for(y=200;y>120;y--)
{
try{Thread.sleep(1000);}
catch(Exception e){}
repaint();
}
}

public void actionPerformed(ActionEvent a)


{
if(a.getSource()==b1)
{
t=new Thread(this);
sf=1;
t.start();
showStatus("Thread started..");
}
if(a.getSource()==b2)
{
if(sf==1)
{
t.stop();
sf=0;
showStatus("Thread stopped..");
}
else
showStatus("Thread not started..");
}
if(a.getSource()==b3)
{
if(rf==1)
{
t.resume();
rf=0;
showStatus("Thread resumed..");
}
else
showStatus("Thread not Suspended...");
}
if(a.getSource()==b4)
{
if(sf==1)
{
t.suspend();
rf=1;
showStatus("Thread suspended..");
}
else
showStatus("Thread not Started....");
}
}
public void paint(Graphics g)
{
g.drawLine(120,120,120,200);
g.drawLine(200,120,200,200);
g.setColor(Color.blue);
g.fillRect(120,y,80,200-y);
}
}

/*<applet code=tank width=750 height=750></applet>*/

E:\java programing>javac tank.java

Note: glow1.java uses or overrides a deprecated API.

Note: Recompile with -Xlint:deprecation for details.


E:\java programing>appletviewer tank.java

Warning: Applet API and AppletViewer are deprecated.

EXP.NO:-09 PRELAB EXERCISE:-


import java.awt.*;

import java.awt.event.*;

public class AwtFrame extends Frame implements FocusListener,ActionListener

TextField tf1,tf2;

Button b1,b2;

String msg="";

public AwtFrame()
{

setTitle("Login Screen");setBackground(Color.cyan);

Label lbl = new Label("SASTRA DEEMED UNIVERSITY",Label.CENTER);

lbl.setBounds(50,30,300,40);

lbl.setFont(new Font("SansSerif", Font.BOLD,20));

add(lbl);

setFont(new Font("SansSerif", Font.BOLD, 10));

Label lb2=new Label("User Name",Label.LEFT);

Label lb3=new Label("PassWord",Label.LEFT);

tf1=new TextField("Enter User Name");

tf1.setForeground(Color.gray);

tf2=new TextField("Enter PassWord");

tf2.setForeground(Color.gray);

b1= new Button("OK");

b2=new Button("CANCEL");

add(lb2);

add(tf1);

add(lb3);

add(tf2);

add(b1);

add(b2);

tf1.setBounds(120,90,170,20);

tf2.setBounds(120,120,170,20);

lb2.setBounds(25,90,90,20);

lb3.setBounds(25,120,90,20);
b1.addActionListener(this);

b2.addActionListener(this);

tf1.addFocusListener(this);

tf2.addFocusListener(this);

b1.setBounds(100,180,80,20);

b2.setBounds(200,180,80,20);

addWindowListener(new WindowAdapter(){

public void windowClosing(WindowEvent e) {System.exit(0);}});

setLayout(null);

setSize(380,300);

setVisible(true);

public void focusGained(FocusEvent fe)

TextField t=(TextField)fe.getSource();

if(t==tf1)

{ tf1.setText(""); }

else

{ tf2.setText("");}

public void focusLost(FocusEvent fe)

}
public void actionPerformed(ActionEvent ae)

Button b =(Button) ae.getSource();

if(b==b1)

String s=tf2.getText();

if(s.length()>=8)

smsg="Login Successful";

else

msg = "Invalid User Name / PassWord";

repaint();

else

tf1.setText("Enter UserName");

tf1.setForeground(Color.gray);

tf2.setText("Enter PassWord");

tf2.setForeground(Color.gray);

msg="";

repaint();

public void paint(Graphics g)

g.drawString(msg,150,250);
}

public static void main(String[] args)

new AwtFrame();

E:\java programing>javac AwtFrame.java

E:\java programing>java AwtFrame

EXP.NO:-09 LAB EXERCISE:-


import java.awt.*;

import java.applet.*;

import java.awt.event.*;

public class student9 extends Frame implements FocusListener,ItemListener

String msg="",csg="";int i;Choice c[]=new Choice[3];String melt,melt1,melt2;

List lst=new List(4,true);boolean isEmpty;boolean isnumberornot;

Label l[]=new Label[12];int qq=0,m=1,n=1,pp=1,mm=1,nn=1;


String lcap[]={"Register No.","Name","Gender","Degree","Branch","Year of Study","Date of
Birth","Hobby","Address","Extra Curricular Activities","E-Mail
Id","B.Tech","M.Tech","CSE","ECE","EEE","You Entered"};

Checkbox h1,h2,h3;

Label p=new Label(" ",Label.CENTER);

Label u=new Label(" ",Label.CENTER);

Label l11=new Label("Student Response Form",Label.CENTER);

Label l7=new Label("",Label.RIGHT);

TextField t1=new TextField(20);

TextField t2=new TextField(20);

TextField t3=new TextField(20);

TextField t4=new TextField(100);

TextArea ta=new TextArea("",100,100,TextArea.SCROLLBARS_BOTH);

CheckboxGroup cbg=new CheckboxGroup();

Checkbox ck1=new Checkbox("Male",false,cbg);

Checkbox ck2=new Checkbox("Female",false,cbg);

TextArea t5=new TextArea("",180,90,TextArea.SCROLLBARS_VERTICAL_ONLY);

Choice branch=new Choice();

Choice degree=new Choice();

Choice yos=new Choice();

public student9()

for(i=0;i<7;i++)

{l[i]=new Label(lcap[i],Label.LEFT);add(l[i]);}

for(i=7;i<11;i++)

{l[i]=new Label(lcap[i],Label.CENTER);add(l[i]);i++;}
for(i=8;i<11;i++)

{l[i]=new Label(lcap[i],Label.LEFT);add(l[i]);i++;}

l[11]=new Label(lcap[16],Label.CENTER);

add(l[11]);

for(i=0;i<3;i++)

{ c[i]=new Choice();add(c[i]);}

add(p);

add(ta);

h1=new Checkbox("Stamp Collection");

h2=new Checkbox("Reading Novels");

h3=new Checkbox("Playing Tennis");

addWindowListener(new myWindowAdapter());

setBackground(Color.cyan);

setForeground(Color.black);

setLayout(null);

add(l11);

lst.add("Tennis");

lst.add("Cricket");

lst.add("Basket Ball");

lst.add("Hockey");

add(t4);

add(h1);add(h2);add(h3);

add(lst);

add(t1);

add(t2);
add(t3);

add(ck1);

add(ck2);

add(branch);

add(degree);

add(yos);

degree.add(lcap[11]);

degree.add(lcap[12]);

for(i=13;i<16;i++)

branch.add(lcap[i]);

yos.add("1");add(u);

yos.add("2");

yos.add("3");

yos.add("4");

l11.setFont(new Font("SansSerif", Font.BOLD+Font.ITALIC, 15));

p.setFont(new Font("SansSerif", Font.BOLD+Font.ITALIC, 15));

u.setFont(new Font("SansSerif", Font.BOLD+Font.ITALIC, 15));

for(int i=1;i<=31;i++)

c[0].add(""+i);

c[1].add("January");

c[1].add("February");

c[1].add("March");t1.addFocusListener(this);

c[1].add("April");t2.addFocusListener(this);

c[1].add("May");t3.addFocusListener(this);

c[1].add("June");t4.addFocusListener(this);
c[1].add("July");degree.addItemListener(this);

c[1].add("August");yos.addItemListener(this);

c[1].add("September");

c[1].add("October");

c[1].add("November");

c[1].add("December");

for(i=1990;i<2002;i++)

c[2].add(""+i);

for(i=0;i<6;i++)

l[i].setBounds(25,(60+(i*30)),90,20);

l[6].setBounds(25,240,90,20);

l[7].setBounds(425,65,100,20);

l[8].setBounds(25,290,90,20);

l[9].setBounds(450,105,150,20);

l[10].setBounds(25,400,90,20);

l[11].setBounds(450,210,90,20);ck1.addFocusListener(this);

l11.setBounds(300,40,280,20);ck2.addFocusListener(this);

lst.setBounds(480,140,150,45);lst.addFocusListener(this);

t1.setBounds(120,60,170,20);

t2.setBounds(120,90,170,20);

t3.setBounds(120,400,170,20);

t4.setBounds(120,275,150,90);

ta.setBounds(480,245,335,170);

ck1.setBounds(120,120,50,20);

ck2.setBounds(170,120,60,20);
degree.setBounds(120,150,70,20);degree.addFocusListener(this);

branch.setBounds(120,180,50,20);branch.addFocusListener(this);

yos.setBounds(120,210,30,20);yos.addFocusListener(this);

c[0].setBounds(120,240,35,20);c[0].addFocusListener(this);

c[1].setBounds(160,240,77,20);c[1].addFocusListener(this);

c[2].setBounds(243,240,50,20);c[2].addFocusListener(this);

h1.setBounds(530,65,105,20);h1.addFocusListener(this);

h2.setBounds(644,65,100,20);h2.addFocusListener(this);

h3.setBounds(750,65,100,20);h3.addFocusListener(this);

p.setBounds(300,520,400,20);

u.setBounds(200,590,400,20);

public void focusGained(FocusEvent ae)

if(ae.getSource()==t4)

if(cbg.getSelectedCheckbox()==null)

msg="Select the Gender";

mm=1;ta.setText("");

}else{

mm=0;}

p.setText(msg);p.setForeground(Color.red);

}
public void focusLost(FocusEvent ae)

if(ae.getSource()==t1)

if(t1.getText().length()!=9)

ta.setText("");

msg="register number should be 9characters!";

m=1; }else{

try{

int kk=Integer.parseInt(t1.getText());isnumberornot=false;

catch(Exception e)

isnumberornot=true;

if(isnumberornot)

msg="Characters should be avoided for RegNo";

else

m=0;

}
}

else if(ae.getSource()==t2)

msg="";isEmpty=t2.getText()==null||t2.getText().trim().length()==0;

if(isEmpty)

ta.setText("");

msg="Name should not be blank";

n=1; }else{n=0;}

else if(ae.getSource()==t4)

msg="";isEmpty=t4.getText()==null||t4.getText().trim().length()==0;

if(isEmpty)

msg="Address should not be blank";

nn=1;ta.setText(""); }else{nn=0;}

else if(ae.getSource()==t3)

msg="";int yo=t3.getText().lastIndexOf("@");

if(!t3.getText().endsWith("@gmail.com"))

msg="Invalid E-Mail ID(@gmail.com not found)";


pp=1;ta.setText(""); }

else

String jo=(t3.getText()).substring(0,yo);

isEmpty=jo==null||jo.trim().length()==0||jo.startsWith(" ");

if(isEmpty)

msg="Invalid E-Mail Id(characters is not present before@ORfirst letter is null)";

pp=1;ta.setText(""); }else{pp=0;}

else

csg="Atlast select the YOU ENTERED TextArea for updation";

u.setText(csg);u.setForeground(Color.red); }

if(mm==0&&nn==0&&pp==0&&qq==0&&m==0&&n==0)

if(cbg.getSelectedCheckbox().getLabel()=="Male")

melt="He";melt1="His";melt2="Shri";

if(cbg.getSelectedCheckbox().getLabel()=="Female")

melt="She";melt1="Her";melt2="Sow";

}
String dob,ptr="",pho[],h="";

pho=lst.getSelectedItems();

for(int i=0;i<pho.length;i++)

{ptr+=pho[i];if(i!=pho.length-1){ptr+=",";}}

dob=c[0].getSelectedItem()+"-"+c[1].getSelectedItem()+"-"+c[2].getSelectedItem();

if(h1.getState()){h+=h1.getLabel();if(h.charAt(0)==',')h=h.substring(1,h.length());}

if(h2.getState()){h+=","+h2.getLabel();if(h.charAt(0)==',')h=h.substring(1,h.length());}

if(h3.getState()){h+=","+h3.getLabel();if(h.charAt(0)==',')h=h.substring(1,h.length());}

ta.append("\n\n"+melt2+" "+t2.getText()+"'s register number is "+t1.getText());

ta.append("\n"+melt+" is studying in "+yos.getSelectedItem()+" year


"+degree.getSelectedItem()+" "+branch.getSelectedItem());

ta.append("\n"+melt+" was born on "+dob);

ta.append("\n"+melt+" is residing at "+t4.getText());

ta.append("\n"+melt1+" E-Mail address is "+t3.getText());

ta.append("\n"+melt+" is interested in "+h);

ta.append("\n"+melt+" plays "+ptr+" well");

msg="student details are submitted!";

csg="";

}p.setText(msg);p.setForeground(Color.red);

public void itemStateChanged(ItemEvent e)

if(e.getItemSelectable()==degree)

if(((Choice)e.getItemSelectable()).getSelectedItem()=="M.Tech")

{yos.remove("3");
yos.remove("4");}

if(((Choice)e.getItemSelectable()).getSelectedItem()=="B.Tech")

{yos.add("3");

yos.add("4");}

public static void main(String g[])

{student9 stu=new student9();

stu.setSize(new Dimension(850,650));

stu.setTitle("Response Form");

stu.setVisible(true);

class myWindowAdapter extends WindowAdapter

{public void windowClosing(WindowEvent we)

System.exit(0);

E:\java programing>javac student9.java

E:\java programing>java student9


EXP.NO:-10 LAB EXERCISE:-
NOTE : CONSECUTIVE ARITHMETIC OPERATIONS CAN ALSO BE
PERFORMED … EG: 1+2*8-1 , 1*2*3/2 , ETC , …

import java.awt.*;

import java.awt.event.*;

public class MyCal4 extends Frame implements ActionListener

char OP=' ',a3,a2;TextField t1;String Str1="";

int i=0,j,k=5;

Button b[]=new Button[24];


double v1=0.0,v2=0.0,a1=0,a4=0,result=0.0,memValue,c,co;

String s[]={"M+","M-","MC","MR","C","CE","<-","Sqrt","1","2","3","+","4","5","6","-
","7","8","9","*","0",".","=","/"};

public MyCal4()

super("Calculator");

setSize(400,600);

setFont(new Font("SansSerif",Font.BOLD,25));

setBackground(Color.yellow);

setLayout(new BorderLayout(5,5));

t1=new TextField("0",10);

t1.setBackground(Color.green);

t1.setForeground(Color.red);

t1.addActionListener(this);

addWindowListener(new WindowAdapter(){

public void windowClosing(WindowEvent e) {System.exit(0);}});

add(t1,BorderLayout.NORTH);

Panel p=new Panel();

p.setLayout(new GridLayout(6,4,10,10));

p.setBackground(Color.yellow);

add(p,BorderLayout.CENTER);

for(int i=0;i<24;i++)

b[i]=new Button(s[i]);

p.add(b[i]);

b[i].addActionListener(this);
b[i].setBackground(Color.cyan);

setVisible(true);

public void actionPerformed(ActionEvent ae)

try{

String str=ae.getActionCommand();

if(str.equals("+")||str.equals("-")||str.equals("*")||str.equals("/"))

v1=Double.parseDouble(t1.getText());

a4=v1;

a3=OP;

if(a3==' ')

a1=a4;

else if(a3=='+')

a1=a1+a4;

else if(a3=='-')

a1=a1-a4;

else if(a3=='*')

a1=a1*a4;

else

a1=a1/a4;

OP=str.charAt(0);

a2=OP;
t1.setText(Str1="");a3=a2;

else if(str.equals("=")||str.equals("M+")||str.equals("M-"))

v1=a1;

v2=Double.parseDouble(t1.getText());

if(OP=='+')

{result=v1+v2;a1=0.0;}

else if(OP=='-')

{result=v1-v2;a1=0.0;}

else if(OP=='*')

{result=v1*v2;a1=0.0;}

else if(OP=='/')

{result=v1/v2;a1=0.0;}

else if(OP==' ')

result=c;

if(v1==0.0)

result=Double.parseDouble(t1.getText());

if(str.equals("="))

t1.setText(""+result);

str=Str1="";v1=v2=0;}

else if(str.equals("M+")||str.equals("M-"))

OP=' ';
if(str.equals("M+"))

{memValue+=result;}

else

{memValue-=result;}

c=result;

result=0;

t1.setText("0");str=Str1="";v1=v2=0;}

else if(str.equals("CE"))

memValue=0;a1=0.0;OP=' ';

t1.setText("0");

str="";

Str1="";

else if(str.equals("<-"))

String Res="";

for(int i=0; i<((t1.getText()).length()-1); i++) Res+=((t1.getText()).charAt(i));

if(Res.equals(""))

{t1.setText("0");Str1="";}

else

t1.setText(Str1=Res);

else if(str.equals("."))
{

if(t1.getText()==" ")

{t1.setText("0.");}

else

{ t1.setText(Str1=t1.getText()+"."); }

else if(str.equals("Sqrt"))

try

double temp=Double.parseDouble(t1.getText());

double tempd=result=Math.sqrt(temp);

String resText=""+tempd;

resText=""+Double.parseDouble(resText.substring(0,resText.length()-2));

t1.setText(resText); }

catch(ArithmeticException excp)

{t1.setText("Divide by 0.");}

else if(str.equals("C"))

v2=0.0;OP=' '; memValue=0.0;

t1.setText(""+a1);

else if(str.equals("MC"))

{
memValue=0.0;

else if(str.equals("MR"))

String resText=""+memValue;

resText=""+Double.parseDouble(resText.substring(0,resText.length()-2));

t1.setText(resText);

else

t1.setText(Str1.concat(str));

Str1=t1.getText();

}catch(Exception e){}

public static void main(String a[])

{ new MyCal4(); }

public Insets getInsets()

return new Insets(50,25,25,25);

} }

E:\java programing>javac MyCal4.java

E:\java programing>java MyCal4

EXP.NO:-11 PRELAB EXERCISE:-


import java.io.*;

class copyfile

public static void main(String a[])

File in=new File("hai.txt");

File out=new File("hh.txt");

FileReader ins=null;

FileWriter outs=null;

try

ins=new FileReader(in);

outs=new FileWriter(out);

int ch;

while((ch=ins.read())!=-1)

outs.write(ch);

catch(IOException e)

System.out.println(e);
System.exit(-1);

finally

try

ins.close();

outs.close();

catch(IOException e){}

} }

E:\java programing>javac copyfile.java

E:\java programing>java copyfile

EXP.NO:-11 LAB EXERCISE:-


import java.io.*;import java.io.File.*;

import java.awt.*;

import java.applet.*;

import java.awt.event.*;

public class student1 extends Frame implements ActionListener,ItemListener

String msg="",taa="";int i;Choice c[]=new Choice[3];

List lst=new List(4,true);

Label l[]=new Label[16];boolean isnumberornot;

String lcap[]={"Register No.","Name","Sex","Degree","Branch","Year of Study","Date of


Birth","Hobby","Address","Extra Curricular Activities","E-Mail Id","B.Tech","M.Tech","CSE","ECE","EEE"};

Button b1=new Button("submit");

Button b2=new Button("cancel");Checkbox h1,h2,h3;

Label p=new Label(" ",Label.CENTER);

Label l11=new Label("Student Response Form",Label.CENTER);

Label l7=new Label("",Label.RIGHT);

TextField t1=new TextField(20);

TextField t2=new TextField(20);

TextField t3=new TextField(20);

TextArea ta=new TextArea("",100,100,TextArea.SCROLLBARS_BOTH);

CheckboxGroup cbg=new CheckboxGroup();

Checkbox ck1=new Checkbox("Male",false,cbg);


Checkbox ck2=new Checkbox("Female",false,cbg);

TextArea t5=new TextArea("",180,90,TextArea.SCROLLBARS_VERTICAL_ONLY);

Choice branch=new Choice();

Choice degree=new Choice();

Choice yos=new Choice();RandomAccessFile pol=null;

public student1()

for(i=0;i<7;i++)

{l[i]=new Label(lcap[i],Label.LEFT);add(l[i]);}

for(i=7;i<11;i++)

{l[i]=new Label(lcap[i],Label.CENTER);add(l[i]);}

for(i=0;i<3;i++)

{ c[i]=new Choice();add(c[i]);}

add(p);

h1=new Checkbox("Stamp Collection");

h2=new Checkbox("Reading Novels");

h3=new Checkbox("Playing Tennis");

addWindowListener(new myWindowAdapter());

setBackground(Color.cyan);

setForeground(Color.black);

setLayout(null);

add(l11);

lst.add("Tennis");lst.add("Cricket");lst.add("Basket Ball");lst.add("Hockey");

add(ta);add(h1);add(h2);add(h3);add(lst);

add(t1); add(t2); add(t3); add(ck1); add(ck2); add(branch); add(degree); add(yos);


add(b1); b1.addActionListener(this); b2.addActionListener(this); add(b2);

degree.add(lcap[11]);degree.add(lcap[12]);

for(i=13;i<16;i++)

branch.add(lcap[i]);

yos.add("1"); yos.add("2"); yos.add("3");yos.add("4");

l11.setFont(new Font("SansSerif", Font.BOLD+Font.ITALIC, 15));

p.setFont(new Font("SansSerif", Font.BOLD+Font.ITALIC, 15));

for(int i=1;i<=31;i++)

c[0].add(""+i);

degree.addItemListener(this);

c[1].add("January");c[1].add("February");c[1].add("March");

c[1].add("April");c[1].add("May");c[1].add("June");c[1].add("July");c[1].add("August");

c[1].add("September");c[1].add("October");c[1].add("November");c[1].add("December");

for(i=1990;i<2002;i++)

c[2].add(""+i);

for(i=0;i<6;i++)

l[i].setBounds(25,(60+(i*30)),90,20);

l[6].setBounds(25,320,90,20); l[7].setBounds(425,65,100,20);

l[8].setBounds(431,105,100,20); l[9].setBounds(632,105,150,20); l[10].setBounds(433,320,100,20);

l11.setBounds(300,40,280,20); lst.setBounds(642,125,130,89);

t1.setBounds(120,60,170,20); t2.setBounds(120,90,170,20); t3.setBounds(538,320,170,20);

ta.setBounds(461,125,130,90); ck1.setBounds(120,120,50,20); ck2.setBounds(170,120,60,20);

degree.setBounds(120,150,70,20); branch.setBounds(120,180,50,20); yos.setBounds(120,210,30,20);

c[0].setBounds(120,320,35,20); c[1].setBounds(160,320,77,20); c[2].setBounds(243,320,50,20);

h1.setBounds(530,65,105,20); h2.setBounds(644,65,100,20); h3.setBounds(750,65,100,20);


p.setBounds(120,420,530,20); b1.setBounds(300,380,65,20); b2.setBounds(400,380,65,20);

public void actionPerformed(ActionEvent ae)

{if(ae.getActionCommand().equals("submit"))

if(t1.getText().length()!=9)

msg="register number should be 9characters!";

else

try{

int kk=Integer.parseInt(t1.getText());isnumberornot=false;

catch(Exception e)

isnumberornot=true;

if(isnumberornot)

msg="Characters should be avoided for RegNo";

else

msg="";boolean isEmpty=t2.getText()==null||t2.getText().trim().length()==0;
if(isEmpty)

msg="Name should not be blank";

else

if(cbg.getSelectedCheckbox()==null)

msg="Select the Gender";

else

msg="";isEmpty=ta.getText()==null||ta.getText().trim().length()==0;

if(isEmpty)

msg="Address should not be blank";

else

msg="";int yo=t3.getText().lastIndexOf("@");

if(!t3.getText().endsWith("@gmail.com"))

msg="Invalid E-Mail ID(@gmail.com not found)";

else
{

String jo=(t3.getText()).substring(0,yo);

isEmpty=jo==null||jo.trim().length()==0||jo.startsWith(" ");

if(isEmpty)

msg="Invalid E-Mail Id(characters is not present before@ORfirst letter is null)";

else

String dob,ptr="",pho[],h="";

pho=lst.getSelectedItems();

for(int i=0;i<pho.length;i++)

{ptr+=pho[i];if(i!=pho.length-1){ptr+=",";}}

dob=c[0].getSelectedItem()+"-"+c[1].getSelectedItem()+"-"+c[2].getSelectedItem();

if(h1.getState()){h+=h1.getLabel();if(h.charAt(0)==',')h=h.substring(1,h.length());}

if(h2.getState()){h+=","+h2.getLabel();if(h.charAt(0)==',')h=h.substring(1,h.length());}

if(h3.getState()){h+=","+h3.getLabel();if(h.charAt(0)==',')h=h.substring(1,h.length());}

taa="\r\nRegister No:"+t1.getText()

+"\r\nName :"+t2.getText()

+"\r\nSex :"+cbg.getSelectedCheckbox().getLabel()

+"\r\nDegree :"+degree.getSelectedItem()

+"\r\nBranch :"+branch.getSelectedItem()

+"\r\nYear Of Study :"+yos.getSelectedItem()

+"\r\nD.O.B :"+dob

+"\r\nHobbies:"+h
+"\r\nExtra Curricular Activities :"+ptr

+"\r\nAddress :"+ta.getText()

+"\r\nE-Mail Id :"+t3.getText();

msg="student details are submitted!";

} } } } } } }

try

pol=new RandomAccessFile("stud.txt","rw");

//new RandomAccessFile("stud.txt","rw").setLength(0);//clears the entire file content and append

pol.seek(pol.length());pol.writeBytes(taa+"\r\n");//without using above statement,appending records


//continuously

pol.close();

taa="";

catch(Exception e){}

if(ae.getActionCommand().equals("cancel"))

if(degree.getSelectedItem().equals("M.Tech")){yos.add("3");yos.add("4");}

t1.setText("");t2.setText("");t3.setText("");ta.setText("");

cbg.setSelectedCheckbox(null);h1.setState(false);h2.setState(false);h3.setState(false);

lst.deselect(0);lst.deselect(1);lst.deselect(2);lst.deselect(3);msg="";

degree.select(0);branch.select(0);c[0].select(0);c[1].select(0);c[2].select(0);

yos.select(0);

p.setText(msg);
p.setForeground(Color.red);

public void itemStateChanged(ItemEvent e)

if(e.getItemSelectable()==degree)

if(((Choice)e.getItemSelectable()).getSelectedItem()=="M.Tech")

{yos.remove("3"); yos.remove("4");}

if(((Choice)e.getItemSelectable()).getSelectedItem()=="B.Tech")

{yos.add("3"); yos.add("4");}

} }

public static void main(String g[])

{student1 stu=new student1();

stu.setSize(new Dimension(900,500));

stu.setTitle("Response Form");

stu.setVisible(true);

} }

class myWindowAdapter extends WindowAdapter

{public void windowClosing(WindowEvent we)

{ System.exit(0);

} }

E:\java programing>javac student1.java

E:\java programing>java student1

EXP.NO:-12 PRELAB EXERCISE:-


import java.awt.*; import java.sql.*; import java.awt.event.*;

class sampjdbc extends Frame implements ActionListener

Label l1,l2; TextField t1,t2; Button b; Connection c; Statement st; ResultSet rs;

sampjdbc()

setFont(new Font("Arial",Font.BOLD,20));

l1 = new Label("Login");

l2 = new Label("Password");

t1= new TextField(10);

t2 =new TextField(10);

b= new Button("Next");

addWindowListener(new WindowAdapter(){

public void windowClosing(WindowEvent e) {System.exit(0);}});

setLayout(new GridLayout(3,2));

add(l1); add(l2);add(t1); add(t2);add(b);

b.addActionListener(this);

try

Class.forName("org.apache.derby.jdbc.EmbeddedDriver");

Statement st=c.createStatement();

//Connection c=DriverManager.getConnection("jdbc:derby:cse;create=true");
c=DriverManager.getConnection("jdbc:derby:cse");

//st.execute("create table stu(name char(20), id int)");

//st.execute("insert into stu values('ccc',333)");

//st.execute("insert into stu values('ddd',444)");

rs=st.executeQuery("select * from stu");

}catch(Exception e){}

public void actionPerformed(ActionEvent ae)

try

if(rs.next())

t1.setText(rs.getString(1));

t2.setText(String.valueOf((rs.getInt(2))));

}catch(Exception e){}

public static void main(String args[])

sampjdbc j=new sampjdbc();

j.setTitle("Student DB ");

j.setSize(210,150);j.setBackground(Color.cyan);

j.setVisible(true);

} }
E:\java programing>javac sampjdbc.java

E:\java programing>java sampjdbc

EXP.NO:-12 LAB EXERCISE:-


import java.sql.*; import java.awt.*; import java.applet.*; import java.awt.event.*;

public class student6 extends Frame implements ActionListener,ItemListener

String msg="";int i;Choice c[]=new Choice[3];

List lst=new List(4,true);int sar=0,moi=0,soi=0,tit,kiy,rows;

Label l[]=new Label[16];

String lcap[]={"Register No.","Name","Sex","Degree","Branch","Year of Study","Date of


Birth","Hobby","Address","Extra Curricular Activities","E-Mail Id","B.Tech","M.Tech","CSE","ECE","EEE"};

String lo[]={"ADD","SEARCH","DELETE","<<","<",">",">>","UPDATE","CLEAR"};

Checkbox h1,h2,h3;

Label p=new Label(" ",Label.CENTER);boolean isnumberornot;

Label l11=new Label("Student Response Form",Label.CENTER);

Label l7=new Label("",Label.RIGHT);

TextField t1=new TextField(20);

TextField t2=new TextField(20);

TextField t3=new TextField(20);

Button b[]=new Button[9];

TextArea ta=new TextArea("",100,100,TextArea.SCROLLBARS_BOTH);

CheckboxGroup cbg=new CheckboxGroup();

Checkbox ck1=new Checkbox("Male",false,cbg);

Checkbox ck2=new Checkbox("Female",false,cbg);

TextArea t5=new TextArea("",180,90,TextArea.SCROLLBARS_VERTICAL_ONLY);

Choice branch=new Choice();


Choice degree=new Choice();

Choice yos=new Choice();

Connection co; Statement st; ResultSet rs; PreparedStatement q;

public student6()

for(i=0;i<7;i++)

{l[i]=new Label(lcap[i],Label.LEFT);add(l[i]);}

for(i=7;i<11;i++)

{l[i]=new Label(lcap[i],Label.CENTER);add(l[i]);}

for(i=0;i<3;i++)

{ c[i]=new Choice();add(c[i]);}

add(p);

h1=new Checkbox("Stamp Collection");

h2=new Checkbox("Reading Novels");

h3=new Checkbox("Playing Tennis");

addWindowListener(new myWindowAdapter());

setBackground(Color.cyan);

setForeground(Color.black);

setLayout(null);

add(l11);

lst.add("Tennis");

lst.add("Cricket");lst.add("Basket Ball"); lst.add("Hockey");lst.add("Volley Ball");

add(ta);add(h1);add(h2);add(h3);add(lst); add(t1);

add(t2); add(t3); add(ck1); add(ck2); add(branch); add(degree); add(yos);

for(i=0;i<9;i++)
{b[i]=new Button(lo[i]);add(b[i]);b[i].addActionListener(this);}

degree.add(lcap[11]);

degree.add(lcap[12]);

for(i=13;i<16;i++)

branch.add(lcap[i]);

yos.add("1"); yos.add("2"); yos.add("3"); yos.add("4");

l11.setFont(new Font("SansSerif", Font.BOLD+Font.ITALIC, 15));

p.setFont(new Font("SansSerif", Font.BOLD+Font.ITALIC, 15));

for(int i=1;i<=31;i++)

c[0].add(""+i);

degree.addItemListener(this);

c[1].add("January");c[1].add("February");c[1].add("March");c[1].add("April");

c[1].add("May");c[1].add("June");c[1].add("July");c[1].add("August");c[1].add("September");

c[1].add("October");c[1].add("November");c[1].add("December");

for(i=1990;i<2002;i++)

c[2].add(""+i);

for(i=0;i<6;i++)

l[i].setBounds(25,(60+(i*30)),90,20);

l[6].setBounds(25,320,90,20); l[7].setBounds(425,65,100,20);

l[8].setBounds(431,105,100,20); l[9].setBounds(632,105,150,20); l[10].setBounds(433,320,100,20);

l11.setBounds(300,40,280,20);lst.setBounds(642,125,130,59); t1.setBounds(120,60,170,20);

t2.setBounds(120,90,170,20); t3.setBounds(538,320,170,20); ta.setBounds(461,125,130,60);

ck1.setBounds(120,120,50,20); ck2.setBounds(170,120,60,20); degree.setBounds(120,150,70,20);

branch.setBounds(120,180,50,20); yos.setBounds(120,210,30,20); c[0].setBounds(120,320,35,20);

c[1].setBounds(160,320,77,20); c[2].setBounds(243,320,50,20); h1.setBounds(530,65,105,20);


h2.setBounds(644,65,100,20); h3.setBounds(750,65,100,20); p.setBounds(120,420,530,20);

b[0].setBounds(145,380,50,20); b[1].setBounds(213,380,70,20); b[2].setBounds(300,380,70,20);

b[3].setBounds(385,380,35,20); b[4].setBounds(435,380,20,20); b[5].setBounds(465,380,20,20);

b[6].setBounds(505,380,35,20); b[7].setBounds(555,380,70,20); b[8].setBounds(420,440,70,20);

try

Class.forName("org.apache.derby.jdbc.EmbeddedDriver");

//co=DriverManager.getConnection("jdbc:derby:csel;create=true");

co=DriverManager.getConnection("jdbc:derby:csel");

st=co.createStatement();

//st.execute("create table human(RNO integer, Name varchar(40), Gender char(8), Degree char(20),
Branch char(20), YearOfStudy integer,DOB date, Address varchar(1000), EMailId varchar(60), Hobby
char(160), ECA char(160))");

//st.execute("insert into human values(221003116,'photons','Male','B.Tech','CSE',2,'1999-10-


19','Papanasam','karuppaiyaa4139@gmail.com','Reading Novels','Tennis')");

st=co.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);

rs=st.executeQuery("select * from human");

if(rs.first()){display();sar=1;}

rs=st.executeQuery("select * from human");

q=co.prepareStatement("insert into human values(?,?,?,?,?,?,?,?,?,?,?)");

}catch(Exception e){ e.printStackTrace();}

public void reset()

{ if(degree.getSelectedItem().equals("M.Tech")){yos.add("3");yos.add("4");}

t2.setText("");t3.setText("");ta.setText("");

cbg.setSelectedCheckbox(null);h1.setState(false);h2.setState(false);h3.setState(false);

lst.deselect(4);lst.deselect(3);lst.deselect(2);lst.deselect(1);lst.deselect(0);
degree.select(0);branch.select(0);c[0].select(0);c[1].select(0);c[2].select(0);

yos.select(0);

public void actionPerformed(ActionEvent ae)

try{

if(ae.getActionCommand().equals("ADD"))

if(t1.getText().length()!=9)

msg="register number should be 9characters!";

else

try{

int kk=Integer.parseInt(t1.getText());isnumberornot=false;

catch(Exception e)

isnumberornot=true;

if(isnumberornot)

msg="Characters should be avoided for RegNo";

}
else

msg="";boolean isEmpty=t2.getText()==null||t2.getText().trim().length()==0;

if(isEmpty)

msg="Name should not be blank";

else

if(cbg.getSelectedCheckbox()==null)

msg="Select the Gender";

else

msg="";isEmpty=ta.getText()==null||ta.getText().trim().length()==0;

if(isEmpty)

msg="Address should not be blank";

else

msg="";int yo=t3.getText().lastIndexOf("@");

if(!t3.getText().endsWith("@gmail.com"))

{
msg="Invalid E-Mail ID(@gmail.com not found)";

else

String jo=(t3.getText()).substring(0,yo);

isEmpty=jo==null||jo.trim().length()==0||jo.startsWith(" ");

if(isEmpty)

msg="Invalid E-Mail Id(characters is not present before@ORfirst letter is null)";

else

rs=st.executeQuery("select * from human");

while(rs.next())

if((String.valueOf(rs.getInt(1))).equals(t1.getText())){msg="ERROR,RegNo is already present in


the record!";moi=1;}

if(moi!=1)

String dob,ptr="",bod="",good="",pho[],h="";

for(int tt=0;tt<12;tt++)

if(c[1].getSelectedIndex()==tt)

{if(tt<9)good="0"+(tt+1);

else{good=""+(tt+1);}
} }

pho=lst.getSelectedItems();

for(int i=0;i<pho.length;i++)

{ptr+=pho[i];if(i!=pho.length-1){ptr+=",";}}

dob=c[0].getSelectedItem()+"-"+c[1].getSelectedItem()+"-"+c[2].getSelectedItem();

bod=c[2].getSelectedItem()+"-"+good+"-"+c[0].getSelectedItem();

if(h1.getState()){h+=h1.getLabel();if(h.charAt(0)==',')h=h.substring(1,h.length());}

if(h2.getState()){h+=","+h2.getLabel();if(h.charAt(0)==',')h=h.substring(1,h.length());}

if(h3.getState()){h+=","+h3.getLabel();if(h.charAt(0)==',')h=h.substring(1,h.length());}

msg="student details are added!";

q.setInt(1,Integer.parseInt(t1.getText()));

q.setString(2,t2.getText());

q.setString(3,cbg.getSelectedCheckbox().getLabel());

q.setString(4,degree.getSelectedItem());

q.setString(5,branch.getSelectedItem());

q.setInt(6,Integer.parseInt(yos.getSelectedItem()));

q.setString(7,bod);

q.setString(8,ta.getText());

q.setString(9,t3.getText());

q.setString(10,h);

q.setString(11,ptr);

q.executeUpdate();

rs=st.executeQuery("select * from human");rs.last();

} }moi=0; } } } } } } }

if(ae.getActionCommand().equals("SEARCH"))
{

rs=st.executeQuery("select * from human");

while(rs.next())

if((String.valueOf(rs.getInt(1))).equals(t1.getText())){display();msg="student detail is
searched!";break;}

else{

msg="Enter valid RegNo!";reset();

} } }

if(ae.getActionCommand().equals("CLEAR"))

msg="student details are cleared!";reset();t1.setText("");

if(ae.getActionCommand().equals("DELETE"))

rs=st.executeQuery("select * from human");

while(rs.next())

if((String.valueOf(rs.getInt(1))).equals(t1.getText()))

String frog="delete from human where RNO= "+t1.getText()+"";

st.executeUpdate(frog);

msg="student details are deleted!";reset();

rs=st.executeQuery("select * from human");

break; }

else{
msg="Enter valid RegNo!";reset();}

if(ae.getActionCommand().equals("<<"))

if(rs.first()) display();

msg="First student record!";}

if(ae.getActionCommand().equals("<"))

if(rs.previous())

{display();

msg="Previous student record!";}

else

msg="You Had Reached The First record!";

if(ae.getActionCommand().equals(">"))

if(rs.next())

{display();

if(sar==1){msg="This is first student record!";sar=0;}

else

{msg="Next student record!";}

}else

{msg="You Had Reached The Last record!";}

}
if(ae.getActionCommand().equals(">>"))

if(rs.last()) display();

msg="Last student record!";}

if(ae.getActionCommand().equals("UPDATE"))

rs=st.executeQuery("select * from human");

while(rs.next())

{tit=rs.getRow();

if((String.valueOf(rs.getInt(1))).equals(t1.getText()))

{soi=1;

if(t1.getText().length()!=9)

msg="register number should be 9characters!";

else

try{

int kk=Integer.parseInt(t1.getText());isnumberornot=false;

catch(Exception e)

isnumberornot=true;

}
if(isnumberornot)

msg="Characters should be avoided for RegNo";

else

msg="";boolean isEmpty=t2.getText()==null||t2.getText().trim().length()==0;

if(isEmpty)

msg="Name should not be blank";

else

if(cbg.getSelectedCheckbox()==null)

msg="Select the Gender";

else

msg="";isEmpty=ta.getText()==null||ta.getText().trim().length()==0;

if(isEmpty)

msg="Address should not be blank";

else
{

msg="";int yo=t3.getText().lastIndexOf("@");

if(!t3.getText().endsWith("@gmail.com"))

msg="Invalid E-Mail ID(@gmail.com not found)";

else

String jo=(t3.getText()).substring(0,yo);

isEmpty=jo==null||jo.trim().length()==0||jo.startsWith(" ");

if(isEmpty)

msg="Invalid E-Mail Id(characters is not present before@ORfirst letter is null)";

else

String dob,ptr="",bod="",good="",pho[],h="";

for(int tt=0;tt<12;tt++)

if(c[1].getSelectedIndex()==tt)

{if(tt<9)good="0"+(tt+1);

else{good=""+(tt+1);}

} }

pho=lst.getSelectedItems();

for(int i=0;i<pho.length;i++)
{ptr+=pho[i];if(i!=pho.length-1){ptr+=",";}}

dob=c[0].getSelectedItem()+"-"+c[1].getSelectedItem()+"-"+c[2].getSelectedItem();

bod=c[2].getSelectedItem()+"-"+good+"-"+c[0].getSelectedItem();

if(h1.getState()){h+=h1.getLabel();if(h.charAt(0)==',')h=h.substring(1,h.length());}

if(h2.getState()){h+=","+h2.getLabel();if(h.charAt(0)==',')h=h.substring(1,h.length());}

if(h3.getState()){h+=","+h3.getLabel();if(h.charAt(0)==',')h=h.substring(1,h.length());}

rs.absolute(tit); rs.updateInt(1,Integer.parseInt(t1.getText()));

rs.updateString(2,t2.getText());

rs.updateString(3,cbg.getSelectedCheckbox().getLabel());

rs.updateString(4,degree.getSelectedItem());

rs.updateString(5,branch.getSelectedItem());

rs.updateInt(6,Integer.parseInt(yos.getSelectedItem()));

rs.updateString(7,bod);

rs.updateString(8,ta.getText());

rs.updateString(9,t3.getText());

rs.updateString(10,h);

rs.updateString(11,ptr);

rs.updateRow();msg="student details are updated!";

}moi=0;

} } } } } } break; } }

if(soi!=1)msg="RegNo is unavailable in the record";

p.setText(msg);

p.setForeground(Color.red);

}catch(Exception e){e.printStackTrace();}
}

public void itemStateChanged(ItemEvent e)

if(e.getItemSelectable()==degree)

if(((Choice)e.getItemSelectable()).getSelectedItem()=="M.Tech")

{yos.remove("3"); yos.remove("4");}

if(((Choice)e.getItemSelectable()).getSelectedItem()=="B.Tech")

{yos.add("3"); yos.add("4");}

} }

public void display()

try{

t1.setText(String.valueOf((rs.getInt(1))));

t2.setText(rs.getString(2));

String sds=rs.getString(3).trim();

if(sds.equals("Male"))ck1.setState(true);

if(sds.equals("Female"))ck2.setState(true);

degree.select(rs.getString(4));

branch.select(rs.getString(5));

yos.select(rs.getString(6));

String uu=rs.getString(7);

String gh=uu.substring(8,10);

if(gh.charAt(0)=='0')gh=gh.substring(1,2);

c[0].select(gh);
gh=uu.substring(5,7);

if(gh.charAt(0)=='0')gh=gh.substring(1,2);

c[1].select((Integer.parseInt(gh)-1));

c[2].select(uu.substring(0,uu.indexOf("-")));

ta.setText(rs.getString(8));

t3.setText(rs.getString(9));

h1.setState(false);h2.setState(false);h3.setState(false);

lst.deselect(4);lst.deselect(3);lst.deselect(2);lst.deselect(1);lst.deselect(0);

String hhp=rs.getString(10);

for(int zz=0;zz<47;zz++)

if(hhp.charAt(zz)=='S')h1.setState(true);

if(hhp.charAt(zz)=='R')h2.setState(true);

if(hhp.charAt(zz)=='P')h3.setState(true);

hhp=rs.getString(11);

for(int zz=0;zz<47;zz++)

if(hhp.charAt(zz)=='T')lst.select(0);

if(hhp.charAt(zz)=='C')lst.select(1);

if(hhp.charAt(zz)=='B')lst.select(2);

if(hhp.charAt(zz)=='H')lst.select(3);

if(hhp.charAt(zz)=='V')lst.select(4);

}
catch(Exception e){e.printStackTrace();}

public static void main(String g[])

{student6 stu=new student6();

stu.setSize(new Dimension(900,500));

stu.setTitle("Response Form");

stu.setVisible(true);

} }

class myWindowAdapter extends WindowAdapter

{public void windowClosing(WindowEvent we)

System.exit(0);

} }

E:\java programing>javac student6.java

E:\java programing>java student6

You might also like