CSE 131 Module 9: TBD

Extensions

Extension 1: More ListItem Methods: the List Goes On (4 points):

Authors
In the file ListItem.java, write static methods that satisfy the following specifications. Remember that static methods are called directly on the ListItem class itself, rather than on ListItem objects.

Create JUnit tests to test each method thoroughly. Recall that to call static methods of the ListItem class from your JUnit test methods, you can specify the class name each time, as in ListItem.evenElements(ls). Alternatively, you can save characters and just write evenElements(ls) if you import the static methods from the ListItem class by adding the line
import static lab8.ListItem.*;
near the top of your file, after the package declaration.

As you work through these exercises, be sure to use recursion or iteration as indicated. Where not indicated, you may choose either approach. Each method will take references to list items as parameters. Unless otherwise specified, you should handle the case of a null parameter value.

  1. A recursive static procedure pairwiseSum
    PARAMETERS:   two ListItem references, ls1 an ls2
    RETURN VALUE: a ListItem at the front of a new list containing the pairwise
                  sum of the elements in ls1 and ls2
                     for example, given lists ( 3 2 6 ) and ( 1 4 2), 
                     the return value would be the list ( 4 6 8 )
    
    You may assume that the given lists are the same length.

  2. An iterative static procedure smallElements
    PARAMETERS:   a ListItem reference, ls
                  an integer n
    RETURN VALUE: a new list identical to the given list, except
                  that it contains no occurrences of numbers greater than n.
                  for example, given input list ( 3 2 6 3 4 ) and 3,
                     the return value would be the list ( 3 2 3 )
    

  3. An iterative static procedure scale
    PARAMETERS:   a ListItem reference, ls
                  an integer n
    RETURN VALUE: none (void)
                  the procedure mutates the list by multiplying
                  each number in the list by the given number n.
                     for example, given input lists ( 3 2 6 3 4) and
                     the number 3,
                     the modified list would be ( 9 6 18 9 12 ).
    
  4. A static procedure insertAfter
    PARAMETERS:   a ListItem reference, ls
                  two integers i and j (not equal)
    RETURN VALUE: none (void)
                  the procedure mutates the list by inserting the
                  given number i after each occurrence of j.
                     for example, given input lists ( 3 2 6 3 4) and
                     the number 5 and 3,
                     the modified list would be ( 3 5 2 6 3 5 4 ).
    
    Be sure to do this by creating new list items only for the inserted numbers. Modifying the next references in the existing ListItem objects to insert the new items in the right places. Don't create a whole new list structure.

When you done with this extension, you must be cleared by the TA to receive credit.

This demo box is for extension 9.1
Last name WUSTL Key Propagate?
(NOT your numeric ID) Do not propagate
lower case only
e.g. Smith j.smith
1    

Acknowledgements and assertion of integrity

You must select one of the options below
The work submitted here was performed in accordance with this course's policy on collaboration.
On your honor, you have neither given nor received any unauthorized aid on this assignment.

However, the following TAs, students, or professors were supportive in completing this assignment.
Their help was also in accordance with course policies.

Thanks to (leave blank if appropriate):

In spite of seeking help as allowable by this course's policy on collaboration, you were unable to complete this assignment. No credit will be received for this assignment.

You would like to be contacted by an instructor to facilitate staying on track in this course.

Comments about this:

You have NOT abided by this course's policy on collaboration. No credit will be received for this assignment, but by checking this box, no academic integrity violation will be filed for this assignment.

You would like to be contacted by an intructor to faciliate staying on track in this course.

Comments about this:


TA: Password:

End of extension 1


Extension 2: Reversing Lists (3 points):

Authors

In the ListItem class, write methods with the following specifications, and write thorough JUnit tests to check that they work correctly.

When you done with this extension, you must be cleared by the TA to receive credit.

This demo box is for extension 9.2
Last name WUSTL Key Propagate?
(NOT your numeric ID) Do not propagate
lower case only
e.g. Smith j.smith
1    

Acknowledgements and assertion of integrity

You must select one of the options below
The work submitted here was performed in accordance with this course's policy on collaboration.
On your honor, you have neither given nor received any unauthorized aid on this assignment.

However, the following TAs, students, or professors were supportive in completing this assignment.
Their help was also in accordance with course policies.

Thanks to (leave blank if appropriate):

In spite of seeking help as allowable by this course's policy on collaboration, you were unable to complete this assignment. No credit will be received for this assignment.

You would like to be contacted by an instructor to facilitate staying on track in this course.

Comments about this:

You have NOT abided by this course's policy on collaboration. No credit will be received for this assignment, but by checking this box, no academic integrity violation will be filed for this assignment.

You would like to be contacted by an intructor to faciliate staying on track in this course.

Comments about this:


TA: Password:

End of extension 2