//StringTests.java import java.lang.*; public class StringTests{ public StringTests(String array1[]){ /**This method breaks the passed array into two separate * items. It then converts the first string to an integer * using parseInt() method and then assigns the * second string to a new array. The last stage passes the * new int and array to the switch statement **/ System.out.println(); System.out.println("String tests program "); System.out.println("By Garth Bruen."); int x = Integer.parseInt(array1[0]); //Changes first index to an integer String words = array1[1]; //puts second index item into a variable String array2[] = new String[1]; //Creates new array array2[0] = words; //put string variable into new array switchStatement(x, array2); //passes new integer and array to switch statment } public void switchStatement(int n, String array2[]){ if(n <= 3){ /**If checks to see if the integer value *is valid for the switch statement **/ int j = 0; while(j < 2){ switch(n) { case 0: System.out.println(n+" "+array2[0]); break; case 1: showLength(array2); break; case 2: caseCheck(array2); break; case 3: reverseString(array2); break; default: System.out.println("You must enter a number and a string"); break; } j = j + 1; } } else System.out.println("You must enter a number between 1 and 3"); } public void reverseString(String array2[]){ /** This method prints the string backwards by using * two if loops and printing from the array **/ System.out.println(); System.out.print("This is your string backwards: "); for(int r = array2.length-1; r >= 0; r--){ for(int rr = array2[r].length()-1; rr>=0; rr--){ System.out.print(array2[r].charAt(rr)); } System.out.println(" "); } System.out.println(); return; } public void showLength(String array2[]){ /**This method checks the length of the string *using length() **/ System.out.println(); System.out.println("The length of your string is "+array2[0].length()); System.out.println(); return;} public void caseCheck(String args1[]){ String newWord; newWord = args1[0]; //asigns the string to a new variable String uCase, lCase; //Creates test variables uCase = newWord; lCase = newWord; uCase = uCase.toUpperCase(); //Changes the cases lCase = lCase.toLowerCase(); //of the test variables /**The next if/else/if/else checks to see if the the string is *upper case or lower case by comparing them to the original string *with euqals() method **/ if(newWord.equals(uCase)){ System.out.println(); System.out.println("Strings are upper case: "+uCase+" "+newWord);} else if(newWord.equals(lCase)){ System.out.println(); System.out.println("Strings are lower case: "+lCase+" "+newWord);} else {System.out.println(); System.out.println("String is multiple case");} } public static void main(String args[]){ StringTests st = new StringTests(args);//passes the command line string to the program } }