I am attempting to design and implement a program with a Java class that will ask the user to input a non-null string. First, I should convertthis string to lower case (for simplicity) and store each character of the string into a char[] (an array of type char) (“helloworld”→|h|e|l|l|o|w|o|r|l|d|). Then print the array in forward and reverse order, unless the input string is a palindrome (the same spelling forward and backward, ex: "noon”). In that case, only print the array once and state that the inputted string is a planindrome. (see sample output). Next, store the string into a different char[], putting only 1 instance of each character into the array (“helloworld”→|h|e|l|o|w|r|d|). Then printthe new array in forward and reverse order (see sample output). Finally, I should sort the new array containing the non-repeated characters in ascending alphabetical order (|h|e|l|o|w|r|d|→|d|e|h|l|o|r|w|). Then print the sorted array in forward and reverse order ( see sampleoutput).
P.S. - I cannot touch the main. PLEASE HELP, 4 days on the same code.
] import java.lang.reflect.Array; import java.util.Arrays; import javax.swing.*; public class Program6 { // Modify the constant below to have your name instead of CIS Faculty public final static String TITLE_BAR = "Program 6 (Me)"; // Write your class methods below // Passed the user input string and an array (size = length of the string) // for storing the chars of that string. Stores each char of the string to // the array. private static void storeAllCharacters(String input, char[] allCharacters) { String strOrig = ""; allCharacters = strOrig.toCharArray(); } private static int storeNoRepeatCharacters(String input, char[] noRepeatCharacters) { int stored = noRepeatCharacters.length; char[] nonDup; nonDup = new char[stored]; for(int i = 0; i <= stored; i++) { if(input.charAt(i) != input.charAt(stored)) { return nonDup[i]; } } return 0; // int index = 1; // for (int i = 1; i < length; ++i) // { // int j; // for (j = 0; j < index; ++j) // { // if (noRepeatCharacters[i] == noRepeatCharacters[j]) // { // break; // } // } // if (j == index) // { // noRepeatCharacters[index] = noRepeatCharacters[i]; // ++index; // } // } // for (; index < length; index++) // { // noRepeatCharacters[index] = 0; // } // return index; } private static boolean isCharacterPresent(char repeat, char[] noRepeat, int index) { for(int i = 0; i <= noRepeat.length; i++) { if(noRepeat[i] == repeat) { return true; } } return false; } private static void sortArray(char[] noRepeatCharacters, int lastIndexStored) { Arrays.sort(noRepeatCharacters); } private static void printArray(char[] allCharacters) { int j = 0; char[] temparray = allCharacters; boolean isPalindrome = false; if (isPalindrome) { System.out.print(temparray); } for (int i = allCharacters.length - 1; i >= 0; i--) { temparray[j++] = allCharacters[i]; } for (int i = 0; i < allCharacters.length; i++) { allCharacters[i] = temparray[i]; } System.out.print(temparray); } private static void printArray(char[] noRepeatCharacters, int lastIndexStored) { for(int i = 0; i <= lastIndexStored; i++) { System.out.print(noRepeatCharacters[i] + " "); } System.out.print("\n"); for(int i = noRepeatCharacters.length -1; i <= 0; i++) { System.out.print(noRepeatCharacters[i]); } // Start from the size of the array (minus 1 to get the highest subscript) // and go down to zero for (int i = noRepeatCharacters.length - 1; i >= 0; i--) { System.out.println(noRepeatCharacters[i]); } } private static boolean isPalindrome(String input) { int lowNum = 0; int highNum = input.length() - 1; while (lowNum < highNum) { if (input.charAt(lowNum) != input.charAt(highNum)) return false; lowNum++; highNum--; } return true; } // Main method provided // Do not modify the main method public static void main(String[] args) { // Local Variables. String input = ""; char[] allCharacters; char[] noRepeatCharacters; int lastIndexStored; do { input = JOptionPane.showInputDialog("Enter a non-empty string"); if (input == null) { JOptionPane.showMessageDialog(null, "User clicked cancel. The Program will exit", TITLE_BAR, JOptionPane.PLAIN_MESSAGE); System.exit(0); } } while (input.length() == 0); // Convert the string to all lower case input = input.toLowerCase(); // Create the arrays using the length of the input string allCharacters = new char[input.length()]; noRepeatCharacters = new char[input.length()]; // Call the method to store the entire input string storeAllCharacters(input, allCharacters); // Call the method to print the entire allCharacters array // Call the method to store the characters without repeating // and assign its return value lastIndexStored = storeNoRepeatCharacters(input, noRepeatCharacters); // Call the method to print the noReapeatCharacters array // up to the lastIndexStored printArray(noRepeatCharacters, lastIndexStored); // Call the method to sort the noReapeatCharacters array // up to the lastIndexStored sortArray(noRepeatCharacters, lastIndexStored); // Call the method to print the sorted noReapeatCharacters array // up to the lastIndexStored printArray(noRepeatCharacters, lastIndexStored); } // end of main } // end of Program6