class Main { public static void main(String[] args) { java.util.Scanner scan = n
ID: 3742711 • Letter: C
Question
class Main {
public static void main(String[] args) {
java.util.Scanner scan = new java.util.Scanner(System.in);
System.out.println("Please enter two booleans (true or false):");
boolean isWearingShirt = scan.nextBoolean();
boolean isWearingShoes = scan.nextBoolean();
boolean isServed;
// TODO: write the expression for "no shirt, no shoes, no service"
// using isServed, isWearingShirt, and isWearingShoes.
if
System.out.println("isWearingShirt = " + isWearingShirt);
System.out.println("isWearingShoes = " + isWearingShoes);
System.out.println("isServed = " + isServed);
}
}
On line 11 add a statement to set isServed to the combination of isWearingShirt and isWearingShoes that matches the English expression.
Explanation / Answer
public class Main {
public static void main(String[] args) {
java.util.Scanner scan = new java.util.Scanner(System.in);
System.out.println("Please enter two booleans (true or false):");
boolean isWearingShirt = scan.nextBoolean();
boolean isWearingShoes = scan.nextBoolean();
boolean isServed = false;
// TODO: write the expression for "no shirt, no shoes, no service"
// using isServed, isWearingShirt, and isWearingShoes.
if( isWearingShirt && isWearingShoes)
isServed = true;
System.out.println("isWearingShirt = " + isWearingShirt);
System.out.println("isWearingShoes = " + isWearingShoes);
System.out.println("isServed = " + isServed);
}
}
/*SAMPLE OUTPUT
Please enter two booleans (true or false):
true true
isWearingShirt = true
isWearingShoes = true
isServed = true
Please enter two booleans (true or false):
true false
isWearingShirt = true
isWearingShoes = false
isServed = false
*/
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.