Skip to main content

Practice Code Structure

Section 1.6 Identification

Activity 1.6.1.

    These code blocks are 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 determineEventEligibility(int personAge, int yearsInGroup) {
        if (personAge > 60) {
            if (yearsInGroup >= 5) {
                return "Qualified";
            } else {
                return "Not qualified";
            }
        }
        return "Not qualified";
    }
    
  • This code can be improved!
  • 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";
    }
    
  • This code can be improved!
  • 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.