MyRecursion.java
and provides code for testing the those
* methods. Do NOT change anything or add anything to this file
*/
public abstract class Recursion extends Shell
{
public void showHelp() {
super.showHelp();
System.out.println("Recursion 3 commands:");
System.out.println(" repeat String
that is a result of repeating the input
* value n
times. This method can be tested with the
* repeat
command and will be useful in your directory
* listing.
* @param value the string to be repeated
* @param count the number of times to repeat it.
*/
public abstract String repeat (String value, int count);
/** Return a String
that is a result of reversing the input
* value. This method can be tested with the reverse
command
* and will be useful in diamond
code.
* listing.
* @param value the string to be reversed
* @return an input of abc
will return cba
*/
public abstract String reverse (String value);
/** Print the values of list
, one per line. This method may
* be tested using the list
command.
* This method will not be directly used in the directory listing,
* but will serve as a guide as to how to write that code. Helper method(s)
* may make this code easier to write.
*
* @param list the list to be printed
*/
public abstract void list (String[] list);
/** Determine whether a value exists in the list. This will be reused
* in the MyRecursion.intersect
code. This may be tested
* with the intersect
command.
*
* @param list the list of values to search
* @param value the value to search for (may be null)
* @return - true if the value is contained in the list, false otherwise
*/
public abstract boolean contains (String[] list, String value);
/** Print a diamond shape recursively. Using repeat()
and
* reverse()
and taking advantage of the symmetry (horizontai
* and vertical) should make the code much simpler.
* @param size defines the size of the diamond shape.
* For a diamond of size 5 the result is (result has no indentation):
* * ***** ***** * **** **** * *** *** * ** ** * * * * ** ** * *** *** * **** **** * ***** ***** **/ public abstract void diamond (int size); /** Find the elements that are in common in the two lists. This is the * intersection of the two lists. The common values must be returned in the * order they occur in list1. * * @param list1 an array of values * @param list2 a second array of values * @return an ArrayList containing all values that appear in both lists. If * no values are in common, return an empty ArrayList. */ public abstract ArrayList
* csXXX/ * slides/ * 01_introduction.ppt * 02_classes.ppt * code/ * week1/ * example.java * assignments/ * assignment1.pdf * assignment2.pdf * quizzes/ * quiz1.pdf ** Note that each directory is printed followed by a
/
. Had
* a maximum depth of 4 been specified, the result would be:
* * csXXX/ * slides/ * 01_introduction.ppt * 02_classes.ppt * code/ * week1/ * example.java * assignments/ * quizzes/ ** In this case the contents of
assignments
are not listed.
*
* If the root file/directory does not exist, print
* name: No such file or directory
where name
* is the name of the root file.
*
*
To help you, explore the directory structure, use Java's File
*
class. It contains many usefull methods like: isDirectory(),
* exists(), list(), and listFiles()
.
*
You will use multiple helper method(s) to complete the code
* for this method.
*
* @param fileName the name of the file/directory at the root of the tree
* @param indent how many spaces to increase the indent per level.
* @param maxLevels do NOT go beyond this level. Level 0 is the
* top level. Level 1 contains the children of level 0 and so on.
*/
public abstract void directory (String fileName, int indent, int maxLevels) ;
/** Process one command for this assignment.
*/
public void processOneCommand (String cmd, String params)
throws FileNotFoundException, NoSuchElementException
{
Scanner scan = new Scanner(params);
ArrayList