Categories
Study Questions

Java coding problem (Boolean algebra and truth tables)

Write a program to generate a truth table for a given Boolean statement. For example, A + B * C produces the following table:

A B C | B * C | A + B * C

===============================

0 0 0 | 0 | 0

0 0 1 | 0 | 0

0 1 0 | 0 | 0

0 1 1 | 1 | 1

1 0 0 | 0 | 1

1 0 1 | 0 | 1

1 1 0 | 0 | 1

1 1 1 | 1 | 1

Input from the keyboard a string representing a Boolean expression where the operators are the following: ! (NOT), * (AND), + (OR), ^ (XOR). Single sets of parentheses can be used if needed. Covert all letters to uppercase and have one space between each operator. The truth table must be able to handle up to four variables and be in binary order. For example, in the first test case, if the Boolean values of A, B, and C were replaced with 1’s for true and 0’s for false, the Boolean combination with the smallest binary representation would come first.

Output to the screen a truth table for the given Boolean expression. The first column of the truth table should represent A, the second B, the third C, and so on. Each binary operation must have its own column and all columns must be labeled. The entries in each column should be aligned and formatted with capital letters like the examples below. Except for the final column, columns do not have to be in any order except the order of operations must be followed to get the correct final answer. Finally, the program should ask if the user wants to run the program again (Check case). Refer to the sample output below.

Sample Run:

Enter the Boolean expression: A + B * C

A B C | B * C | A + B * C

===============================

0 0 0 | 0 | 0

0 0 1 | 0 | 0

0 1 0 | 0 | 0

0 1 1 | 1 | 1

1 0 0 | 0 | 1

1 0 1 | 0 | 1

1 1 0 | 0 | 1

1 1 1 | 1 | 1

Run again (Y/N)? y

Enter the Boolean expression: (!A * B) ^ (B + C)

A B C | !A * B | B + C | (!A * B) ^ (B + C)

=================================================

0 0 0 | 0 | 0 | 0

0 0 1 | 0 | 1 | 1

0 1 0 | 1 | 1 | 0

0 1 1 | 1 | 1 | 0

1 0 0 | 0 | 0 | 0

1 0 1 | 0 | 1 | 1

1 1 0 | 0 | 1 | 1

1 1 1 | 0 | 1 | 1

Run again (Y/N)? N

This page is having a slideshow that uses Javascript. Your browser either doesn't support Javascript or you have it turned off. To see this page as it is meant to appear please use a Javascript enabled browser.

Jessy
Jessy
Just a bit off from the syllabus rubric, but I can add to the slides on my own. Thank you anyway.
Alvin
Alvin
To the writer, THANK YOU, a million times over, this is very impressive! Thank you to the support team for making a hiccup not turn into a disaster!
Milly.P
Milly.P
There was consistent communication from the start, and it was obvious the writer thoroughly reviewed the information provided. Thank you.
Ivy.G
Ivy.G
Excellent work all the time! love my writer also. Don't know if I'm supposed to do this but I just need to say this writer does excellent work!
Emily.s
Emily.s
The writer followed my instruction thoroughly and did a great job. The quality of the paper is more than I expected. Thank you.
Justus N
Justus N
You people have been really patient with me as I created mechanical engineering content. It’s not an easy topic to handle, yet I can say that I worked with a skilled specialist. My writer took time to understand my ideas but it was mostly my fault. Just share more details.
Kelly H
Kelly H
When I received a paper revision from my new college professor, I was desperate as I didn’t know what to do. If not for Academized, I would be doomed. They know how to fix things for you and explain what was wrong as they fix it.
Paul D
Paul D
You're the best, I'll be using your services again soon! Thank you Thank you Thank you!
Mark P.
Mark P.
I asked my writer to help me compose a personal essay about charity work that I do at the local church. It is not easy for me to express myself in words, which is why I needed some privacy and a good person who would appreciate my thoughts and ideas.

error: Content is protected !!
Open chat
1
Do You Need Assignment Help? Lets Chat!
StudyPoo Inc.
Get Help Instantly direct from an Expert.

Talk through Live Chat right now!