Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

4) Write a Java program to compute the truth table for this \"optimal\" Boolean

ID: 3913336 • Letter: 4

Question

4) Write a Java program to compute the truth table for this "optimal" Boolean polynomial. For each row of the truth table, the main program should call an int function LCircuit, having four int parameters, that calculates the output of the digital circuit for a given set of inputs. All int variables should take only the values 0 (false) and 1 (true). The LCircuit function should call int functions ANDgate(x,y), ORgate(x,y), and NOTgate(x) as needed.

f| 1 1 1 1 0 1 0 0 W01010101 72| 0 0 1 1 0 0 1 1 y00001111 f| 0 0 1 1 1 1 0 0 | W| 0 1 0 1 0 1 0 1 z| 0 0 1 1 0 0 1 1 y0000-111

Explanation / Answer

import java.util.*;

import java.io.*;

class optimal

{

public static void main (String[] args) // declaring 'main' function

{

optimal obj = new optimal(); // creating object

int x, y, z, w;

System.out.println("x y z w f");

for(x=0; x<2; x++)

{

for(y=0; y<2; y++)

{

for(z=0; z<2; z++)

{

for(w=0; w<2; w++)

obj.LCircuit(x, y, z, w); // caling "LCircuit" function

}

}

}

}

public int LCircuit(int x, int y, int z, int w) // taking 4 int inputs and displaying the result

{

System.out.print(x + " " + y + " " + z + " " + w + " ");

if(x == 0 && y == 0)

System.out.println(z);

else if(x == 0 && y == 1)

System.out.println(NOTgate(z));

else if(x == 1 && y == 0)

System.out.println(x);

else

System.out.println(ANDgate(NOTgate(z), w));

return 0;

}

public int ANDgate(int x,int y) // function to calculate x AND y

{

if(x == 1 && y == 1)

return 1;

else

return 0;

}

public int ORgate(int x,int y) // function to calculate x OR y

{

if(x == 0 && y == 0)

return 0;

else

return 1;

}

public int NOTgate(int x) // function to calculate NOT x

{

return (x == 0 ? 1 : 0);

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote