this is a problem for electrical circuit.
we have a input x and i/o file <number><type> <input1><input2>
also a input can be a number of port and the last line is<Y><input>
were input is the number of which port we want the result.
example of io

<1><AND><X><X> 
<2><OR><X><1>
<Y><2>

if is not port we just take input1.

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.lang.reflect.Array;
import java.util.LinkedList;
public class komponenti {
    String tip;
    boolean vl1,vl2;
    int redBr;
    boolean vlez1,vlez2,izlez;

    komponenti(int redBr, String tip, boolean vl1, boolean vl2)
    {
        this.redBr=redBr;
        this.tip=tip;
        this.vl1=vl1;
        this.vl2=vl2;
        this.izlez=this.func();
    }
    komponenti(String tip, boolean vl1,boolean vl2)
    {
        this.tip=tip;
        this.vl1=vl1;
        this.vl2=vl2;
    }
    public void ToString()
    {
        System.out.println(redBr + " "+ vl1+ "  "+ vl2+"  "+tip);
    }
     public boolean func()
     {
         if(tip=="AND")
         {
             if (this.vl1 && vl2)
             {
                 return true;
             }
             else
                 return false;
        }
         else
             if(tip=="OR")
             {
                 if(this.vl1==false && this.vl2==false)
                     return false;
                 else
                     return true;
             }
             else
                 if(tip=="NOT")
                 {
                     if(vl1==true)
                         return false;
                     else
                         return true;
                 }
                 else
                 {
                     if(vl1==vl2)
                         return false;
                     else
                         return true;
                 }
     }


}
public class kolo 
{
 boolean funkcija(boolean X) throws IOException
 {
     int Y=1;
        BufferedReader in=new BufferedReader(new FileReader("kolata.txt"));
        LinkedList a=new LinkedList();
        String s;
        boolean vll1,vll2;
        int port1,port2;

        while((s=in.readLine())!=null)
        {
           System.out.println(s);
           String niza[]=new String [4];
           if(in.readLine()!=null){}
           int i=0;
           int j=0;
           for (i=0;i<4;i++)
           {
               niza[i]="";
           }
           if (s.charAt(2)!='Y')
           {
               for(i=0;i<s.length();i++)
               {
                   if (s.charAt(i)=='<')
                       continue;
                       else
                          if(s.charAt(i)=='>')
                             {j++; continue;}
                                 else
                                    niza[j]=niza[j]+s.charAt(i);

                }
               System.out.print(niza[0]+"   "+niza[1]+"  "+niza[2]+"  "+niza[3]);  
               if ( niza[2].equalsIgnoreCase("X"))
               {
                   vll1=X;

               }
               else
               {

                port1=Integer.parseInt(niza[2]); 

                vll1=((komponenti)(a.get(port1))).izlez;
               }
               if(niza[3].equalsIgnoreCase("X"))
               {
                   vll2=X;
               }
               else
               {
                   port2=Integer.parseInt(niza[3]); 
                   vll2=((komponenti)(a.get(port2))).izlez;
               }
              komponenti komp=new komponenti(Integer.parseInt(niza[0]),niza[1],vll1,vll2);
              a.add(komp);
           }
           else
               {
               int kl=3;
               String t="";
               while (s.charAt(kl)!='>')
                   {
                       t=t+s.charAt(kl);
                        kl++; 
                   }
               Y=Integer.parseInt(t);

               }

        }


        return ((komponenti)(a.get(Y))).izlez;



 }



    public static void main(String[] args) throws IOException 
    {
        kolo t=new kolo();
        t.funkcija(false);


    }
}

Edited 3 Years Ago by Reverend Jim: Fixed formatting

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.lang.reflect.Array;
import java.util.LinkedList;
public class komponenti {
	String tip;
	boolean vl1,vl2;
	int redBr;
	boolean vlez1,vlez2,izlez;
	
	komponenti(int redBr, String tip, boolean vl1, boolean vl2)
	{
		this.redBr=redBr;
		this.tip=tip;
		this.vl1=vl1;
		this.vl2=vl2;
		this.izlez=this.func();
	}
	komponenti(String tip, boolean vl1,boolean vl2)
	{
		this.tip=tip;
		this.vl1=vl1;
		this.vl2=vl2;
	}
	public void ToString()
	{
		System.out.println(redBr + " "+ vl1+ "  "+ vl2+"  "+tip);
	}
	 public boolean func()
	 {
		 if(tip=="AND")
		 {
			 if (this.vl1 && vl2)
			 {
				 return true;
			 }
			 else
				 return false;
		}
		 else
			 if(tip=="OR")
			 {
				 if(this.vl1==false && this.vl2==false)
					 return false;
				 else
					 return true;
			 }
			 else
				 if(tip=="NOT")
				 {
					 if(vl1==true)
						 return false;
					 else
						 return true;
				 }
				 else
				 {
					 if(vl1==vl2)
						 return false;
					 else
						 return true;
				 }
	 }
	
	 
}
public class kolo 
{
 boolean funkcija(boolean X) throws IOException
 {
	 int Y=1;
		BufferedReader in=new BufferedReader(new FileReader("kolata.txt"));
		LinkedList a=new LinkedList();
		String s;
		boolean vll1,vll2;
		int port1,port2;
		
		while((s=in.readLine())!=null)
		{
		   System.out.println(s);
		   String niza[]=new String [4];
		   if(in.readLine()!=null){}
		   int i=0;
		   int j=0;
		   for (i=0;i<4;i++)
		   {
			   niza[i]="";
		   }
		   if (s.charAt(2)!='Y')
		   {
			   for(i=0;i<s.length();i++)
			   {
				   if (s.charAt(i)=='<')
					   continue;
					   else
						  if(s.charAt(i)=='>')
				             {j++; continue;}
				                 else
				             	    niza[j]=niza[j]+s.charAt(i);
				   
				}
			   System.out.print(niza[0]+"   "+niza[1]+"  "+niza[2]+"  "+niza[3]);  
			   if ( niza[2].equalsIgnoreCase("X"))
			   {
				   vll1=X;
				   
			   }
			   else
			   {
				   
				port1=Integer.parseInt(niza[2]); 
				
				vll1=((komponenti)(a.get(port1))).izlez;
			   }
			   if(niza[3].equalsIgnoreCase("X"))
			   {
				   vll2=X;
			   }
			   else
			   {
				   port2=Integer.parseInt(niza[3]); 
				   vll2=((komponenti)(a.get(port2))).izlez;
			   }
		      komponenti komp=new komponenti(Integer.parseInt(niza[0]),niza[1],vll1,vll2);
		      a.add(komp);
		   }
		   else
			   {
			   int kl=3;
			   String t="";
			   while (s.charAt(kl)!='>')
				   {
					   t=t+s.charAt(kl);
					    kl++; 
				   }
			   Y=Integer.parseInt(t);
			   
			   }
		   
		}
	
		
		return ((komponenti)(a.get(Y))).izlez;
		   
		   
		 
 }
	 
 

	public static void main(String[] args) throws IOException 
	{
		kolo t=new kolo();
		t.funkcija(false);
		

	}
}
This article has been dead for over six months. Start a new discussion instead.