CMSC 132Take Home Quiz (20 pts)

advertisement
CMSC 132Take Home Quiz (20 pts)
Due Date: Tuesday Nov 1, 6:00 pm (No late submissions accepted)
The following material will be part of the next in-lab quiz for the course (Wed, Nov 2). There
will be an additional worksheet posted before the quiz, which will cover additional material. This
will be considered a “take home quiz” and you should treat the quiz as an open homework as
described in:
http://www.cs.umd.edu/class/fall2005/cmsc132/openClosedPolicy.shtml
Use the submit server to upload your jar file with the implementation of the methods. Make sure
your jar file is correctRemember to create a project with src and bin directories, and to place the
file MyList.java in a package named “exercises”, which is part of the src directory. Upload the
project to the entry in the submit server labeled “TakeHomeOne”. You have release testing for
this exercise so make sure your results are correct. This take home quiz is worth 20 pts.
Recommendation
Try to write the implementation of the following methods on paper first, trying to make sure your
solution is correct. Then proceed to type the implementation in Eclipse. This will better prepare
you for the in-lab quiz and exams.
Problem I
Provide a recursive implementation for each of the following methods, using the class
“MyList” presented in class. You can not use any iteration statements (e.g., for, while, do
while). You can define an auxiliary method if you understand it is needed. You cannot
use the “size” method during the implementation of the other methods.
1. A method called “size” that computes the length of the list.
2. A method named “even” that returns a String with only the even numbers of the
list (0 is considered even). There will be one space in between each value.
3. A method named “same” that recursively compares two MyList objects and
returns true if the lists are equivalent and false otherwise. Two lists are equivalent
if they have the same corresponding integer values, in the same order. Two
empty lists are considered the “same”.
4. A method named “remove” that removes a specified integer element from the list.
5. A method named “oddValues” that creates a new MyList object with only the odd
values present in a list.
Download