/*
 * Palindrome String Checker
 * Author: Ahmad Nurfais
 * Created: 02.09.2023
 * Description: OOP Course Assignment
 */
import java.util.Scanner; // Using scanner to write and read user input

public class Palindrome {
    // The function that will check whether a string is a palindrome or not
    public static void doPalindrome(String input) {
        String tupni = ""; // The reverse string variable of the input. Declare it at the beginning just to make that variable can be used and contain the value after the iteration below. That's why its length is set to be zero.

        // The iteration that reverse the input string. It start from the last index of the string until 0 which is the first index of the string.
        for (int j = input.length() - 1; j > 0 - 1 ; j--) {
            tupni = tupni + input.charAt(j); // This syntax is used to avoid the error of converting a string into char, because in this iteration, each character in the string will be read one by one based on their index by using charAt() function.
        }

        // Convert the input and its reverse into upper case using toUpperCase() function. This is to avoid the difference case text type after the reverse iteration above, because the if-else statement below reads data one by one based on their index, and that differences will make the if-else statement reads the same alphabet with different case text type as different character. For example, Nun -> nuN, N != n. This program want to recognize the same alphabet as the same character, although they has different case type text. If we do not want to do it, we can omit this part and change the if condition from inputL.equals(tupniL) to input.equals(tupni).
        String inputL = input.toUpperCase();
        String tupniL = tupni.toUpperCase();

        // The if-else statement that will check whether the input and reverse are the same or not. If the same, print "Yes". If not, print "No".
        if (inputL.equals(tupniL)) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }

    // The function to execute the program
    public static void main(String[] args) {
        Scanner numberOfTestCases = new Scanner(System.in); // Make a new scanner object
        System.out.println("\n\033[1mEnter 'T' (Number of Test Cases) <enter> to Continue:\033[0m\n"); // In this print line function, there are escape sequences: (\n) that will print a new line and (\033[1m ... \033[0m]) that will give the output text the bold effect.
        int T = numberOfTestCases.nextInt(); // Integer T will contain the value of T which is the the number of test cases amount.

        Scanner arrayScanner = new Scanner(System.in);
        System.out.println("\n\033[1mInput (Enter the String) <enter>:\033[0m\n");
        String[] arrayString = new String[T]; // Declare the string array that will contain the input of user. Its length will equal to T, number of test cases.
        for (int i = 0; i < T; i++) {
            arrayString[i] = arrayScanner.nextLine(); // In this iteration, user asked to enter each string input, and those input will be stored in arrayString array. The iteration will end after the user do input 'T' time(s).
        }

        int count = 1; // Make a new integer variable to count a number of case
        System.out.println("\n\033[1mOutput:\033[0m\n");
        // This iteration will read the input data that previously stored in arrayString array, and the doPalindrome function will check whether that data include as palindrome or not. The iteration start from index 0 of array until the string in the array .
        for (int i = 0; i < T; i++) {
            String finalString = arrayString[i]; // Get each string in array based on their index
            System.out.print("\tCase #" + count++ + ": "); // Print "Case #" and the number. In this print function, there is a escape sequence (\t) that will make a tab space of the output print.
            doPalindrome(finalString); // Call the doPalindrome function
        }

        // End the object of scanners
        arrayScanner.close();
        numberOfTestCases.close();
        System.out.println("\n~ Program End.\n");
    }
}
