Professional Documents
Culture Documents
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();
}
}
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);
}
}
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();
}
}
import java.lang.*;
import java.util.*;
class Account
{
protected double balance;
protected int accnumber;
Account(int acn,double bal)
{
balance= bal;
accnumber=acn;
}
}
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
{
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());
}
}
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);
}
}
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);
}
}
}
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 :
import java.util.*;
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 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
20000
1000
20000000
C:\app>java main1
1000
1000
C:\app>java main1
20000
1000
Caught:Output character = $
C:\app>java main1
20000
100
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();
}
}
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();
}
}
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);
}
}
}
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+ ")");
}
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]
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 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);
}
}
}
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.awt.event.*;
TextField tf1,tf2;
Button b1,b2;
String msg="";
public AwtFrame()
{
setTitle("Login Screen");setBackground(Color.cyan);
lbl.setBounds(50,30,300,40);
add(lbl);
tf1.setForeground(Color.gray);
tf2.setForeground(Color.gray);
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(){
setLayout(null);
setSize(380,300);
setVisible(true);
TextField t=(TextField)fe.getSource();
if(t==tf1)
{ tf1.setText(""); }
else
{ tf2.setText("");}
}
public void actionPerformed(ActionEvent ae)
if(b==b1)
String s=tf2.getText();
if(s.length()>=8)
smsg="Login Successful";
else
repaint();
else
tf1.setText("Enter UserName");
tf1.setForeground(Color.gray);
tf2.setText("Enter PassWord");
tf2.setForeground(Color.gray);
msg="";
repaint();
g.drawString(msg,150,250);
}
new AwtFrame();
import java.applet.*;
import java.awt.event.*;
Checkbox h1,h2,h3;
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);
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");
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);
if(ae.getSource()==t4)
if(cbg.getSelectedCheckbox()==null)
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("");
m=1; }else{
try{
int kk=Integer.parseInt(t1.getText());isnumberornot=false;
catch(Exception e)
isnumberornot=true;
if(isnumberornot)
else
m=0;
}
}
else if(ae.getSource()==t2)
msg="";isEmpty=t2.getText()==null||t2.getText().trim().length()==0;
if(isEmpty)
ta.setText("");
n=1; }else{n=0;}
else if(ae.getSource()==t4)
msg="";isEmpty=t4.getText()==null||t4.getText().trim().length()==0;
if(isEmpty)
nn=1;ta.setText(""); }else{nn=0;}
else if(ae.getSource()==t3)
msg="";int yo=t3.getText().lastIndexOf("@");
if(!t3.getText().endsWith("@gmail.com"))
else
String jo=(t3.getText()).substring(0,yo);
isEmpty=jo==null||jo.trim().length()==0||jo.startsWith(" ");
if(isEmpty)
pp=1;ta.setText(""); }else{pp=0;}
else
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());}
csg="";
}p.setText(msg);p.setForeground(Color.red);
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");}
stu.setSize(new Dimension(850,650));
stu.setTitle("Response Form");
stu.setVisible(true);
System.exit(0);
import java.awt.*;
import java.awt.event.*;
int i=0,j,k=5;
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(){
add(t1,BorderLayout.NORTH);
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);
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;}
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="";
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"))
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){}
{ new MyCal4(); }
} }
class copyfile
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){}
} }
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
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);
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);
degree.add(lcap[11]);degree.add(lcap[12]);
for(i=13;i<16;i++)
branch.add(lcap[i]);
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);
l11.setBounds(300,40,280,20); lst.setBounds(642,125,130,89);
{if(ae.getActionCommand().equals("submit"))
if(t1.getText().length()!=9)
else
try{
int kk=Integer.parseInt(t1.getText());isnumberornot=false;
catch(Exception e)
isnumberornot=true;
if(isnumberornot)
else
msg="";boolean isEmpty=t2.getText()==null||t2.getText().trim().length()==0;
if(isEmpty)
else
if(cbg.getSelectedCheckbox()==null)
else
msg="";isEmpty=ta.getText()==null||ta.getText().trim().length()==0;
if(isEmpty)
else
msg="";int yo=t3.getText().lastIndexOf("@");
if(!t3.getText().endsWith("@gmail.com"))
else
{
String jo=(t3.getText()).substring(0,yo);
isEmpty=jo==null||jo.trim().length()==0||jo.startsWith(" ");
if(isEmpty)
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\nD.O.B :"+dob
+"\r\nHobbies:"+h
+"\r\nExtra Curricular Activities :"+ptr
+"\r\nAddress :"+ta.getText()
+"\r\nE-Mail Id :"+t3.getText();
} } } } } } }
try
pol=new RandomAccessFile("stud.txt","rw");
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);
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");}
} }
stu.setSize(new Dimension(900,500));
stu.setTitle("Response Form");
stu.setVisible(true);
} }
{ System.exit(0);
} }
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");
t2 =new TextField(10);
b= new Button("Next");
addWindowListener(new WindowAdapter(){
setLayout(new GridLayout(3,2));
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");
}catch(Exception e){}
try
if(rs.next())
t1.setText(rs.getString(1));
t2.setText(String.valueOf((rs.getInt(2))));
}catch(Exception e){}
j.setTitle("Student DB ");
j.setSize(210,150);j.setBackground(Color.cyan);
j.setVisible(true);
} }
E:\java programing>javac sampjdbc.java
String lo[]={"ADD","SEARCH","DELETE","<<","<",">",">>","UPDATE","CLEAR"};
Checkbox h1,h2,h3;
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);
addWindowListener(new myWindowAdapter());
setBackground(Color.cyan);
setForeground(Color.black);
setLayout(null);
add(l11);
lst.add("Tennis");
add(ta);add(h1);add(h2);add(h3);add(lst); add(t1);
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]);
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);
l11.setBounds(300,40,280,20);lst.setBounds(642,125,130,59); t1.setBounds(120,60,170,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=co.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
if(rs.first()){display();sar=1;}
{ 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);
try{
if(ae.getActionCommand().equals("ADD"))
if(t1.getText().length()!=9)
else
try{
int kk=Integer.parseInt(t1.getText());isnumberornot=false;
catch(Exception e)
isnumberornot=true;
if(isnumberornot)
}
else
msg="";boolean isEmpty=t2.getText()==null||t2.getText().trim().length()==0;
if(isEmpty)
else
if(cbg.getSelectedCheckbox()==null)
else
msg="";isEmpty=ta.getText()==null||ta.getText().trim().length()==0;
if(isEmpty)
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)
else
while(rs.next())
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());}
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();
} }moi=0; } } } } } } }
if(ae.getActionCommand().equals("SEARCH"))
{
while(rs.next())
if((String.valueOf(rs.getInt(1))).equals(t1.getText())){display();msg="student detail is
searched!";break;}
else{
} } }
if(ae.getActionCommand().equals("CLEAR"))
if(ae.getActionCommand().equals("DELETE"))
while(rs.next())
if((String.valueOf(rs.getInt(1))).equals(t1.getText()))
st.executeUpdate(frog);
break; }
else{
msg="Enter valid RegNo!";reset();}
if(ae.getActionCommand().equals("<<"))
if(rs.first()) display();
if(ae.getActionCommand().equals("<"))
if(rs.previous())
{display();
else
if(ae.getActionCommand().equals(">"))
if(rs.next())
{display();
else
}else
}
if(ae.getActionCommand().equals(">>"))
if(rs.last()) display();
if(ae.getActionCommand().equals("UPDATE"))
while(rs.next())
{tit=rs.getRow();
if((String.valueOf(rs.getInt(1))).equals(t1.getText()))
{soi=1;
if(t1.getText().length()!=9)
else
try{
int kk=Integer.parseInt(t1.getText());isnumberornot=false;
catch(Exception e)
isnumberornot=true;
}
if(isnumberornot)
else
msg="";boolean isEmpty=t2.getText()==null||t2.getText().trim().length()==0;
if(isEmpty)
else
if(cbg.getSelectedCheckbox()==null)
else
msg="";isEmpty=ta.getText()==null||ta.getText().trim().length()==0;
if(isEmpty)
else
{
msg="";int yo=t3.getText().lastIndexOf("@");
if(!t3.getText().endsWith("@gmail.com"))
else
String jo=(t3.getText()).substring(0,yo);
isEmpty=jo==null||jo.trim().length()==0||jo.startsWith(" ");
if(isEmpty)
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);
}moi=0;
} } } } } } break; } }
p.setText(msg);
p.setForeground(Color.red);
}catch(Exception e){e.printStackTrace();}
}
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");}
} }
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();}
stu.setSize(new Dimension(900,500));
stu.setTitle("Response Form");
stu.setVisible(true);
} }
System.exit(0);
} }