Tuesday, 19 July 2011

online examination system

very soon
Read More

online banking system

very soon
Read More

Write a program of paint

very soon
Read More

Write a program of YES/NO game

very soon
Read More

Write a program in which name moves as we move the mouse

very soon
Read More

Write a program of 8Q game

very soon
Read More

Write a program of tik-tak game

very soon
Read More

Write a program of snake game

very soon
Read More

Write a program which can find the number of counts and Unicode of keypressed

very soon
Read More

Write a program which generates a different names with different colors randomly

very soon
Read More

rite a program of traffic light

very soon
Read More

Write a program of analog clock

very soon
Read More

Write a program in which two string collide and bounces back

very soon
Read More

Write a program of digital clock (00:00:00)

very soon
Read More

Write a program of marquee

very soon
Read More

Write a program to draw a hut

very soon
Read More

Write a program to display a frame

will be available soon

Read More

Sunday, 17 July 2011

Event

Event:- is a package
It contains classes like KeyEvent,MouseEvent,ItemEvent.

Source(generates)------------------------------àListener(listen)

class Key extends Frame implements KeyListener
{
public void keyPressed(KeyEvent ke)
{
}
public void keyReleased(KeyEvent ke)
{
}
public void keyTyped(KeyEvent ke)
{
}
Key()
{
addKeyListener();
}
}



Ques1:-Write a program which can find the number of counts and Unicode of keypressed.
Ques2:-Write a program of snake game.




MouseListener:-
class Mouse extends Frame implements MouseListener
{
public void mousePressed(MouseEvent me)
{
Graphics g=getGraphics();
x=me.getX();
y=me.getY();
g.drawString(“India”,x,y);
}
public void mouseReleased(MoiseEvent me)
{
}
public void mouseClicked(MoiseEvent me)
{
}
public void mouseEntered(MoiseEvent me)
{
}
public void mouseExited(MoiseEvent me)
{
}
Mouse()
{
addMouseListener(this);
}
}

Ques3:-Write a program of tik-tak game.
Ques4:-Write a program of 8Q game.

Note:-Abstract class have constructor if it will execute with the help of child class.

super.display();
we can use the method of parent class by super class in case of overriding.

MouseMotionListener:-
Dragged & Moved

Class Moving extends Frame implements MouseMotionListener
{
public void mouseDragged(MouseEvent me)
{
}
public void mouseMoved(MouseEvent me)
{
}
Moving()
{
addMouseMotionListener(this);
}
}

Ques5:-Write a program in which name moves as we move the mouse.
Ques6:-Write a program of YES/NO game.
Ques7:-Write a program of paint.

Read More

AWT package

awt:- is a package
Abstract window package

import java.awt.*;
It contains many classes like Frame class, Dialogue class, Canvas class.

*g.drawRext(x,y,width,height);    //to draw a rectangle
Eg.
g.drawRect(100,100,50,50);
*g.drawOval(x,y,width,height);    //to draw a oval
Eg.
g.drawOval(100,100,50,50);

*g.setColor(Color.red);                 //to set a color
*g.fillRect(100,100,50,50);           //to fill a rect
*g.drawLine(x,y,x1,y1);                //to draw a line
*g.drawArc(x,y,width,height,angle1,angle2);
Eg.
g.drawArc(100,100,80,80,100,60);




Ques1:-Write a program to display a frame.
Ques2:-Write a program to draw a hut.

*g.drawString(“Ashish”,100,200);
*for filling any color
Color c=new Color(255,0,0);
g.setColor(c);
*Font f=new Font(“Arial”,Font.BOLD,22);
g.setFont(f) ;

Ques3:-Write a program of marquee.
Ques4:-Write a program of digital clock (00:00:00).
Ques5:-Write a program in which two string collide and bounces back.
Ques6:-Write a program of analog clock.
Ques7:-write a program of traffic light.

Math.random()
Random is the function of math class that is available in lang package it will generate a number between 0 & 1 randomly.
0 can be generated but 1 can’t be generated.

For generating between 100&580
X=(int)(Math.random*481+100);
Y=(int)(Math.random*481+100) ;

100 is the starting point where as 481 is the difference plus 1.

*Color c=new Color(r,gr,b);

int r=(int)(Math.random()*256);
int gr=(int)(Math.random()*256);
int b=(int)(Math.random()*256);

Ques:-Write a program which generates a different names with different colors randomly.
Read More

Write a program of addition of matrix

import java.io.*;
class Matrix1
{
int row,i,j;
int col;
int n[][]=new int[10][10];

public void input()
throws IOException
{
          BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
          System.out.println("enter the order of matrix");
          row=Integer.parseInt(br.readLine());
          col=Integer.parseInt(br.readLine());
          System.out.println("enter the matrix");
          for(i=0;i<row;i++)
          {
                   for(j=0;j<col;j++)
                   {   BufferedReader cr=new BufferedReader(new InputStreamReader(System.in));
                             n[i][j]=Integer.parseInt(cr.readLine());
                   }
          }
}
          public void output()
          {
                   System.out.println("matrix is");
                   for(i=0;i<row;i++)
                             {
                                      for(j=0;j<col;j++)
                                      {

                                                System.out.print(n[i][j]+"\t");
                                      }
                                      System.out.print("\n");
          }
}
 public void sum(Matrix1 m1,Matrix1 m2)
 {
           Matrix1 t3=new Matrix1();
           row=m1.row;
           col=m1.col;
           for(i=0;i<row;i++)
                    {
                             for(j=0;j<col;j++)
                             {
                                       t3.n[i][j]=m1.n[i][j]+m2.n[i][j];
                             }
                   }

                   t3.output();
          }
}


class matmain
{
          public static void main(String[] arg)
          throws IOException
          {
                   Matrix1 m1=new Matrix1();
                   Matrix1 m2=new Matrix1();
                   Matrix1 m3=new Matrix1();
                   m1.input();
                   m2.input();
                   m1.output();
                   m2.output();
                   m3.sum(m1,m2);

          }
}
Read More

Write a program of addition, subtraction, multiplication and division of rational number

import java.io.*;
class rational
{
int num;
int den;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
public void input()
throws IOException
{
System.out.println("enter the numerator");
num=Integer.parseInt(br.readLine());
System.out.println("enter the denominator");
den=Integer.parseInt(br.readLine());
}
public void output()
{
System.out.println("the rattional  number is"+num+"/"+den);
}
public rational sum(rational r1,rational r2)
{
rational r3=new rational();
r3.num=r1.num*r2.den+r1.den*r2.num;
r3.den=r1.den*r2.den;
return r3;
}
public rational sub(rational r1,rational r2)
{
rational r3=new rational();
r3.num=r1.num*r2.den-r1.den*r2.num;
r3.den=r1.den*r2.den;
return r3;
}
public rational mul(rational r1,rational r2)
{
rational r3=new rational();
r3.num=r1.num*r2.num;
r3.den=r1.den*r2.den;
return r3;
}
public rational div(rational r1,rational r2)
{
rational r3=new rational();
r3.num=r1.num*r2.den;
r3.den=r1.den*r2.num;
return r3;
}
public void hcf()
{
int n;
int d;
int rem=1;
n=num;
d=den;
int hc=1;
if(n>d)
{
while(rem!=0)
{
rem=n%d;
n=d;
d=rem;
hc=n;
}
}
else
{
while(rem!=0)
{
rem=d%n;
d=n;
n=rem;
hc=d;
}
}
num=num/hc;
den=den/hc;
}

}

class main2
{
public static void main(String[] arg)
throws IOException
{
int ch;
BufferedReader cr=new BufferedReader(new InputStreamReader(System.in));
rational r1=new rational();
rational r2=new rational();
rational r3=new rational();
r1.input();
r2.input();
r1.output();
r2.output();
System.out.println("enter your choice ");
System.out.println("1 for add");
System.out.println("2.for sub");
System.out.println("3.for mul");
System.out.println("4 for div");
ch=Integer.parseInt(cr.readLine());
switch(ch)
{
case 1:
{
r3=r3.sum(r1,r2);
r3.hcf();
r3.output();
break;
}
case 2:
{
r3=r3.sub(r1,r2);
r3.hcf();
r3.output();
break;
}
case 3:
{
r3=r3.mul(r1,r2);
r3.hcf();
r3.output();
break;
}
case 4:
{
r3=r3.div(r1,r2);
r3.hcf();
r3.output();
break;
}
}
}
}
Read More

Write a program of addition of complex number

import java.io.*;
class complex25
{
int real;
int img;
public void input()
throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("enter the real and imaginary part");
real=Integer.parseInt(br.readLine());
img=Integer.parseInt(br.readLine());
}
public void output()
{
System.out.println(real+"+"+img+"i");
}
public complex25 sum(complex25 c1,complex25 c2)
{
complex25 c3=new complex25();
c3.real=c1.real+c2.real;
c3.img=c1.img+c2.img;
return c3;
}
}
class complex25main
{
public static void main(String[] arg)
throws IOException
{
complex25 c1=new complex25();
complex25 c2=new complex25();
complex25 c3=new complex25();
c1.input();
c2.input();
System.out.println("first complex no is=");
c1.output();
System.out.println("second complex no is=");
c2.output();
c3=c3.sum(c1,c2);
System.out.println("result is=");
c3.output();
}}
Read More

Write a program of prime number

import java.io.*;
class Prime
{
          public static void main(String[] arg)
          throws IOException
          {
                   int i=2;
                   BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
                   System.out.println("enter the first number");
                   int n=Integer.parseInt(br.readLine());
                   for(i=2;i<=n/2;i++)
                   {
                             if(n%i==0)
                             break;
                   }
                   if(i==((n/2)+1))
                   System.out.println("prime");
                   else
                   System.out.println("not prime");
          }
}
Read More

Write a program to calculate the sum of n rational numbers using array of objects

import java.io.*;
class rational25
{
int num;
int den;
public void input()
throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("enter the numerator");
num=Integer.parseInt(br.readLine());
System.out.println("enter the numerator");
den=Integer.parseInt(br.readLine());
}
public void hcf()
{
int temp=0;
if(num<den)
temp=num;
else
temp=den;
while(temp>=2)
{
if(num%temp==0&&den%temp==0)
{

num=num/temp;
den=den/temp;

}
temp--;
}
System.out.println(num+"/"+den);
}


public void sum(rational25 c[])
{
num=c[0].num;
den=c[0].den;
for(int i=1;i<c.length;i++)
{
num=num*c[i].den+den*c[i].num;
den=den*c[i].den;
}


}
}

class rational25main
{
public static void main(String[] arg)
throws IOException
{
int n=0;
rational25 s=new rational25();
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("enter the number of rational numbers");
n=Integer.parseInt(br.readLine());
rational25[] c=new rational25[n];
for(int i=0;i<n;i++)
{
c[i]=new rational25();
c[i].input();
}
s.sum(c);
s.hcf();
}
}
Read More

Write a program to calculate the sum of n complex numbers using array of objects

import java.io.*;
class complexn25
{
int real;
int img;
public void input()
throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("enter the real and imaginary part");
real=Integer.parseInt(br.readLine());
img=Integer.parseInt(br.readLine());
}

public void sum(complexn25 c[])
{
complexn25 s=new complexn25();
real=c[0].real;
img=c[0].img;
for(int i=1;i<c.length;i++)
{
real=real+c[i].real;
img=img+c[i].img;
}
System.out.println(real+"+"+img+"i");
}
}
class complexn25main
{
public static void main(String[] arg)
throws IOException
{
int n=0;
complexn25 p=new complexn25();
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("enter the number of complex numbers");
n=Integer.parseInt(br.readLine());
complexn25[] c=new complexn25[n];
for(int i=0;i<n;i++)
{
c[i]=new complexn25();
c[i].input();
}
complexn25 s=new complexn25();
s.sum(c);
}
}import java.io.*;
class complexn25
{
int real;
int img;
public void input()
throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("enter the real and imaginary part");
real=Integer.parseInt(br.readLine());
img=Integer.parseInt(br.readLine());
}

public void sum(complexn25 c[])
{
complexn25 s=new complexn25();
real=c[0].real;
img=c[0].img;
for(int i=1;i<c.length;i++)
{
real=real+c[i].real;
img=img+c[i].img;
}
System.out.println(real+"+"+img+"i");
}
}
class complexn25main
{
public static void main(String[] arg)
throws IOException
{
int n=0;
complexn25 p=new complexn25();
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("enter the number of complex numbers");
n=Integer.parseInt(br.readLine());
complexn25[] c=new complexn25[n];
for(int i=0;i<n;i++)
{
c[i]=new complexn25();
c[i].input();
}
complexn25 s=new complexn25();
s.sum(c);
}
}
Read More

Write examples of inheritance

Example1:-
public class gandhi
{
public void invitation()
{
System.out.println("object of gandhi,class gandhi");
}
public void invitation1(rahul r)
{
System.out.println("object of rahul,class gandhi");
}
public void invitation2(varun v)
{
System.out.println("object of varun,class gandhi");
}
}
public class rahul extends gandhi
{
public void invitations()
{
System.out.println("object of gandhi,class rahul");
}
public void invitations1(rahul r)
{
System.out.println("object of rahul,class rahul");
}
public void invitations2(varun v)
{
System.out.println("object of varun,class rahul");
}
}
public class varun extends gandhi
{
public void invitationv()
{
System.out.println("object of gandhi,class varun");
}
public void invitationv1(rahul r)
{
System.out.println("object of rahul,class varun");
}
public void invitationv2(varun v)
{
System.out.println("object of varun,class varun");
}
}
public class gandhimain
{
public static void main(String[] arg)
{
gandhi g=new gandhi();
rahul r=new rahul();
varun v=new varun();
new rahul().invitation();
new rahul().invitations();
new varun().invitation();

new varun().invitationv();
new gandhi().invitation();
}
}
Example 2:-
public class gandhi
{
public void invitation(gandhi g)
{
System.out.println("object of gandhi,class gandhi");
}
public void invitation1(rahul r)
{
System.out.println("object of rahul,class gandhi");
}
public void invitation2(varun v)
{
System.out.println("object of varun,class gandhi");
}
}
public class rahul extends gandhi
{
public void invitations(gandhi g)
{
System.out.println("object of gandhi,class rahul");
}
public void invitations1(rahul r)
{
System.out.println("object of rahul,class rahul");
}
public void invitations2(varun v)
{
System.out.println("object of varun,class rahul");
}
}
public class varun extends gandhi
{
public void invitationv(gandhi g)
{
System.out.println("object of gandhi,class varun");
}
public void invitationv1(rahul r)
{
System.out.println("object of rahul,class varun");
}
public void invitationv2(varun v)
{
System.out.println("object of varun,class varun");
}
}
public class gandhimain
{
public static void main(String[] arg)
{
gandhi g=new gandhi();
rahul r=new rahul();
varun v=new varun();
g.invitation(g);
g.invitation1(r);
g.invitation2(v);
r.invitations(g);
r.invitations1(r);
r.invitations2(v);
v.invitationv(g);
v.invitationv1(r);
v.invitationv2(v);
}
}
Read More

Write a program to calculate compound interest using inheritance

public class Power
{
double pr=1;
public double pow(double no,int p)
{
while(p>0)
{
pr=pr*no;
p--;
}
return pr;
}
}
import java.io.*;
public class Ci extends Power
{
int p,t;
double r,ans;
public void input()
throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the principal");
p=Integer.parseInt(br.readLine());
System.out.println("enter the rate of interest");
r=Double.parseDouble(br.readLine());
System.out.println("Enter the time");
t=Integer.parseInt(br.readLine());
}
public void output()
{
System.out.println("the compound interest is:"+ans);
}
public void cal()
{
double h=1.0+r/100;

double res=pow(h,t);

ans=p*res-p;
}
}

import java.io.*;
public class Cimain
{
public static void main(String[] arg)
throws IOException
{
Ci c=new Ci();
c.input();
c.cal();
c.output();
}
}
Read More

Write a program to convert a binary number into decimal using inheritance

public class Binpow
{
public int pow(int n)
{
int res=1;
if(n!=0)
{
for(int i=1;i<=n;i++)
res=2*res;
n++;

}
return res;
}
}

import java.io.*;
public class Binary extends Binpow
{
int g=1;
int bin;
int dec;
int rem=1;
public void input()
throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("ENTER the binary number");
bin=Integer.parseInt(br.readLine());
}
public void output()
{

}
public void cal()
{
int n=0;
int h=0;System.out.println("check");
while(rem!=0||bin!=0)
{

rem=bin%10;
bin=bin/10;
h=pow(n);
dec=rem*h+dec;
n++;
}
System.out.println("decimal number ="+dec);
}
}
import java.io.*;
public class Bimain
{
public static void main(String[] arg)
throws IOException
{
Binary c=new Binary();
c.input();
c.cal();

}
}
Read More
 

About The Author


I am a B.Tech Computer Science Student. I love Programming and blogging. I am Oracle certified Java Professional. Read More
Indian Blogger

Teachers Jobs

Footer 3

Twitter Facebook RSS YouTube Google
​

All Rights Reserved ©Sun Java Masters 2013