Write a program to simulate the working of bridge
connecting different LANs.
//Bridge
import java.io.*;
import java.applet.*;
import java.awt.*;
/*<applet code="ntdd6.class" width=500
height=500></applet>*/
public class ntdd6 extends Applet
{
public
void init()
{}
public
void start()
{}
public
void paint(Graphics g)
{
g.drawRect(60,100,80,20);
g.drawRect(20,60,20,20);
g.drawRect(20,140,20,20);
g.drawRect(60,40,20,20);
g.drawRect(60,160,20,20);
g.drawRect(120,40,20,20);
g.drawRect(120,160,20,20);
g.drawRect(160,60,20,20);
g.drawRect(160,140,20,20);
g.drawLine(50,110,60,110);
g.drawLine(140,110,150,110);
g.drawLine(50,70,50,150);
g.drawLine(150,70,150,150);
g.drawLine(40,70,50,70);
g.drawLine(150,70,160,70);
g.drawLine(40,150,50,150);
g.drawLine(150,150,160,150);
g.drawLine(100,80,100,100);
g.drawLine(100,120,100,140);
g.drawLine(70,80,130,80);
g.drawLine(70,140,130,140);
g.drawLine(70,60,70,80);
g.drawLine(130,60,130,80);
g.drawLine(70,140,70,160);
g.drawLine(130,140,130,160);
g.drawString("A",25,75);
g.drawString("B",25,155);
g.drawString("C",65,175);
g.drawString("D",125,175);
g.drawString("E",165,155);
g.drawString("F",165,75);
g.drawString("G",65,55);
g.drawString("H",125,55);
g.drawString("Bridge",80,115);
g.drawString("Lan
1",20,110);
g.drawString("Lan
2",85,175);
g.drawString("Lan
3",170,110);
g.drawString("Lan
4",85,55);
}
public
static void main(String s[]) throws IOException
{
char
ch[]=new char[0];
int
i=0;
String
sender, receiver, choice, a="";
String
table[][]=new String[8][2];
InputStreamReader
is=new InputStreamReader(System.in);
BufferedReader
bf=new BufferedReader(is);
boolean
flag, f;
do
{
f=true;
flag=false;
System.out.println("enter
the sender");
sender=bf.readLine();
ch=sender.toCharArray();
for(int
j=0;j<i;j++)
{
a=ch[0]+"";
if(table[j][0].equals(a))
f=false;
}
if(f)
{
switch(ch[0])
{
case
'A':
table[i][0]="A";
table[i][1]="Lan
1";
i++;
break;
case
'B':
table[i][0]="B";
table[i][1]="Lan
1";
i++;
break;
case
'C':
table[i][0]="C";
table[i][1]="Lan
2";
i++;
break;
case
'D':
table[i][0]="D";
table[i][1]="Lan
2";
i++;
break;
case
'E':
table[i][0]="E";
table[i][1]="Lan
3";
i++;
break;
case
'F':
table[i][0]="F";
table[i][1]="Lan
3";
i++;
break;
case
'G':
table[i][0]="G";
table[i][1]="Lan
4";
i++;
break;
case
'H':
table[i][0]="H";
table[i][1]="Lan
4";
i++;
break;
default:
System.out.println("error");
return;
}
}
System.out.println("");
System.out.println("the
content of the table as follows");
System.out.println("");
System.out.println("");
System.out.println("Nodes
lans");
for(int
k=0;k<i;k++)
{
for(int
j=0;j<2;j++)
{
System.out.println(table[k][j]+" ");
}
System.out.println("");
}
System.out.println("");
System.out.println("");
System.out.println("enter
the receiver");
receiver=bf.readLine();
for(int
j=0;j<i;j++)
{
if(table[j][0].equals(receiver))
{
System.out.println("msg
is transfered to"+table[j][1]);
flag=true;
break;
}
}
if(!flag)
{
System.out.println("msg
is transfered to all nodes");
}
System.out.println("do
you want to continue yes/no");
choice=bf.readLine();
}
while(choice.equals("yes"));
}
}
/* output
*enter the
sender
A
the content of the table as follows
Nodes lans
A
Lan 1
enter the receiver
D
msg is transfered to all nodes
do you want to continue yes/no
yes
enter the sender
D
the content of the table as follows
Nodes lans
A
Lan 1
D
Lan 2
enter the receiver
E
msg is transfered to all nodes
do you want to continue yes/no
yes
enter the sender
E
the content of the table as follows
Nodes lans
A
Lan 1
D
Lan 2
E
Lan 3
enter the receiver
A
msg is transfered toLan 1
do you want to continue yes/no
yes
enter the sender
A
the content of the table as follows
Nodes lans
A
Lan 1
D
Lan 2
E
Lan 3
enter the receiver
E
msg is transfered toLan 3
do you want to continue yes/no
yes
enter the sender
D
the content of the table as follows
Nodes lans
A
Lan 1
D
Lan 2
E
Lan 3
enter the receiver
F
msg is transfered to all nodes
do you want to continue yes/no
no
Press any key to continue...
*/
No comments:
Post a Comment