Variable Manipulation Basics
31 Questions
0 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

What message is printed when the value of gradeValue is set to 85?

  • C
  • Not Passing
  • A
  • B (correct)
  • In the computeTaxes() method, how much tax is applied to an income of $60,000?

  • $9,000 (correct)
  • $5,000
  • $6,000
  • $4,500
  • What is the output of triangleType() if the sides are 3.0, 4.0, and 5.0?

  • Scalene
  • Equilateral
  • Right-angled (correct)
  • Isosceles
  • Which condition would cause the computeTaxes() method to apply a 20% tax rate?

    <p>An income between $75,000 and $149,999</p> Signup and view all the answers

    What would the output be for the gradeValue of 65 in the conditional structure?

    <p>Not Passing</p> Signup and view all the answers

    What is the value of blah when evaluated with the expression blah = !(distance > 20) || speed == 7.5?

    <p>True</p> Signup and view all the answers

    What would the console output be when running the following code? isVerified = true; duration = 6; animal = null;

    <p>B, D, I, L</p> Signup and view all the answers

    Evaluate the result of blah for blah = bird.compareTo("Sparrow") < 0.

    <p>False</p> Signup and view all the answers

    What will blah be when evaluated with blah = height % 3 == 0 && width / 4 >= 7?

    <p>True</p> Signup and view all the answers

    Determine the output of blah for blah = Math.pow(speed, 2) <= height.

    <p>False</p> Signup and view all the answers

    What does the expression blah = Math.min(height, width) > Math.sqrt(distance) evaluate to?

    <p>True</p> Signup and view all the answers

    If isVerified = false; duration = 3; animal = ""; what will be the console output?

    <p>A, D, L</p> Signup and view all the answers

    What will blah evaluate to for blah = height != width?

    <p>True</p> Signup and view all the answers

    Which type of triangle is formed when all three sides are equal?

    <p>Equilateral Triangle</p> Signup and view all the answers

    What does the triangleType method return when two sides are equal and the third is different?

    <p>Isosceles Triangle</p> Signup and view all the answers

    In the context of triangle classification, when should you classify a triangle as a Right Triangle?

    <p>When the Pythagorean Theorem holds true.</p> Signup and view all the answers

    What is the result of !(numPets > 3 || isFunny) using De Morgan's Laws?

    <p>numPets &lt;= 3 &amp;&amp; !isFunny</p> Signup and view all the answers

    Which statement is true about the comparison of phrase and text in the code?

    <p>phrase == text returns True.</p> Signup and view all the answers

    What will be the outcome of blah = ugh.equals(ahh) in the given code?

    <p>Error, ahh not initialized</p> Signup and view all the answers

    What will blah be set to when evaluated: blah = word.compareTo(quote) < 0?

    <p>True</p> Signup and view all the answers

    Which statement is correct regarding the evaluation of blah = word.equals(ugh)?

    <p>Error, can't do equals on a null String.</p> Signup and view all the answers

    What is printed when the value of 'animal' is null and duration is less than 4?

    <p>D</p> Signup and view all the answers

    Under what condition would 'E' be printed?

    <p>If 'animal' length is greater than 0 and last letter is 'z' or higher</p> Signup and view all the answers

    What will happen if duration is 3 and 'isVerified' is true?

    <p>Prints 'J' only</p> Signup and view all the answers

    What output occurs when 'isVerified' is true and animal is non-empty with last letter 'a'?

    <p>F, G, L</p> Signup and view all the answers

    What is printed when duration is 7 and 'animal' is 'octopus'?

    <p>H, L</p> Signup and view all the answers

    If 'animal' is an empty string and duration is exactly 5, what gets printed?

    <p>B, D</p> Signup and view all the answers

    What is the condition needed to print 'C' when 'animal' is null?

    <p>When duration is 4 or longer and 'isVerified' is true</p> Signup and view all the answers

    What prints when duration is a negative number with 'animal' being non-empty?

    <p>H.</p> Signup and view all the answers

    Which statement best describes the output when 'isVerified' is false and duration is 6?

    <p>Prints 'A', 'D'</p> Signup and view all the answers

    What happens when 'animal' is 'zebra' and duration is 4?

    <p>Prints 'E', 'L'</p> Signup and view all the answers

    Study Notes

    Variable Manipulation

    • blah = height + width == 43; evaluates to true because the sum of height and width is equal to 43.
    • blah = !(distance > 20) || speed == 7.5; evaluates to true because distance is not greater than 20, and speed is equal to 7.5.
    • blah = bird.compareTo("Sparrow") < 0; evaluates to false because bird 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 of height divided by 3 is 0, and the result of width divided by 4 is greater than or equal to 7.
    • blah = dessert.indexOf('k') == 0; evaluates to false because the character k is not at index 0 of the string dessert.
    • blah = speed * 2 != distance && !(width < 25); evaluates to true because speed multiplied by 2 is not equal to distance, and width is not less than 25.
    • blah = height != width; evaluates to true because height is not equal to width.
    • blah = fruit.equals("Mango") || dessert.length() > 5; evaluates to true because fruit 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 of speed is greater than height.
    • blah = Math.min(height, width) > Math.sqrt(distance); evaluates to true because the minimum value of height and width is greater than the square root of distance.

    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 because word is equal to "bang", and the substring of phrase from index 0 to 3 is "ban" (not including index 3).
    • blah = phrase == text; evaluates to true because phrase and text both reference the same String object in memory. However, this comparison is checking for reference equality, not value equality.
    • blah = word == text; evaluates to false because word and text reference different String objects in memory.
    • blah = ahh == ugh; results in an error because ahh is not initialized and therefore has no value.
    • blah = text != ugh; evaluates to true because text is a valid String object, and ugh is null.
    • blah = quote != null; evaluates to true because quote is a valid String object, even if it is equal to the string "null".
    • blah = ugh.equals(ahh); results in an error because ahh is not initialized and therefore has no value.
    • blah = word.equals(phrase); evaluates to true because word and phrase have the same value, even though they reference different objects in memory.
    • blah = word.compareTo(quote) < 0; evaluates to true because quote is null, and the compareTo() method always returns 0 when compared to a null value.
    • blah = word.compareTo(phrase) > 0; evaluates to false because word and phrase have the same value, so compareTo() would return 0, not a positive number.
    • blah = ugh.equals(word); results in an error because ugh is null and you cannot use equals() on a null value.
    • blah = word.substring(text.length()/2);
      • blah = word.equals(ugh); results in false because word is "bang" and ugh is null. The code will execute normally because word is not null and text.length() is 4, so text.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 representing income which represents the individual's yearly income
      • returns a double value that represents the amount of taxes for the specific income level
    • public String triangleType(double a, double b, double c) {
      • takes as input three double values representing a (length of one side of the triangle), b (length of one side of the triangle), and c (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.

    Studying That Suits You

    Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

    Quiz Team

    Related Documents

    Unit 3 Test Review Complete PDF

    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!

    More Like This

    Python Conditional Expressions Quiz
    8 questions
    AAA SPACES Flashcards
    10 questions
    Espressioni Condizionali in Python
    34 questions
    Use Quizgecko on...
    Browser
    Browser