Assignment #7

Instructions

  1. Write a Java application that executes the following 5 recursive methods, each of which returns a value (do NOT use System.out.print() inside the method definitions), and prints that value in the main() method, where x is a positive integer on the commandline (1st argument), and s is a String on the commandline (2nd argument).
    1. Method 1: Return and print in main() x number of s (ssss...), in other words print the String s, x times.
    2. Method 2: Return and print in main() the first character in s, x number of times (ssss...), where "s" is the first letter in String "s".
    3. Method 3: Return and print in main() each letter in s two times (s0s0s1s1s2s2s3s3...) where s0 is the first letter, s1 is the second letter, s2 is the third letter, etc.
    4. Method 4: Return and print in main() each letter in s three times backwards (sn-1sn-1sn-1sn-2sn-2sn-2sn-3sn-3sn-3sn-4sn-4sn-4...) where sn-1 is the last letter, sn-2 is the second to last letter, sn-3 is the third to last letter, etc.
    5. Method 5: Return and print in main() a String which counts down by 1 for x, and deletes one letter for each recursion for s, until x becomes 1, or until s has only 1 letter (x s, x-1 s1 letter deleted, x-2 s2 letters deleted, x-3 s3 letters deleted...)
  2. Use the commandline arguments to enter one positive integer (a number) as 1st argument, and a String (a word) as the 2nd argument.
    1. see this webpage for instructions on commandline arguments.
    2. You need to convert the 1st commandline argument to an integer:
      Integer number = Integer.parseInt(args[0]);
    3. Note that "number" is the same as "x" in the above explanation.
    4. You need to store the 2nd commandline argument in a String variable:
      String word = args[1];
    5. Note that "word" is the same as "s" in the above explanation.
    6. You may find it useful to use more than one parameter for some of your methods.
  3. At the beginning of the main method, check to make sure that the user entered the correct input.
    1. If exactly one (1) positive integer argument is not entered on the commandline, then display an error message and end the program.
    2. You also need to have a try-catch statement just in case a non-integer is inputted as a commandline argument.
  4. Make sure your code follows the ICs 211 Java Coding standard, in particular the Java documentation (Javadoc) comments that go above each method.
  5. Write your original comments every 3-5 lines of code.
    1. WARNING: Do NOT copy my code or my comments. Use my code as a guide to write your own code.

Output

  1. Example output for commandline arguments 5 natto
    nattonattonattonattonatto
    nnnnn
    nnaattttoo
    ooottttttaaannn
    5 natto, 4 atto, 3 tto, 2 to, 1 o,
        
  2. Example output for commandline argument 10 ten
    tentententententententententen
    tttttttttt
    tteenn
    nnneeettt
    10 ten, 9 en, 8 n, 
        
  3. Example output for commandline argument 10 abracadabra
    abracadabraabracadabraabracadabraabracadabraabracadabraabracadabraabracadabraabracadabraabracadabraabracadabra
    aaaaaaaaaa
    aabbrraaccaaddaabbrraa
    aaarrrbbbaaadddaaacccaaarrrbbbaaa
    10 abracadabra, 9 bracadabra, 8 racadabra, 7 acadabra, 6 cadabra, 5 adabra, 4 dabra, 3 abra, 2 bra, 1 ra, 
        

Click to validate the HTML code

Click to validate the Css code