/**
 * This exercise requires the student to manipulate strings using nested if statements.
 *
 * @param text A string to be manipulated.
 * @return The manipulated string.
 */
fun stringManipulation(text: String): String {

    // Check if the length of the string is even
    val result: String = if (text.length % 2 == 0) {
        // Check if the string starts with 'A'
        if (text.startsWith('A')) {
            // Check if the string ends with 'E'
            if (text.endsWith('E')) {
                // Return the string with all lowercase letters
                text.toLowerCase()
            } else {
                // Return the string with all uppercase letters
                text.toUpperCase()
            }
        } else {
            // Return the string with alternating cases (e.g., aBcDeF)
            text.mapIndexed { index, char ->
                if (index % 2 != 0) char.toUpperCase() else char.toLowerCase()
            }.joinToString("")
        }
    } else {
        // Return the string reversed
        text.reversed()
    }

    return result
}
/**
 * This exercise requires the student to manipulate strings using nested if statements.
 *
 * @param text A string to be manipulated.
 * @return The manipulated string.
 */
fun stringManipulation(text: String): String {
/**
 * This exercise requires the student to manipulate strings using nested if statements.
 *
 * @param text A string to be manipulated.
 * @return The manipulated string.
 */
fun stringManipulation(text: String): String {

    // Check if the length of the string is even
    val result: String = if (text.length % 2 == 0) {
        // Check if the string starts with 'A'
        if (text.startsWith('A')) {
            // Check if the string ends with 'E'
            if (text.endsWith('E')) {
                // Return the string with all lowercase letters
                text.toLowerCase()
            } else {
                // Return the string with all uppercase letters
                text.toUpperCase()
            }
        } else {
            // Return the string with alternating cases (e.g., aBcDeF)
            text.mapIndexed { index, char ->
                if (index % 2 != 0) char.toUpperCase() else char.toLowerCase()
            }.joinToString("")
        }
    } else {
        // Return the string reversed
        text.reversed()
    }

    return result
}