Friday, 27 April 2012

MPI Lab Programs


1.Write a program in 8086 to find out maxium of N numbers

Program:
        OUTPUT 2500AD
        ORG 2000H
MES1:   DB 0AH,0DH,'ENTER THE VALUE'
        LEA AX,MES1
        CALL FAR 0FE00:0031H
        CALL FAR 0FE00:0013H
        CALL FAR 0FE00:00C7H
        MOV BL,AL
        MOV CL,AL
        MOV CH,00H
        MOV SI,2200H
IN:     CALL FAR 0FE00:0031H
        CALL FAR 0FE00:00C7H
        MOV [SI],AL
        INC SI
        DEC CL
        JNZ IN
        MOV SI,2200H
        MOV CL,BL
B1:     MOV AL,[SI]
        INC SI
        LOOP B1
        MOV SI,2200H
        MOV CL,BL
        DEC CL
        MOV AL,[SI]
BACK:   INC SI
        CMP AL,[SI]
        JNC NEXT
        MOV AL,[SI]
NEXT:   LOOP BACK
        CALL FAR 0FE00:0031H
        CALL FAR 0FE00:0052H

        HLT       




2.Arranging set of a number in ascending order

Program:
        OUTPUT 2500AD
        ORG 2000H
M:      CALL FAR 0FE00:0031H
M1:     DB 10,13,'ENTER N VALUE',00H
        LEA AX,M1
        CALL FAR 0FE00:0013H
        CALL FAR 0FE00:0031H
        CALL FAR 0FE00:00C7H
        MOV DL,AL
        MOV BL,AL
        MOV DH,00H
        MOV CL,AL
        MOV CH,00H
        MOV SI,2200H
C1:     CALL FAR 0FE00:0031H
        CALL FAR 0FE00:00C7H
        MOV [SI],AL
        INC SI
        LOOP L1
        MOV SI,2200H

L1:     DEC DL
        MOV CL,DL
        MOV AL,[SI]
L2:     INC SI
        CMP AL,[SI]
        JC L3
        XCHG AL,[SI]
L3:     LOOP L2
        SUB SI,DX
        MOV [SI],AL
        INC SI
        CMP DL,01H
        JNZ L1
        MOV SI,2200H
        MOV CX,BX
L4:     MOV AL,[SI]
        CALL FAR 0FE00:0031H
        CALL FAR 0FE00:0052H
        INC SI
        LOOP L4
        HLT

 


3. Conversion of HEX to BCD

Program:
                   OUTPUT 2500AD
        ORG 2000H
M:      CALL FAR 0FE00:0031H
M1:     DB 10,13,'ENTER 2 DIGIT HEX VALUE',00H
M2:     DB 10,13,'THE BCD IS:',00H
        LEA AX,M1
        CALL FAR 0FE00:0013H
        CALL FAR 0FE00:00E0H
        MOV AH,00H
        MOV BL,64H
        DIV BL
        MOV DL,AL
        MOV AL,AH
        MOV AH,00H
        MOV BL,0AH
        DIV BL
        SHL AL
        SHL AL
        SHL AL
        SHL AL
        OR AL,AH
        MOV AH,DL
        MOV BX,AX
        CALL FAR 0FE00:0031H
        LEA AX,M2
        CALL FAR 0FE00:0013H
        MOV AX,BX
        CALL FAR 0FE00:006AH
        JMP M
        RET

 
4. To check the given number is prime or not?

Program:
        OUTPUT 2500AD

        ORG 2000H
       
M1:     DB 10,13,'  ENTER A NUMBER  :  ',00H

        LEA AX,M1
        CALL FAR 0FE00:0013H
        CALL FAR 0FE00:00C7H
        MOV BL,AL
        MOV CH,AL
        MOV CL,AL
        MOV AH,00H
        DEC CL
        DEC CL
        MOV BH,02H

L1:     DIV BH

        CMP AH,00H
        JE L2
        INC BH
        MOV AL,CH
        MOV AH,00H
        DEC CL
        JNZ L1
        CALL FAR 0FE00:0031H

M2:     DB 10,13,'   PRIME NUMBER   ',00H

        LEA AX,M2
        CALL FAR 0FE00:0013H
        JMP L3

L2:     CALL FAR 0FE00:0031H

M3:     DB 10,13,'  NOT PRIME   ',00H

        LEA AX,M3
        CALL FAR 0FE00:0013H

L3:     RET



 
5. To find out the Fibonacci series

Program:
        OUTPUT 2500AD

        ORG 2000H

        CALL FAR 0FE00:0031H

        MOV AX,0000H

MES1:   DB  10,13,'ENTER THE N VALUE : ',00H

        LEA DX,MES1

        MOV AX,DX

        CALL FAR 0FE00:0013H

        CALL FAR 0FE00:00C7H

        MOV CL,AL

        MOV CH,00H
       
        MOV AL,00H

        CALL FAR 0FE00:0031H

        CALL FAR 0FE00:0052H

        MOV AL,00H

        MOV BL,01H

        DEC CL

LAB:    XCHG AL,BL

        ADD AL,BL

        CALL FAR 0FE00:0031H

        CALL FAR 0FE00:0052H

        DEC CL

        JNZ LAB
       
        RET

6. Write a program to search an element in any search method

Program:
     OUTPUT 2500AD
     ORG 2000H
     CALL FAR 0FE00:0031H
     CALL FAR 0FE00:00C7H
     MOV SI,2200H
     MOV BL,AL
     MOV CH,00H
     MOV CL,AL
     CALL FAR 0FE00:0031H
L1:  CALL FAR 0FE00:0031H
     CALL FAR 0FE00:00C7H
     MOV [SI],AL
     INC SI
     LOOP L1
     MOV CH,BL
     DEC BL
L4:  MOV SI,2200H
     MOV CL,BL
L3:  MOV AL,[SI]
     MOV DI,SI
     INC DI
     CMP AL,[DI]
     JL L2
     MOV DL,[DI]
     XCHG [DI],AL
     XCHG [SI],DL
     MOV SI,DI
     MOV DL,[DI]
     MOV [SI],DL
     DEC SI
L2:  INC SI
     DEC CL
     JNZ L3       
     DEC CH
     JNZ L4
     MOV SI,2200H
     INC BL
     MOV CL,BL
L5:  MOV AL,[SI]
     CALL FAR 0FE00:0031H
     CALL FAR 0FE00:0031H
     CALL FAR 0FE00:0052H
     INC SI
     DEC BL
     JNZ L5
     RET
 

7. Write a program in 8086 Alp to run the stepped motor in different speeds

Program:
OUTPUT 2500AD
                ORG 2000H
                MOV AX,0000H            ;Initialise Segment
                MOV ES,AX               ;Registers
                MOV DX,0FFE6H           ;Initialise
                MOV AL,80H              ;all 8255 Ports as o/p
                OUT DX,AL
                CALL FAR 0FE00:01EDH
                JMP SHORT START
MES1:           DB 0AH,0DH,'ENTER DIRECTION'      
                DB 0AH,0DH,'A-ANTICLOCKWISE     C-CLOCKWISE',00H

START:          LEA  DX,MES1            ;Display message
                MOV AX,DX               ;on LCD or Console
                CALL FAR 0FE00:0013H
GET:            CALL FAR 0FE00:00A9H    ;Wait for user entry
                CMP AL,41H              ;If key ='A',
                JE   ANTI               ;rotate anti-clockwise
                CMP AL,43H              ;If key = 'C'
                JE   CLO                ;rotate clockwise
                JMP SHORT GET           ;Accept valid key only
                                

CLO:            CALL COMMON
R1:             OUT  DX,AL
                CALL  DELAY             ;Introduce delay
                RCR  AL,1               ;Rotate bits in
                JMP  SHORT R1           ;data byte right & repeat

  
ANTI:           CALL COMMON
R2:             OUT  DX,AL
                CALL  DELAY
                RCL  AL,1               ;Rotate bits 
                JMP  SHORT R2           ;left & repeat

COMMON:         CALL FAR 0FE00:0031H
                CALL FAR 0FE00:00H
                MOV  AL,11H             ;Output value
                MOV  DX,0FFE0H          ;to Port A
                RET

DELAY:          MOV  CX,800H            ;Delay routine
SS:             LOOP SS
                RET
                END

 
8.Write a program to stimulate TLC(Traffic Light Controller) using 8086

Program:
OUTPUT  2500AD

        ORG     2000H
START:  MOV     AL,80H                 ; Initialisation of 8255 Mode 0
        MOV     DX,0FFE6H
        OUT     DX,AL                  ; All ports as o/p ports
AGAIN:  MOV     SI,2038H               ; Table of port values
NEXTST: MOV     AL,[SI]
        MOV     DX,0FFE0H
        OUT     DX,AL                  ; PortA value
        INC     SI
        ADD     DX,2
        MOV     AL,[SI]
        OUT     DX,AL                  ; PortB value
        INC     SI
        ADD     DX,2
        MOV     AL,[SI]
        OUT     DX,AL                  ; PortC value
        INC     SI
        CALL    DELAY                  ; Calling Delay routine
        CMP     SI,2056H               ; Checking for the end of the data values
        JNZ     NEXTST
        JMP     AGAIN
DELAY:  MOV     CX,0FFH                ; Delay routine
DLY5:   PUSH    CX
        MOV     CX,03FFH
DLY10:  NOP
        LOOP    DLY10
        POP     CX
        LOOP    DLY5
        RET

        ORG     2038H
        PORTVALUES:   DB      10H,81H,7AH                ; State 1
                      DB      44H,44H,0F0H               ; All ambers ON
                      DB      08H,11H,0E5H               ; State 2
                      DB      44H,44H,0F0H               ; All ambers ON    
                      DB      81H,10H,0DAH               ; State 3
                      DB      44H,44H,0F0H               ; All ambers ON
                      DB      11H,08H,0B5H               ; State 4
                      DB      44H,44H,0F0H               ; All ambers ON
                      DB      88H,88H,00H                ; State 5
                      DB      44H,44H,0F0H               ; All ambers ON
                      DB      00H                        ; Dummy

9. Write a program to interface 4 nor of FND 507 to 8086 in multiplexed mode//seven segment display

Program:
OUTPUT 2500AD
                ORG 2000H
                MOV AX,0000H                     ;Initialise segment reg.
                MOV DS,AX
                MOV DX,FFE6H                     ;Configure all 8255 ports
                MOV AL,80H                          ;as output.
                OUT DX,AL

         LOOP4: MOV SI,2100H             ;Initialise pointer
                MOV CL,05H                        ;set counter for 5 groups.
         LOOP3: MOV CH,04H                 ;4 charecters/group
         LOOP2: MOV BL,08H                  ;8 segments/charecter

                MOV AL,[SI]                          ;get the display code
                INC SI                                     ;Increment pointer
         LOOP1: ROL AL,1                           ;get 1 data bit
                MOV DX,FFE2H
                OUT DX,AL                               ;o/p bit to portb
                MOV AH,AL
                MOV AL,01H                            ;o/p clock to
                MOV DX,FFE4H                       ;shift register
                OUT DX,AL
                DEC AL
                OUT DX,AL
                MOV AL,AH
                DEC BL                                       ;all bits over?
                JNZ LOOP1                                ;no,continue
                DEC CH                                      ;all charecters over?
                JNZ LOOP2                                ;no,continue                              
                CALL DELAY
                DEC CL                                       ;all groups over?
                JNZ LOOP3                                ;no,continue
                JMP SHORT LOOP4

         DELAY: PUSH CX                              ;delay subroutine
                MOV CX,0
            L1: LOOP L1
            L2: LOOP L2
                POP CX
                RET

;Display code table

                ORG 2100H
        STRING: DB 0FFH,0FFH,0FFH,0FFH
                DB 0C6H,086H,0C7H,086H
                DB 0BFH,0C0H,0DEH,087H
                DB 0BFH,092H,091H,092H
                DB 092H,0C8H,086H,087H

                END
 

Java Lab Programs


/* 1. Develop a program to convert the given temperature in fahreneit to Celsius
using the following connversion formulas C = and display the values in a
tabular form
 *Celsius.java
 *Ravi 24
 *20.01.12
 *To convert temperature scales
*/
import java.lang.*;
import java.io.*;
class Celsius
{
 public static void main(String args[])
 {
   double c[]=new double[20];
   double f[]=new double[20];
   int n;
   DataInputStream dis=new DataInputStream(System.in);
   try
   {
   System.out.println("Enter number of values to be entered");
   n=Integer.parseInt(dis.readLine());
   for(int i=0;i<n;i++)
    {
                   f[i]=Integer.parseInt(dis.readLine());
                }
                for(int i=0;i<n;i++)
    {
                   c[i]=(f[i]-32)/1.8;
                }
                System.out.println(" farenheit-celsius");
                for(int i=0;i<n;i++)
    {
                  System.out.println(" "+f[i]+" "+c[i]);
                }
                }
                catch(Exception e){}
               
 }
}


/*2. Develop a program that will take a string from a command line argument in order to check
whether it is a palindrome.

 * palindrome.java
 * Ravi 24
 * 23/12/2011
 * Checks palindrome
 */
import java.lang.*;
import java.io.*;
import java.util.*;
class palindrome
{
                public static void main(String args[])
                {
                                boolean flag=true;
                                String str;
                                str=args[0];
                                int len= str.length();
                                System.out.println("Length: "+len);
                                for(int i=0;i<(len/2);i++)
                                 {
                                                if(str.charAt(i)==str.charAt((len-1)-i)) ;
                                                else { flag=false;  break;}
                                 }
                                if(flag==true) System.out.println("Palindrome");
                                else System.out.println("Not Palindrome");
                }
}


/*  3. Develop a program by design a class to represent a bank account. Including the following
members:
Data Members:
Name of the Depositor
Account Number
Type of account
Balance
Methods:
To assign initial values
To deposit an amount
To withdraw an amount after checking
balance
To display the name and balance

*Bank.java
*Ravi 24
*10.02.12
*Demonstration of Bank operations
*/
import java.lang.*;
import java.io.*;
import java.util.*;
class Account
{
                String name;
                long accNum=1000;
                int type=1;
                double bal;
                static int count;
               
}
class Bank extends Account
{              void createAccount()
{
                DataInputStream dis=new DataInputStream(System.in);
                try{
                                System.out.print("Enter Name:");
                                name=new String(dis.readLine());
                System.out.print("\n Account Type(1-savings/2-current:");
                type=Integer.parseInt(dis.readLine());
                accNum+=++count;
                assignInitialValues();
                }
                catch(Exception e)
                {
                System.out.println(e);
                }
                }
                void assignInitialValues()
                {
                if(type==1)
                {
                bal=500.0;
                }
                if(type==2)
                {
                                bal=1000.0;
                }
                }
void withdraw(double val)
{
if(bal>=val){bal=bal-val;}
else{ System.out.println("InSufficient Balance"); }
}
void deposit(double val)
{
                bal=bal+val;
}
void display()
{
String accType;
if(type==1){accType=new String("Savings"); }
else{ accType=new String("Current"); }
                System.out.println("\n\n"+accNum+"\t\t"+name+"\t\t"+accType+"\t\t"+bal);
                }
public static void main(String args[])
{
int ch=0;
double val=0,num=0;
boolean flag=false;
Vector v=new Vector(10);
Bank ob=null;
DataInputStream dis=new DataInputStream(System.in);
try
{
loop:      while(true)
                {             
                flag=false;
                System.out.println("\n Enter 1. create 2.Credit 3.Debit 4.display 5.Exit:");
                ch=Integer.parseInt(dis.readLine());
                switch(ch)
                {
                case 1: ob=new Bank(); ob.createAccount();v.add(ob);break;
                case 2: System.out.println("\n Enter accnum:");
                                num=Integer.parseInt(dis.readLine());
                                for(int i=0;i<v.size();i++)
                                {
                                ob=((Bank)v.get(i));
                                if(ob.accNum==num){flag=true; break;}
                                }
                                if(flag)
                                {
                                System.out.println("\n Enter amount:");
                                val=Integer.parseInt(dis.readLine());
                                ob.deposit(val);
                                }
                                else
                                {
                                System.out.println("Enter proper AccNum");
                                continue loop;
                                }
                                break;
                                case 3: System.out.println("\n Enter accnum:");
                                num=Integer.parseInt(dis.readLine());
                                for(int i=0;i<v.size();i++)
                                {
                                ob=((Bank)v.get(i));
                                if(ob.accNum==num){flag=true; break;}
                                }
                                if(flag)
                                {
                                System.out.println("\n Enter amount:");
                                val=Integer.parseInt(dis.readLine());
                                ob.withdraw(val);
                                }
                                else
                                {
                                System.out.println("\n Enter proper accnum");
                                continue loop;
                                }
                                break;
case 4: System.out.println("Acc.Num                     Name                    Type                      BalanceAmount");
                                for(int i=0;i<v.size();i++)
                                {
                                ((Bank)v.get(i)).display();
                                }
                                break;
                case 5:  System.exit(1);
                default: System.out.println("Enter Proper Choice"); continue loop;
                }
                }
}
                catch(Exception e)
                {
                                System.out.println(e);
                }             
                }
}



4. Develop a program to demonstrate multiple inheritance through interface

import java.lang.*;
import java.io.*;
import java.util.*;
interface MyInterface
{
 static final int a=20;
 void display();
}
class A
{
  int b=30;
}
class B extends A implements MyInterface
{
 int c;
 public void display()
 {
 
  c=a+b;
  System.out.println("Sum is "+c);
 }
}
class InterfaceDemo
{
 public static void main(String args[])
 {
  B ob=new B();
  ob.display();
 }
}



/*5. Develop a program to illustrate the use of multithreads
*ThreadTest.java
*Ravi 24
*02.03.12
*Demonstrating Threads
*/
class A extends Thread
{
 public void run()
 {
  for(int i=1;i<=3;i++)
   {
    System.out.println("\tFrom ThreadA : i= "+i);
   }
  System.out.println("Exit from A");
 }
}
class B extends Thread
{
 public void run()
 {
  for(int i=1;i<=3;i++)
   {
    System.out.println("\tFrom ThreadB : i= "+i);
   }
  System.out.println("Exit from B");
 }
}
class C extends Thread
{
 public void run()
 {
  for(int i=1;i<=3;i++)
   {
    System.out.println("\tFrom ThreadC : i= "+i);
   }
  System.out.println("Exit from C");
 }
}
class ThreadTest
{
 public static void main(String args[])
 {
  A a=new A();
  B b=new B();
  C c=new C();
  a.start();
  b.start();
  c.start();
 }
}


6. Develop am applet that receives three numeric values as input from the user and then display the
largest of the three.
 
import java.awt.*;
import java.applet.*;
public class Ex1 extends Applet
{ TextField t1,t2,t3;
  public void init()
  {

   Label l1=new Label("first"); 
   Label l2=new Label("second"); 
   Label l3=new Label("third");
   t1= new TextField(8);
   t2= new TextField(8);
   t3= new TextField(8);
   t1.setText("0");
   t2.setText("0");
   t3.setText("0");
   add(l1);
   add(t1);
   add(l2);
   add(t2);
   add(l3);
   add(t3);
  }
  public void paint(Graphics g)
  {
  
   g.drawString("input the num",10,45);
    int x=0,y=0,z=0,max=0;
                String s1,s2,s3,s;
                try{
                s1=t1.getText();
                s2=t2.getText();
                s3=t3.getText();
                x=Integer.parseInt(s1);
                y=Integer.parseInt(s2);
                z=Integer.parseInt(s3);
    }
  catch(Exception e)
   {} 
  if(x>y&&x>z)
   max=x;
  else if(y>x&&y>z)
   max=y;
  else
   max=z;
  s=String.valueOf(max);
  g.drawString("the max num is "+s,20,55);
  }
  public boolean action(Event event,Object object)
  {
    repaint();
                return true;
  }
}

7. Develop an applet that displays different bar charts
import java.awt.*;
import java.applet.*;
public class BarChart extends Applet
{
 int n=0;
 String label[]={"91","92","93","94"};
 int value[]={110,150,100,170};
 public void paint(Graphics g)
 {
  for(int i=0;i<4;i++)
  {
    g.setColor(Color.red);
                g.drawString(label[i],20,i*50+30);
                g.fillRect(50,i*50+10,value[i],40);
  }
  }
}


/*
7. Develop an applet that displays different bar charts
 *graphs.java
 *Ravi 24
 *16.03.12
 *To display IND-SL scores in BarGraphs
*/
import java.lang.*;
import java.io.*;
import java.awt.*;
import java.applet.*;

public class graphs extends Applet
{
                int sri[]={3,3,1,4,6,2,9,1,0,3,8,7,8,3,5,1,10,2,3,0,5,8,2,5,6,11,3,7,7,4,5,6,4,5,11,4,3,6,3,2,2,1,2,4,3,9,4,9,12,4};
                int ind[]={2,4,7,6,4,1,2,8,8,2,3,2,7,5,7,5,6,0,3,1,10,1,3,5,1,6,5,8,4,9,2,3,3,4,8,2,5,7,4,5,0,2,2,4,5,13,5,4,15,4};
               
                public void init()
                {
               
                }
                                public void paint(Graphics g)
                                {
                                                try
                                                {
                                                                int j=-10;
                                                                g.setColor(Color.black);
                                                                g.drawLine(0,200, 1000,200);
                                                                g.setColor(Color.red);
                                                                g.drawString("SRI LANKA:",20,30);
                                                                g.setColor(Color.blue);
                                                                g.drawString("INDIA:",20,330);
                                                for(int i=0;i<50;i++)
                                                {
                                                                g.setColor(Color.red);
                                                                g.fillRect(j+10,200-(sri[i]*10),10,sri[i]*10);
                                                                j+=20;
                                                }
                                                                j=-10;
                                                for(int i=0;i<50;i++)
                                                {
                                                                g.setColor(Color.blue);
                                                                g.fillRect(j+10,200,10,ind[i]*10);
                                                                j+=20;
                                                }             
                                                }catch(Exception e){}
                                }
}








/*
8. Develop an applet to draw the following shapes
a) Cone
b) Cylinder
c) Cube
d) Square inside a circle e) Circle inside a square

*/

import java.applet.*;
import java.awt.*;
public class Shapes extends Applet 
{
 public void paint(Graphics g)
 {
  int c=100,d=100;//to draw cone

    g.drawOval(c,d,50,25);
                g.drawLine(c,d+10,c+25,d+100);
                g.drawLine(c+50,d+10,c+25,d+100);
               
                c=300;d=300;//to draw cylinder
                g.drawOval(c,d,50,25);
                g.drawOval(c,d+100,50,25);
                g.drawLine(c,d+10,c,d+110);
                g.drawLine(c+50,d+10,c+50,d+110);
               
                c=200;d=200;//cube
                g.drawLine(c,d,c+50,d);
                g.drawLine(c,d+50,c+50,d+50);
                g.drawLine(c,d,c,d+50);
                g.drawLine(c+50,d,c+50,d+50);
               
               
                g.drawLine(c+20,d-20,c+70,d-20);
                g.drawLine(c+20,d+30,c+70,d+30);
                g.drawLine(c+20,d-20,c+20,d+30);
                g.drawLine(c+70,d-20,c+70,d+30);
               
                g.drawLine(c,d,c+20,d-20);
                g.drawLine(c+50,d,c+70,d-20);
                g.drawLine(c,d+50,c+20,d+30);
                g.drawLine(c+50,d+50,c+70,d+30);
               
                c=500;d=200;//circle inside square
                g.drawLine(c,d,c+100,d);
                g.drawLine(c,d+100,c+100,d+100);
                g.drawLine(c,d,c,d+100);
                g.drawLine(c+100,d,c+100,d+100);
                g.drawOval(c,d,100,100);
               
               
                c=600;d=100;//square inside circle
                g.drawOval(c,d,100,100);
                g.drawLine(c+15,d+15,c+85,d+15);
                g.drawLine(c+15,d+85,c+85,d+85);
                g.drawLine(c+15,d+15,c+15,d+85);
                g.drawLine(c+85,d+15,c+85,d+85);
 }
}

  9. Develop a program to display a calendar for a specified month using the Date, Calendar and Date
Format classes.
*MyCalendar.java
*Jagadeesh,10
*31-03-2012
*To print the calendar of a month
*/
import java.util.*;
public class MyCalendar
{
                public static void main(String args[])
                {
                                int m=Integer.parseInt(args[0]);
                                int y=Integer.parseInt(args[1]);
                                Date dt=new Date(y-1900,m-1,1);
                                int NumDays=31, count=0;
                                String Month[]= {"JANUARY","FEBRUARY","MARCH", "APRIL","MAY", "JUNE","JULY","AUGUST","SEPTEMBER","OCTOBER","NOVEMBER","DECEMBER"};
                                if((m==4)||(m==6)||(m==9)||(m==11)){ NumDays=30; }
                                if(m==2){ NumDays=28; if((y%400==0)||((y%4==0)&&(y%100!=0))){ NumDays=29;}}
                                int day=dt.getDay();
                                System.out.println("\n\n\t\t"+Month[m-1]+"\t"+y+"\n\n");
                                System.out.println("  SUN\t  MON\t  TUE\t  WED\t  THU\t  FRI\t  SAT");
                                for(int i=0;i<day;i++){ System.out.print("\t"); count++;}
                                for(int k=1;k<=NumDays;k++){
                                if(count==6){System.out.print("   "+k+"\t"); System.out.println("");count=0;}
                                else { System.out.print("   "+k+"\t"); count++;}
                                }
                }
}



/*
  10. Develop a program for handling Mouse Events.

 MyMouseEvent.java
 *Ravi 24
 *09.04.12
 *Demonstrating Mouse events to tell when when mouse enters
*/
import java.awt.*;
import java.awt.event.*;

public class MyMouseEvent extends Frame implements MouseListener{
                 static Frame f;
                MyMouseEvent()
                {
                 f=new Frame("FIRST CSE");
                f.addMouseListener(this);
                }
                public static void main(String args[])
                {
                                MyMouseEvent m=new MyMouseEvent();
                                f.setBounds(100, 100, 600, 200);
                                f.setVisible(true);
                               
                }
                public void mouseClicked(MouseEvent e){ System.out.println("mouseClicked");}
               
                public void mouseEntered(MouseEvent e){System.out.println("mouseEntered");}
               
                public void mouseExited(MouseEvent e){System.out.println("mouseExited");}
                public void mousePressed(MouseEvent e){ System.out.println("mousePressed");}
                public void mouseReleased(MouseEvent e){System.out.println(" mouseReleased"); }
                //public void windowActivated(WindowEvent e){System.out.println("Window activated");}
                //public void windowDeactivated(WindowEvent e){System.out.println("Window Deactived"); }
}


/*
11. Develop a program to display the mouse position when the mouse is pressed.  MyMouseEvents2.java
 *Ravi 24
 *09.04.12
 *Demonstrating mouse events to give the coordinates
*/
import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class MyMouseEvents2 extends Applet implements MouseListener{
                int x=0,y=0;
                public void init()
                {
                                addMouseListener(this);
                }

               
    public void paint(Graphics g)
                {
                                g.drawString("("+x+","+y+")", x,y);
                }
               
                  public void mouseClicked(MouseEvent e){
               
    x = e.getX();
                 y = e.getY();
                repaint();
                //g.drawString("cordinate of x"+x+"cordinate of y"+y);       
               
                }
                public void mouseEntered(MouseEvent e){
                          
                 x = e.getX();
                 y = e.getY();
                repaint();  //System.out.println("mouseEntered");
                                                   }
               
                public void mouseExited(MouseEvent e){
                x = e.getX();
                y = e.getY();
                repaint();//System.out.println("mouseExited");
                }
                public void mousePressed(MouseEvent e){
    x = e.getX();
                y = e.getY();
                repaint();             //System.out.println("mousePressed");
               
                }
                public void mouseReleased(MouseEvent e){
                x = e.getX();
                y = e.getY();
                repaint();
                }
                //public void windowActivated(WindowEvent e){System.out.println("Window activated");}
                //public void windowDeactivated(WindowEvent e){System.out.println("Window Deactived"); }
}




/* 12. Develop a program to meet the following requirements
(a) Create a frame with flow layout
(b) Create two panels and add the panels to the frame
(c) Each panel contains three buttons. The panel uses flow layout

*Layout1.java
*Jagadeesh,10
*30-03-2012
*To create 2 panels each with 3 buttons and add them to a frame
*/
import java.awt.*;
import java.lang.*;
import java.applet.*;
public class Layout1
{
static Frame f=new Frame("FIRST CSE");
 public static void main(String args[])
 {
   Container con=f;
   f.setBounds(100,100,600,200);
   Panel p1=new Panel(new FlowLayout());
   p1.setLayout(new FlowLayout());
   p1.add(new Button("One"));
   p1.add(new Button("Two"));
   p1.add(new Button("Three"));
   f.setLayout(new BorderLayout());
   con.add(p1,BorderLayout.NORTH);
   Panel p2=new Panel(new FlowLayout());
   p2.setLayout(new FlowLayout());
   p2.add(new Button("Four"));
   p2.add(new Button("Five"));
   p2.add(new Button("Six"));
   con.add(p2,BorderLayout.SOUTH);
   f.setVisible(true);
 }
}


/*  13. Develop a program to calculate the future value of an investment at a given interest rate for a
specified number of years. The formula for the calculation is as follows:
Future value = Investment Amount (1+ Interest Rate) years.

*Bank.java
*Ravi 24
*09.04.12
*Interactive input to an applet and Item Event
*/
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class Bank extends Applet implements ItemListener
{                             
                TextField text1, text2,text3,text4;
                int amt=0, years=0, rate=0,futval=0;
                //String result="";
                public void init()
                {
                                Label lob1=new Label();
                                Label lob2=new Label();
                                Label lob3=new Label();
                                Label lob4=new Label();
                                lob1.setText("Amount");
                                lob2.setText("Years");
                                lob3.setText("Rate");
                                lob4.setText("Future Value");
                                text1=new TextField(8);
                                text2=new TextField(8);
                                text3=new TextField(8);
                                text4=new TextField(8);
                                add(lob1);
                                add (text1);
                                add(lob2);
                                add (text2);
                                add(lob3);
                                add (text3);
                                add(lob4);
                                add (text4);
                                text1.setText ("0");
                                text2.setText ("0");
                                text3.setText ("0");
                                text4.setText ("0");
                                List lt=new List(1,false);
                                lt.add("Calculate");
                                lt.addItemListener(this);             
                                add(lt);
                }
                public void paint(Graphics g)
                {
                                //g.drawString("Result is : "+z,25, 75);
                                //s=text2.getText();
                                                //= Integer.parseInt(s2);
                }
                public void itemStateChanged(ItemEvent event)
                {
                String s1=null, s2=null,s3=null;
                                try
                                {
                                                s1=text1.getText();
                                                amt= Integer.parseInt(s1);
                                                s2=text2.getText();
                                                years= Integer.parseInt(s2);
                                                s3=text3.getText();
                                                rate= Integer.parseInt(s3);
                                                //s=text2.getText();
                                                //= Integer.parseInt(s2);
                                }
                                catch (Exception ex) { System.out.println(ex);}
                                if(event.getStateChange()==ItemEvent.SELECTED)
                                {
                                    String s=null;
                                                int           i=(Integer)event.getItem();
                                                List ob=(List) event.getItemSelectable();
                                                if(ob.getItem(i)=="Calculate"){ futval=amt*((1+rate)*years); }
                                                /*if(ob.getItem(i)=="SUB"){ z=x-y;}
                                                if(ob.getItem(i)=="MUL"){ z=x*y; }
                                                if(ob.getItem(i)=="DIV"){ if(y!=0){ z=x/y; }}*/
                                                s=String.valueOf(futval);
                                                text4.setText(s);
                                }
                                repaint();
                }
}