Question: Your job is to create a class called Loops in package loops. That class should contain implementations of the following five public, static methods. The
Your job is to create a class called Loops in package loops. That class should contain implementations of the following five public, static methods. The class and each method must have a Javadoc comment that explains what they do. Your comments should describe behavior from the point of view of an external observer. The best way to do this is to write the comments before you write the code.
1. containsToken takes a String s and a String t as parameters, and returns a boolean. It returns true if t occurs as a token within s, and returns false otherwise. (Implementation note: Use a Scanner to break s into tokens, and use a searching loop to look for t.)
2.findLineWithToken takes a Scanner scn and a String t as parameters, and returns a String. It returns a line from scn that contains t as a token (if such a line exists) and returns the empty string (otherwise). (Implementation note: You'll find the containsToken method specified above helpful. This method calls for a searching loop.)
3.isPalindrome takes a String s as a parameter and returns a boolean. It returns true if s reads the same forwards and backwards, and returns false otherwise. You are not allowed to use any method that reverses s. (Implementation note: Use a loop that searches for a character in s that doesn't "match up" with an identical character elsewhere in the string. You'll need to determine the appropriate definition of "match up".)
4. findLongestPalindrome takes a Scanner scn as its parameter and returns a String. It returns the longest token from scn that is a palindrome (if one exists) or the empty string (otherwise). (Implementation note: You'll find the isPalindrome method helpful here. This method calls for an optimization loop.)
5. findMostWhitespace takes a Scanner scn as its parameter and returns an int. It finds the line in scn with the most whitespace characters and returns the number of whitespace characters it contains (if scn contains at least one line) or -1 (otherwise). (Implementation note: This method calls for an optimization loop, and will be be easy if you first implement a method that counts the amount of whitespace in a string. There is a method Character.isWhitespace() that you'll find useful.)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
