Skip to main content

Practice Code Structure

Section 1.5 Code Comprehension

Activity 1.5.1.

    Look at the first code block. Which of the following options have the same functionality as it (i.e., they produce the same output for the same inputs)? You can check the Hint for some input examples.
    public static String determineEventEligibility(int personAge, int yearsInGroup) {
        if (personAge > 60) {
            if (yearsInGroup >= 5) {
                return "Qualified";
            } else {
                return "Not qualified";
            }
        }
        return "Not qualified";
    }
    
    Hint.
    Hint: You can use the following test cases to compare the functionality of the code blocks.
    • determineEventEligibility(62, 5)
    • determineEventEligibility(62, 3)
    • determineEventEligibility(60, 5)
    • determineEventEligibility(58, 2)
    Select all that apply.
  • public static String determineEventEligibility(int personAge, int yearsInGroup) {
        if (personAge > 60 && yearsInGroup >= 5) {
            return "Qualified";
        } 
        return "Not qualified";
    }
    
  • Correct!
  • public static String determineEventEligibility(int personAge, int yearsInGroup) {
        if (personAge > 60) {
            if (yearsInGroup >= 5) {
                return "Qualified";
            }
        } 
        return "Not qualified";
    }
    
  • Correct!
  • public static String determineEventEligibility(int personAge, int yearsInGroup) {
        if (personAge <= 60 || yearsInGroup < 5) {
            return "Not qualified";
        }
        return "Qualified";
    }
    
  • Correct!
You have attempted 1 of 2 activities on this page.