All pastes #921987 Raw Edit

Anonymous

public text v1 · immutable
#921987 ·published 2008-02-28 14:53 UTC
rendered paste body
import java.io.*;
import java.util.*;
import java.util.LinkedList;
import java.lang.*;

class node
{
	public int id;
	public int capability;
	public double pheromone;
	public int comm;

	public node (int id,int capability,double pheromone,int comm)
	{
		this.id=id;
		this.capability=capability;
		this.pheromone=pheromone;
		this.comm=comm;
		
	}

	public node()
	{
		this.id=0;
		this.capability=0;
		this.pheromone=0.0;
		this.comm=0;

	}

	public void get()
	{
		try
		{
	        DataInputStream in = new DataInputStream(System.in);
		System.out.println("Enter the id and capability of the node :");
		id=Integer.parseInt(in.readLine());
		capability=Integer.parseInt(in.readLine());
		System.out.println("Enter the pheromone value between current node and node"+id);	
		pheromone=Double.parseDouble(in.readLine());
		System.out.println("Enter the communication time between current node and node"+id);
		comm=Integer.parseInt(in.readLine());
		}
		catch(Exception e)
		{}
	}

	public void show()
	{
		System.out.println("id = "+id+" Capability ="+capability+"\n"+"pheromone ="+pheromone+"communication time ="+comm);
	}
		
}


public class demo
{

public static void main(String args[])throws IOException
{

	DataInputStream in = new DataInputStream(System.in);
	
	
	int adj_num=0;	
	int capability;
		
	List nodelist = new LinkedList();
	
	System.out.println("Enter the no. of adjacent nodes to current node");
	adj_num=Integer.parseInt(in.readLine());	

	node[] node1= new node[adj_num];

	for(int j=0;j<adj_num;j++)
	{
	if(node1[j]!=null)
	{

			node1[j].get();
			node1[j].show();
			nodelist.add(node1[0]);
	}
	else
	System.out.println("Error!");
	}
	}
}
}