Skip to main content

Practice Code Structure

Section 1.7 Code Comprehension

Activity 1.7.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 isHighImpact(boolean isPeerReviewed, String journalName, int citationCount) {
        if (isPeerReviewed) {  
            if (isWellKnownJournal(journalName)) { 
                if (citationCount > 50) { 
                    return "High-impact!";
                }
            }
        }
        return "Not high-impact.";
    }
    
    Hint.
    Hint: You can use the following test cases to compare the functionality of the code blocks.
    • isHighImpact(true, "IEEE",20)
    • isHighImpact(true, "ACM", 120)
    • isHighImpact(true, "unknown", 300)
    • isHighImpact(true, "unknown", 20)
    • isHighImpact(false, "ACM", 97)
    • isHighImpact(false, "ACM", 34)
    • isHighImpact(false, "unknown", 543)
    • isHighImpact(false, "unknown", 12)
    Select all that apply.
  • public static String isHighImpact(boolean isPeerReviewed, String journalName, int citationCount) {
        if (!isPeerReviewed) {
            return "Not high-impact.";
        }  
        if (!isWellKnownJournal(journalName)) {
            return "Not high-impact.";
        }
        if (citationCount <= 50) { 
            return "Not high-impact.";               
        }               
        return "High-impact!";
    }
    
  • Correct!
  • public static String isHighImpact(boolean isPeerReviewed, String journalName, int citationCount) {
        if (isPeerReviewed && isWellKnownJournal(journalName) && citationCount > 50) { 
           return "High-impact!";
        }
        return "Not high-impact.";
    }
    
  • Correct!
  • public static String isHighImpact(boolean isPeerReviewed, String journalName, int citationCount) {
        if (!isPeerReviewed || !isWellKnownJournal(journalName) || citationCount <= 50) { 
            return "Not high-impact.";               
        } else {               
            return "High-impact!"; 
        }
    }
    
  • Correct!
You have attempted 1 of 2 activities on this page.