Question: Write a Java program in a source file called StringTools.java. In this program, you will write a number of Java methods that allow you to
Write a Java program in a source file called StringTools.java. In this program, you will write a number of Java methods that allow you to control and test Java String objects. You may not use any Java StringBuffer or StringBuilder methods. You may use the Java String methods equals, compareTo, charAt, length, and indexOf. The methods include: a method called isDigit that takes a Java String type as its only parameter and returns a boolean value. The return is true if the String object contains only digit characters and false otherwise. Such a method is often called a predicate and in Java, the convention is to begin such predicates with the word "is" in lower case followed by a capitalized word or words describing the test. That is, the method name is in "camel case" as is the name isDigit. a method called alphanumeric that takes a Java String type as its only parameter and returns a boolean value. The return is true if the String object contains only digit and letter characters (upper or lower case) and false otherwise. a method called reverse that takes a Java String type as its only parameter and returns a Java String type. The returned String is a new Java String that is the reverse of the parameter string. That is, given the String object "apple", reverse should return "elppa". a method called changeStr that takes a Java String type as its first parameters followed by a variable number of Java char parameters There must be an even number of char parameters; if not return null. The char parameters are considered as pairs. The method returns a new Java String object with all occurrences of the character first char of each pair replaced by the character second. char of the each pair Consider the following parameters "apple", 'p', 'd', 'a', 'z', 'e', 'a', 'b', 'a', 'd', 'e'. The char parameters are considered as the pairs 'p' and 'd'; 'a' and 'z'; 'e' and 'a'; 'b' and 'a'; and 'd' and 'e' for processing the changes. changeStr returns "zddla". Note that the pair 'b' and 'a' is not used as there are no 'b' characters in the String object "apple". Note that the last pair 'd' and 'e' does not change the early substitution of 'd' for 'p' and the method applies the changes to the original String object only. Your methods should be static. Include the main method that tests your methods.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
