Podcast
Questions and Answers
What message is printed when the value of gradeValue is set to 85?
What message is printed when the value of gradeValue is set to 85?
In the computeTaxes() method, how much tax is applied to an income of $60,000?
In the computeTaxes() method, how much tax is applied to an income of $60,000?
What is the output of triangleType() if the sides are 3.0, 4.0, and 5.0?
What is the output of triangleType() if the sides are 3.0, 4.0, and 5.0?
Which condition would cause the computeTaxes() method to apply a 20% tax rate?
Which condition would cause the computeTaxes() method to apply a 20% tax rate?
Signup and view all the answers
What would the output be for the gradeValue of 65 in the conditional structure?
What would the output be for the gradeValue of 65 in the conditional structure?
Signup and view all the answers
What is the value of blah when evaluated with the expression blah = !(distance > 20) || speed == 7.5?
What is the value of blah when evaluated with the expression blah = !(distance > 20) || speed == 7.5?
Signup and view all the answers
What would the console output be when running the following code? isVerified = true; duration = 6; animal = null;
What would the console output be when running the following code? isVerified = true; duration = 6; animal = null;
Signup and view all the answers
Evaluate the result of blah for blah = bird.compareTo("Sparrow") < 0.
Evaluate the result of blah for blah = bird.compareTo("Sparrow") < 0.
Signup and view all the answers
What will blah be when evaluated with blah = height % 3 == 0 && width / 4 >= 7?
What will blah be when evaluated with blah = height % 3 == 0 && width / 4 >= 7?
Signup and view all the answers
Determine the output of blah for blah = Math.pow(speed, 2) <= height.
Determine the output of blah for blah = Math.pow(speed, 2) <= height.
Signup and view all the answers
What does the expression blah = Math.min(height, width) > Math.sqrt(distance) evaluate to?
What does the expression blah = Math.min(height, width) > Math.sqrt(distance) evaluate to?
Signup and view all the answers
If isVerified = false; duration = 3; animal = ""; what will be the console output?
If isVerified = false; duration = 3; animal = ""; what will be the console output?
Signup and view all the answers
What will blah evaluate to for blah = height != width?
What will blah evaluate to for blah = height != width?
Signup and view all the answers
Which type of triangle is formed when all three sides are equal?
Which type of triangle is formed when all three sides are equal?
Signup and view all the answers
What does the triangleType method return when two sides are equal and the third is different?
What does the triangleType method return when two sides are equal and the third is different?
Signup and view all the answers
In the context of triangle classification, when should you classify a triangle as a Right Triangle?
In the context of triangle classification, when should you classify a triangle as a Right Triangle?
Signup and view all the answers
What is the result of !(numPets > 3 || isFunny) using De Morgan's Laws?
What is the result of !(numPets > 3 || isFunny) using De Morgan's Laws?
Signup and view all the answers
Which statement is true about the comparison of phrase and text in the code?
Which statement is true about the comparison of phrase and text in the code?
Signup and view all the answers
What will be the outcome of blah = ugh.equals(ahh) in the given code?
What will be the outcome of blah = ugh.equals(ahh) in the given code?
Signup and view all the answers
What will blah be set to when evaluated: blah = word.compareTo(quote) < 0?
What will blah be set to when evaluated: blah = word.compareTo(quote) < 0?
Signup and view all the answers
Which statement is correct regarding the evaluation of blah = word.equals(ugh)?
Which statement is correct regarding the evaluation of blah = word.equals(ugh)?
Signup and view all the answers
What is printed when the value of 'animal' is null and duration is less than 4?
What is printed when the value of 'animal' is null and duration is less than 4?
Signup and view all the answers
Under what condition would 'E' be printed?
Under what condition would 'E' be printed?
Signup and view all the answers
What will happen if duration is 3 and 'isVerified' is true?
What will happen if duration is 3 and 'isVerified' is true?
Signup and view all the answers
What output occurs when 'isVerified' is true and animal is non-empty with last letter 'a'?
What output occurs when 'isVerified' is true and animal is non-empty with last letter 'a'?
Signup and view all the answers
What is printed when duration is 7 and 'animal' is 'octopus'?
What is printed when duration is 7 and 'animal' is 'octopus'?
Signup and view all the answers
If 'animal' is an empty string and duration is exactly 5, what gets printed?
If 'animal' is an empty string and duration is exactly 5, what gets printed?
Signup and view all the answers
What is the condition needed to print 'C' when 'animal' is null?
What is the condition needed to print 'C' when 'animal' is null?
Signup and view all the answers
What prints when duration is a negative number with 'animal' being non-empty?
What prints when duration is a negative number with 'animal' being non-empty?
Signup and view all the answers
Which statement best describes the output when 'isVerified' is false and duration is 6?
Which statement best describes the output when 'isVerified' is false and duration is 6?
Signup and view all the answers
What happens when 'animal' is 'zebra' and duration is 4?
What happens when 'animal' is 'zebra' and duration is 4?
Signup and view all the answers
Study Notes
Variable Manipulation
-
blah = height + width == 43;
evaluates to true because the sum ofheight
andwidth
is equal to 43. -
blah = !(distance > 20) || speed == 7.5;
evaluates to true becausedistance
is not greater than 20, andspeed
is equal to 7.5. -
blah = bird.compareTo("Sparrow") < 0;
evaluates to false becausebird
is equal to "sparrow" (case-sensitive), which is not lexicographically less than "Sparrow." -
blah = height % 3 == 0 && width / 4 >= 7;
evaluates to true because the remainder ofheight
divided by 3 is 0, and the result ofwidth
divided by 4 is greater than or equal to 7. -
blah = dessert.indexOf('k') == 0;
evaluates to false because the characterk
is not at index 0 of the stringdessert
. -
blah = speed * 2 != distance && !(width < 25);
evaluates to true becausespeed
multiplied by 2 is not equal todistance
, andwidth
is not less than 25. -
blah = height != width;
evaluates to true becauseheight
is not equal towidth
. -
blah = fruit.equals("Mango") || dessert.length() > 5;
evaluates to true becausefruit
is equal to "mango" (case-sensitive), which is equivalent to "Mango" (case-insensitive). -
blah = Math.pow(speed, 2) <= height;
evaluates to false because the square ofspeed
is greater thanheight
. -
blah = Math.min(height, width) > Math.sqrt(distance);
evaluates to true because the minimum value ofheight
andwidth
is greater than the square root ofdistance
.
Conditional Structure Output
- When the input is the following:
-
isVerified = false;
-
duration = 2;
-
animal = "elephant";
- the code will print:
-
H
-
K
-
L
-
-
- When the input is the following:
-
isVerified = true;
-
duration = 6;
-
animal = null;
- The code will print:
-
B
-
D
-
I
-
L
-
-
- When the input is the following:
-
isVerified = false;
-
duration = 3;
-
animal = "";
- The code will print:
-
A
-
D
-
L
-
-
Method Output
- When the input is the following:
-
Device dev = new Device();
-
System.out.print(dev.process(3));
-
dev.process();
- The code will print:
-
59
-
Device: active - basic [low]
-
-
- When the input is the following:
-
Device dev = new Device (64, "premium", false);
-
System.out.print(dev.process(10));
-
dev.process();
- The code will print:
-
171
-
Device: active - premium [low]
-
-
- When the input is the following:
-
Device dev = new Device("proModel");
-
System.out.print(dev.process(5));
-
dev.process();
- The code will print:
-
33
-
Device: active - proModel [low]
-
-
- When the input is the following:
-
Device dev = new Device (9, "simple");
-
System.out.print(dev.process(8));
-
dev.process();
- The code will print:
-
7
-
Device: inactive - Simple [low]
-
-
Boolean Expression Simplification
-
!true || true && !false && !(true || true)
simplifies to-
false || true && true && false
using De Morgan's Law for the last part of the expression -
false || true && true && false
using boolean evaluation -
false || true && false
using order of logical operations -
false || false
using order of logical operations -
false
using boolean evaluation
-
-
!(numPets > 3 || isFunny)
simplifies to:-
!(numPets > 3) && !isFunny
using De Morgan's Law -
numPets <= 3 && !isFunny
using negation of greater than
-
-
!(isCool && gpa != 4.0)
simplifies to:-
!isCool || !(gpa != 4.0)
using De Morgan's Law -
!isCool || gpa == 4.0
using negation of not equals to
-
String Evaluation
-
blah = word.equals(phrase.substring(0,3));
evaluates to false becauseword
is equal to "bang", and the substring ofphrase
from index 0 to 3 is "ban" (not including index 3). -
blah = phrase == text;
evaluates to true becausephrase
andtext
both reference the sameString
object in memory. However, this comparison is checking for reference equality, not value equality. -
blah = word == text;
evaluates to false becauseword
andtext
reference differentString
objects in memory. -
blah = ahh == ugh;
results in an error becauseahh
is not initialized and therefore has no value. -
blah = text != ugh;
evaluates to true becausetext
is a validString
object, andugh
isnull
. -
blah = quote != null;
evaluates to true becausequote
is a validString
object, even if it is equal to the string "null". -
blah = ugh.equals(ahh);
results in an error becauseahh
is not initialized and therefore has no value. -
blah = word.equals(phrase);
evaluates to true becauseword
andphrase
have the same value, even though they reference different objects in memory. -
blah = word.compareTo(quote) < 0;
evaluates to true becausequote
isnull
, and thecompareTo()
method always returns 0 when compared to anull
value. -
blah = word.compareTo(phrase) > 0;
evaluates to false becauseword
andphrase
have the same value, socompareTo()
would return 0, not a positive number. -
blah = ugh.equals(word);
results in an error becauseugh
isnull
and you cannot useequals()
on anull
value. -
blah = word.substring(text.length()/2);
-
blah = word.equals(ugh);
results in false becauseword
is "bang" andugh
isnull
. The code will execute normally becauseword
is notnull
andtext.length()
is 4, sotext.length()/2
is 2.
-
Conditional Structure Output with Assumptions
- When the input is the following:
-
animal = null;
-
duration = 1;
-
isVerified = false;
- the code will print:
-
A
-
D
-
-
- When the input is the following:
-
animal = null;
-
duration = 6;
-
isVerified = false;
- The code will print:
-
C
-
D
-
-
- When the input is the following:
-
animal = null;
-
duration = 5;
-
isVerified = true;
- The code will print:
-
B
-
D
-
-
- When the input is the following:
-
animal = "zebra";
-
duration = 6;
-
isVerified = true;
- The code will print:
-
E
-
L
-
-
- When the input is the following:
-
animal = "cat";
-
duration = 7;
-
isVerified = true;
- The code will print:
-
F
-
G
-
J
-
L
-
-
- When the input is the following:
-
animal = "snake";
-
duration = 6;
-
isVerified = true;
- The code will print:
-
F
-
G
-
K
-
L
-
-
Methods
-
public double computeTaxes(double income) {
- takes as input a
double
value representingincome
which represents the individual's yearly income - returns a
double
value that represents the amount of taxes for the specific income level
- takes as input a
-
public String triangleType(double a, double b, double c) {
- takes as input three
double
values representinga
(length of one side of the triangle),b
(length of one side of the triangle), andc
(length of one side of the triangle) - uses the lengths of the sides to determine the type of triangle and returns a
String
value describing the type.
- takes as input three
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Related Documents
Description
This quiz tests your understanding of variable manipulation and conditional expressions in programming. You'll evaluate different statements based on provided conditions and determine their Boolean outcomes. Prepare to tackle logical operations and string comparisons!