Skip to main content

Practice Code Structure

Section 1.8 Identification

Activity 1.8.1.

    These code blocks are the same as the ones you saw in the previous question, and they all have the same functionality. Among these options which ones are preferable?
  • 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!";
    }
    
  • This code can be improved!
  • 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.";
    }
    
  • This code can be improved!
  • 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.