FREQUENTLY ASKED QUESTIONS

Most recent FAQ on top.

Typically students have a lot of questions on assignment. Some common guidelines for homeworks/exams, and clarifications on homeworks will be posted on this page. Please try and get answers to doubts on homeworks from this page. If you don't seek the answer you are looking for contact the TA incharge.

Read the Submission Rules for information on submitting assignments. It is extremely important to follow these instructions in order to get credit for your assignments.


Comparable type

Where do Comparables come into the picture?
You may not assume that the objects in the lists are of type Integer. They can be Strings, Characters, Floats, or anything that implements the Comparable interface. Note the comments before the description of question 1: "You may assume that the lists in all questions have objects that implement the Comparable interface."

How do I compare Objects holding Comparables?
Say you have:
   Object a = new Integer(3);
   Object b = new Integer(4);
Integer implements Comparable, and so it should have a compareTo() method for comparison. However, the type of a and b is Object, which does not implement the Comparable. You need to cast a and b to Comparable and then use the compareTo() method.
   if (a.compareTo(b) > 0){
   //-->will throw an error because a and b are of type Object
   }

   if ( ((Comparable)a).compareTo((Comparable)b) > 0 ) { // works
   }
   
Note that all the parentheses in the example above are necessary because casting to Comparable has lower precedence than the dot (".") operator. However, the casting needs to be done BEFORE the compareTo() method is called.

Many people seem to be having trouble compiling the code for assignment 0. If you get a "Cannot resolve symbol" error during the compilation of the sources you have a problem with your classpath. Please read the following article that explains what a classpath is and how it will resolve your issue.