Question

In: Computer Science

Lab 7. Boolean Expressions a) Write a program that evaluates the following expressions. Assign reasonable values...

Lab 7. Boolean Expressions a) Write a program that evaluates the following expressions. Assign reasonable values to the variables. Print the results. a<b≥c , √a−7 b2 ≠c , d∨e∧f , a<b∨¬d ∧means and, ∨means inclusive or, ¬ means not. b) Write a program that asks a user whether he or she wants to become a Java programmer and determines if the user typed “yes” (Print true if yes and false otherwise.) Don't use the if
statement here

Solutions

Expert Solution

//Test java program for the expressions
//Lab7.java
public class Lab7
{
   public static void main(String[] args)
   {
       boolean result;
      
       int a=10;
       int b=20;
       int c=5;
      
       //Expression : a< b>=c
       //The above expression can be written as b>a && b>=c
      
       result= b>a && b>=c;
       System.out.println("a = "+a);
       System.out.println("b = "+b);
       System.out.println("c = "+c);
       System.out.println(" a< b>=c = "+result);
      
       //Expression : √a−7
       System.out.println("Sqrt of ( a−7) = "+Math.sqrt(a-7));
      
       //Expression :b2 ≠c
       result=!(b*b==c);
       System.out.println("b2 ≠c = "+result);
      
       boolean d=true;
       boolean e=true;
       boolean f=false;
      
       System.out.println("d = "+d);
       System.out.println("e = "+e);
       System.out.println("f = "+f);
      
       //Experssion : d∨e∧f
       result =d || e && f;
       System.out.println("d∨e∧f = "+result);
       //Expression : a<b∨¬d
       result =(a<b ) || !(d);
       System.out.println("a<b∨¬d = "+result);
      
   }
}

-----------------------------------------------------------------------------------------------

Sample Output:

a = 10
b = 20
c = 5
a< b>=c = true
Sqrt of ( a−7) = 1.7320508075688772
b2 ≠c = true
d = true
e = true
f = false
d∨e∧f = true
a<b∨¬d = true

----------------------------------------------------------------------------------------------------------------------------------------

//Exercise_1.java
import java.util.Scanner;
public class Exercise_1
{
   public static void main(String[] args)
   {
       Scanner console=new Scanner(System.in);
       //prompt for user input
       System.out.println("Do you want to become a java developer ?");
       String response=console.nextLine();
      
       //Using ternary operator
       //result =expression ? statement1 : statement2
       //statement1 is executed if expression is true
       //otherwise statement2 will be executed.
      
       //checking if response is yes then
       boolean result=response.equalsIgnoreCase("yes")?true:false;
       System.out.println(result);
      
   }

}

----------------------------------------------------------------------------------------------------------------------------

Sample Output:

Do you want to become a java developer?
yes
true


Related Solutions

write a program that evaluates the following arithmetic expression: ((A+B)/C)*((D-A)+E). Assign test values to the variables...
write a program that evaluates the following arithmetic expression: ((A+B)/C)*((D-A)+E). Assign test values to the variables and display the resulting value.
1. Use Boolean algebra to simplify the following Boolean expressions to expressions containing a minimum number...
1. Use Boolean algebra to simplify the following Boolean expressions to expressions containing a minimum number of literals: (a) A’C’ + A’BC + B’C (b) (A + B + C)’(ABC)’ (c) ABC’ + AC (d) A’B’D + A’C’D + BD (e) (A’ + B)’(A’ + C’)’(AB’C)’ (f) (AE + A’B’)(C’D’ + CD) + (AC)’ 2. Obtain the truth table of the function F = (AB + C)(B + AC), express the function F in sum-of-minterms and product-of-maxterms forms, and express...
write a java program tht evaluates postfix expressions. args[0] = the output file the answer will...
write a java program tht evaluates postfix expressions. args[0] = the output file the answer will print to
Simplify the following Boolean expressions to the minimum number of terms using the properties of Boolean...
Simplify the following Boolean expressions to the minimum number of terms using the properties of Boolean algebra (show your work and write the property you are applying). State if they cannot be simplified A. X’Y + XY B. (X + Y)(X + Y’) C. (A’ + B’) (A + B)’ D. ABC + A’B + A’BC’ E. XY + X(WZ + WZ’)
Simplify the following Boolean expressions to the minimum number of terms using the properties of Boolean...
Simplify the following Boolean expressions to the minimum number of terms using the properties of Boolean algebra (show your work and write the property you are applying). State if they cannot be simplified. A. A’B + AB B. XY + X(WZ + WZ’) C. X’Y’(X’+Y)(Y’+Y) D. ABC + A’B + A’BC’ E. (A+B)(AC+AC’)+AB+B Draw the circuit logic diagrams for both the original and simplified expressions.
In a Java program, how could I write a program that can assign values that would...
In a Java program, how could I write a program that can assign values that would make a rock paper scissors game work? I have a program that will generate a computer response of either rock, paper, or scissors but how can I compare a user input of "rock", "paper", or "scissors" so that we can declare either the user or the computer the winner.
write a Java program Write a program to assign a letter grade according to the following...
write a Java program Write a program to assign a letter grade according to the following scheme: A: total score >= 90 B: 80 <= total score < 90 C: 70 <= total score < 80 D: 60 <= total score < 70 F: total score < 60 Output - the student's total score (float, 2 decimals) and letter grade Testing - test your program with the following input data: test1 = 95; test2 = 80; final = 90; assignments...
C++ Data Structure Write a program to change following infix expressions to postfix expressions using a...
C++ Data Structure Write a program to change following infix expressions to postfix expressions using a stack a) D-B+C b) C*D+A*B c) (A*B)*C+D*F-C d) (A-4*(B-C)-D/E)*F
Determine the value, true or false, of each of the following Boolean expressions, assuming that the...
Determine the value, true or false, of each of the following Boolean expressions, assuming that the value of the variable count is 0 and the value of the variable limit is 10. Give your answer as one of the values true or false. a. (count == 0) && (limit < 20) b. count == 0 && limit < 20 c. (limit > 20) || (count < 5) d. !(count == 12) e. (count == 1) && (x < y) f....
Write a class Lab7 that reads and evaluates postfix expressions contained in a file. Each line...
Write a class Lab7 that reads and evaluates postfix expressions contained in a file. Each line of the file contains a postfix expression with integers as operands and ‘+’, ‘-’, ‘*’ and ‘/’ as operators. Consecutive operands and operators are separated by spaces. Note the following requirements for the lab: • The main method in Lab7.java should do the following. 1. ask the user for the name of the file containing the expressions, 2. for each line of the file,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT