Wednesday, 10 April 2013

JAVA PROGRAMS USING SWINGS PART 1


package GUI;
import javax.swing.*;

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

public class Five extends JPanel implements ActionListener, ItemListener {

String name,hobby,address,citizenship;
static JLabel jl1;

static JMenuBar jmb;
static JMenu jm1;
static JMenuItem jmit1, jmit2, jmit3;
static JTextField jtf;
static JCheckBox jcb;
static JLabel jl2;
static JComboBox jcmb;
static JLabel jl3;
static JTextArea jta;
static JButton jb;
public void actionPerformed(ActionEvent ae){
if(ae.getSource()==jb){
name=jtf.getText();
address=jta.getText();
String tooltip = jb.getToolTipText();
citizenship=jcb.getText();
System.out.println(ae.getActionCommand()+" Was Pressed ");
System.out.println("Name Entered is "+name);
System.out.println(" Address is "+address);
System.out.println(" Citizeship is "+citizenship);
System.out.println(" Tool Tip Text Value for Button is "+tooltip);
}
/*if(ae.getSource()==jcmb){
System.out.println(ae.getActionCommand()+" Was Pressed ");
hobby=(String)jcmb.getSelectedItem();
System.out.println("Hobby Selected is "+hobby);

}*/

}//end actionPerformed

public void itemStateChanged(ItemEvent e){
if(e.getSource() ==jcmb){
if(jcmb.getSelectedItem().equals("Painting")){
System.out.println("Hello Junior MF Hussain!!");
}
else if(jcmb.getSelectedItem().equals("Dancing")){
System.out.println("Hello Junior Vani Ganapathi!!");
}
else if(jcmb.getSelectedItem().equals("Singing")){
System.out.println("Hello Junior Asha Bhosle!!");
}
}
}

public static void main(String a[]){
Five objfive = new Five();
JFrame jf = new JFrame("Frame");
JPanel jp = new JPanel();
jf.add(jp);
jl1 = new JLabel("Enter Your Name");
jtf = new JTextField(15);
jcb = new JCheckBox("Indian Citizen",true);
jl2 = new JLabel("Choose Your Hobby");
jcmb = new JComboBox();
jcmb.addItem("Painting");
jcmb.addItem("Dancing");
jcmb.addItem("Singing");
jcmb.addItem("Trekking");
jl3 = new JLabel("Enter Your Address");
jta = new JTextArea(20,20);
jb = new JButton("Click Me");
jb.setBounds(20,20,120,120);
jb.setToolTipText("Submit Values...See Console");
jmb = new JMenuBar();
jm1 = new JMenu("File");
jm1.setMnemonic(KeyEvent.VK_F);
jmit1 = new JMenuItem("Open");
jmit1.setMnemonic(KeyEvent.VK_O);
        jmit2 = new JMenuItem("Save");
        jmit2.setMnemonic(KeyEvent.VK_S);
        jmit3 = new JMenuItem("Exit");
        jmit3.setMnemonic(KeyEvent.VK_X);
        jmit3.setToolTipText("Exit application");
        jm1.add(jmit1);
        jm1.add(jmit2);
        jm1.add(jmit3);
        jmb.add(jm1);
        //setJMenuBar(jmb);
        jf.setTitle("Simple menu");
jp.add(jl1);
jp.add(jtf);
jp.add(jcb);
jp.add(jl2);
jp.add(jcmb);
jp.add(jl3);
jp.add(jta);
jb.addActionListener(objfive);
//jcmb.addActionListener(objfive);
jcmb.addItemListener(objfive);
jp.add(jb);
//jf.add(jmb);
jf.setSize(400,400);
jf.setVisible(true);
}//end main
}//end class Five

Wednesday, 27 March 2013

JAVA PROGRAMS USING LINKEDLIST, GENERIC COLLECTIONS FOR STUDENT LIST


 import java.util.*; /* scanner function is used*/

class StudList {
  private String name;
  private String USN;
  private String college;

   StudList(String n, String s, String c) {
    name = n;
    USN = s;
    college = c;
  }

  public String toString() {
    return name + ":" + USN + ":" + college;
  }
}

public class FourB {
  public static void main(String args[]) 
{
  LinkedList<StudList> ml = new LinkedList<StudList>();

  ml.add(new StudList("Shwetha", "1MS00IS101", "MSRIT"));
  ml.add(new StudList("Mishti", "1MS00IS102", "RVCE"));
  ml.add(new StudList("Purvi ", "1MS00IS103","BMSCE"));
  ml.add(new StudList("Aditya", "1MS00IS104", "PESIT"));
  ml.add(new StudList("Rohit", "1MS00IS105", "NMIT"));


System.out.println("Accessing Via Iterator....");
Iterator<StudList> it = ml.iterator();

while (it.hasNext()) {
   String element=it.next().toString();
   System.out.println(element + "");
}

System.out.println("Number of students in the list: "+ml.size());

System.out.println("Which student do you want to remove?");
Scanner s = new Scanner(System.in);
int pos = s.nextInt();
ml.remove(pos);

System.out.println("New Kind of For Loop...List is now...");
    for (StudList element : ml){
      System.out.println(element);
    }
System.out.println("Number of students in the list is"+ml.size());
System.out.println("Shuffling the list...");
Collections.shuffle(ml);
System.out.println("List after shuffling is ...");
    for (StudList element : ml){
      System.out.println(element);
    }

System.out.println("First Student is :"+ml.getFirst());
System.out.println("Last Student is :"+ml.getLast());
  }
}



Sunday, 24 March 2013

CN2 LEAKY BUCKET PROGRAM


#include<stdio.h>
#include<stdlib.h>
#define MIN(x,y) (x>y)? y:x
int main()
{

    int orate, drop=0,cap,x,count=0,inp[10]={0},i=0,nsec,ch;
    printf("\n enter the bucket size");
    scanf("%d",&cap);
    printf("\n enter the output rate");
    scanf("%d",&orate);
    do
    {
        printf("\n enter the number of packets coming at second %d",i+1);
        scanf("%d",&inp[i]);
        i++;
        printf("\n press 1 to continue or 0 to exit------");
        scanf("%d",&ch);
        }
         while(ch);
         nsec=i;
        printf("\n sec\t rec\t sent\t drop\t rem\n");
        for(i=0;count||i<nsec;i++)
       {
        printf("%d",i+1);
        printf("\t %d\t",inp[i]);
        printf("%d\t", MIN((inp[i]+count),orate));
        if((x=inp[i]+count-orate)>0)
        {
           if(x>cap)
           {
             count=cap;
            drop=x-cap;
            }
            else
            count=x;
            drop=0;
            }
        else
        {
        drop=0;
        count=0;
        }
        printf("%d\t %d\n",drop,count);
    }
    }
    


Thursday, 7 March 2013

SS pass1 assembler program


there following files have to be included in the program 
# include <stdio.h>
# include <string.h>
void main()
{
char opcode[10],mnemonic[3],operand[10],label[10],code[10];
int locctr,start,length;
FILE *fp1,*fp2,*fp3,*fp4;
fp1=fopen("input.txt","r");
fp2=fopen("symtab.txt","w");
fp3=fopen("out.txt","w");
fp4=fopen("optab.txt","r");
fscanf(fp1,"%s%s%s",label,opcode,operand);
if(strcmp(opcode,"START")==0)
{
start=atoi(operand);
locctr=start;
fprintf(fp3,"\t%s\t%s\t%s\n",label,opcode,operand);
fscanf(fp1,"%s%s%s",label,opcode,operand);
}
else
locctr=0;
while(strcmp(opcode,"END")!=0)
{
fprintf(fp3,"%d\t",locctr);
if(strcmp(label,"**")!=0)
fprintf(fp2,"%s\t%d\n",label,locctr);
rewind(fp4);
fscanf(fp4,"%s",code);
while(strcmp(code,"END")!=0)
{
if(strcmp(opcode,code)==0)
{
locctr+=3;
break;
}
fscanf(fp4,"%s",code);
}
if(strcmp(opcode,"WORD")==0)
locctr+=3;
else if(strcmp(opcode,"RESW")==0)
locctr+=(3*(atoi(operand)));
else if(strcmp(opcode,"RESB")==0)
locctr+=(atoi(operand));
else if(strcmp(opcode,"BYTE")==0)
++locctr;
fprintf(fp3,"%s\t%s\t%s\n",label,opcode,operand);
fscanf(fp1,"%s%s%s",label,opcode,operand);
}
fprintf(fp3,"%d\t%s\t%s\t\%s\n",locctr,label,opcode,operand);
length=locctr-start;
printf("The length of the program is %d",length);
fclose(fp1);
fclose(fp2);
fclose(fp3);
fclose(fp4);
}

INPUT FILES

input.txt


** START 2000
** LDA FIVE
** STA ALPHA
** LDCH CHARZ
** STCH C1
ALPHA RESW 1
FIVE WORD 5
CHARZ BYTE C’Z’
C1 RESB 1
** END **

optab.txt

START
LDA
STA
LDCH
STCH
END


OUTPUT FILES

out.txt

** START 2000
2000 ** LDA FIVE
2003 ** STA ALPHA
2006 ** LDCH CHARZ
2009 ** STCH C1
2012 ALPHA RESW 1
2015 FIVE WORD 5
2018 CHARZ BYTE C’Z’
2019 C1 RESB 1
2020 ** END **

symtab.txt

ALPHA 2012
FIVE 2015
CHARZ 2018
C1 2019




JAVA PACKAGES PROGRAMS


We have to create 3 different packages for this program  and execute  it.

Vehicle.java



package package1;

public abstract class Vehicle
{    
            public int year;
            public abstract void getData();
            public abstract void putData();
}

class FourWheeler extends Vehicle{
            public void getData()
            {
                  year=92;
            }
            public void putData()
            {
                  System.out.println("Year of manufacture of the fourwheeler is"+year);
            }
}
 

prog2.java

package package2;
import package1.*;
class TwoWheeler extends Vehicle{
      private String EngineType="2-s";
      protected String Brand="Y";
      public String Color="Black";
      public void getData()
      {
                  EngineType="2-stroke";
                  Brand="Yamaha";
                  Color="Black";
                  year=88;
      }
      public void putData()
      {
                  System.out.println("Year of manufacture of the twowheeler is"+year);
                  System.out.println("Engine type is " +EngineType+" ,Brand is "+Brand+" ,Color is "+Color);
      }
            void printprivate()
      {
                  System.out.println("Accessing private variable"+ EngineType);
      }
      }
class MyTwoWheeler extends TwoWheeler
{
      public String OwnerName;
      MyTwoWheeler()
      {
            super();
            OwnerName="Mandhara";
            printprivate();
            System.out.println(""+Brand+" "+Color+" "+OwnerName);
      }
     
}

public class prog2 {
      public static void main(String[] args)
      {
            TwoWheeler a=new TwoWheeler();
            a.getData();
            a.putData();
            MyTwoWheeler b=new MyTwoWheeler();
      }

}
 

prog.java

package package3;

public class prog {

}
 






Tuesday, 26 February 2013

CN LAB PROGRAM DISTANCE VECTOR ALGORITHM

#include<stdio.h>
#include<stdlib.h>
#define NUL 1000
#define NODES 10
struct node
{
int t[NODES][3];
};
struct node n[NODES];
typedef struct node NOD;
int main()
{
void init(int,int);
void inp(int,int);
void caller(int,int);
void op(int,int,int);
void find(int,int);
int i,j,x,y,no;
do
{
printf("\n enter the no of nodes required(less than 10):");
scanf("%d",&no);
}while(no>10||no<0);  
for(i=0;i<no;i++)
{
init(no,i);
inp(no,i);
}
printf("\n the configuration of the nodes after initialization is as follows”);                              for(i=0;i<no;i++)
op(no,i,0);
for(j=0;j<no;j++)
{
for(i=0;i<no;i++)
caller(no,i);
}printf("\n the configuration of the nodes after the comparision of the paths is as follows:");
for(i=0;i<no;i++)
op(no,i,1);
while(1) {
printf("\n enter 0 to exit or any key to find the shortest path:");
scanf("%d",&j);
if(!j) break;
system("clear");
do{
printf("enter the nodes between which path is to befound:")
scanf("%d%d",&x,&y);
}
while((x<0||x>no)&&(y<0||y>no));
printf("\n the most suitable result from node %d to %d is as follows\n",x,y);
find(x,y);
printf("%d",y);
printf("the length of the shortest path between node %d & %d is%d",x,y,n[x-1].t[y-1][2]);
}
}
void init(int no,int x)
{
int i;
for(i=0;i<no;i++)
{
n[x].t[i][1]=i;
n[x].t[i][2]=999;
n[x].t[i][3]=NUL;
}
n[x].t[x][2]=0;
n[x].t[x][3]=x;
}
void inp(int no,int x)
{
int i;
printf("\n enter the dist from nodes %d to other node",x+1);
printf("\n enter 999 if there is no direct\n");
for(i=0;i<no;i++)
{
if(i!=x)
{
do
{       
printf("\n enter the distance to node %d=",i+1);
scanf("%d",&n[x].t[i][2]);
}
while(n[x].t[x][2]<0||n[x].t[i][2]>999);
if(n[x].t[i][2]!=999)        
n[x].t[i][3]=i;
}
}
}
void caller(int no,int x)
{
void compar(int,int,int);
int i;
for(i=0;i<no;i++)
{
if(n[x].t[i][2]!=999&&n[x].t[i][2]!=0)
compar(x,i,no);
}
}
void compar(int x,int y,int no)
{
int i,z;
for(i=0;i<no;i++)
{
z=n[x].t[y][2]+n[y].t[i][2];
if(n[x].t[i][2]>z)
{
n[x].t[i][2]=z;
n[x].t[i][3]=y;
}
}
}
void op(int no,int x,int z)       
{
int i,j;
printf("\nthe routing table for node %d is as follows",x+1);
printf("\n\n\t\t\tDESTINATION\tDISTANCE\tnext hop");
for(i=0;i<no;i++)                    
{
if((!z&&n[x].t[i][2]>=999||n[x].t[i][2]>=(999*no)))
printf("\n\t\t\t%d\tno link\t\tnext hop",n[x].t[i][1]+1);
else
{
if(n[x].t[i][3]==NUL)
printf("\n\t\t\t%d\t\t%d\t\tno hop",n[x].t[i][1]+1,n[x].t[i][2]);
else
printf("\n\t\t\t%d\t\t%d\t\t%d",n[x].t[i][1]+1,n[x].t[i][2],n[x].t[i][3]+1);
}
}
}
void find(int x,int y)
{
int i,j;
i=x-1;
j=y-1;
printf("%d-->",x);
if(n[i].t[j][3]!=j)
{
find(n[i].t[j][3]+1,y);
return;
}
}



Wednesday, 23 January 2013

latest news

hey guys will be uploading 6th sem lab programs soon in the same blog . Thanking you in advance