Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Suppose we have a Rectangle class that includes length and width attributes o

ID: 3566200 • Letter: 1

Question

1. Suppose we have a Rectangle class that includes length and width attributes of type int, both set by the constructor. Create a compareTo method for this class so that rectangle objects are ordered based on their a) Perimeter, and b) Area.

2. Give examples from the "real world" of unsorted lists, sorted lists, indexed lists, lists that permit duplicate elements, and lists that do not permit duplicate elements.

3. Someone suggests that, instead of shifting list elements to the left when an object is removed, the array location holding that object should just be set to null. Discuss the ramifications of such an approach for each of our three list types.

4. Can the linear search algorithm be encoded using recursion? If not, why not? If so, outline an approach and discuss its advantages and disadvantages. Share your thoughts with others in the class.

Explanation / Answer

Answer1)

public int compareTo(Object x)

{

Rectangele a=(Rectangle)x;

return((this.length*this.width)-(r.length*r.width));

Rectangele a=(Rectangle)x;

return(2*(this.length*this.width)-2*(r.length*r.width));}