Easy.java

Resource The Java Documentation will come in handy. To find the String and ArrayList classes, just use the search box in the upper right-hand corner of the page.

Shell CodeDownload the shell file Exercises.java on the left. The comments in the file tell you what to do.

The file is shown here if you'd like to copy and paste it.

Scoring Each method correctly coded is worth 5 points.

public class Exercises
{
    public static void main(String[] args)
    {
        System.out.println(between("catamaran", 'a').equals("tamar"));
        System.out.println(between("catamaran", 'c').equals(""));
        System.out.println(between("catamaran", 'q').equals(""));
        System.out.println(laxEquals("    boot", "boot"));
        System.out.println(laxEquals("boot    ", "boot"));
        System.out.println(laxEquals("     boot    ", "boot"));
        System.out.println(laxEquals(" \t\n    boot \n\t   ", "boot"));
        System.out.println(getExtension("wd2.tex").equals("tex"));
        System.out.println(getExtension("hello.py").equals("py"));
        System.out.println(getExtension("Hello.java").equals("java"));
        System.out.println(getExtension("tossMeNow").equals(""));
        System.out.println(getExtension(".").equals(""));
        System.out.println(isUpperCaseOnly("EAT NOW 123"));
        System.out.println(!isUpperCaseOnly("eat NOW 123"));
        System.out.println(isUpperCaseOnly(""));
    }
    /*
     * This returns an empty string if q is not present in
     * s or if it only appears once.  Otherwise, it returns the
     * substring between the first and last instances of q in s.
     */
    public static String between(String s, char q)
    {
        return "";
    }
    /*
     * This returns true if the only difference between s1 and s2
     * is leading or trailing whitespace.  
     */
    public static boolean laxEquals(String s1, String s2)
    {
        return false;
    }
    /*
     * this returns an empty string if the fileName is empty
     * or has no extension. Otherwise, it returns the extension
     * without the dot.
     */
    public static String getExtension(String fileName)
    {
        return "";
    }
    /*
     * this returns true if the String contains only uppercase
     * or non-alpha characters.
     */
    public static boolean isUpperCaseOnly(String s)
    {
        return false;
    }
}

If you got it all right, the program prints nothing but true.