homework10_001

homework10_001 - 15-121 FALL 2009 [CORTINA]HOMEWORK 10 -...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 15-121 FALL 2009 [CORTINA]HOMEWORK 10 - due Tuesday, December 1 by 11:59PMELECTRONIC HANDIN WILL BE AVAILABLE MONDAY, NOV 23 PROBLEMS (10 pts)1. (2 pts) A Dateis represented as a string in the format MM/DD/YYYY: public class Date implements Comparable {String dateString;public int compareTo(Date other) {return this.dateString.compareTo(other.dateString);}// Other methods not shown}a. How are Dateobjects naturally ordered using the compareTomethod? Give an example. b. Show how to define a DateComparatorthat has a comparemethod that orders two Date objects chronologically. That is, the method returns a negative integer if the first date is earlier than the second date, a positive integer if the first date is later than the second date, and 0 if the two dates are the same. c. Let d1and d2represent two Dateobjects that are already initialized. In Java, show how to print out the earlier of the two dates. (If the dates are the same, print out either one.) d. Let dateListbe a LinkedListof Date. Assume this list is initialized with a collection of dates. Using Java, show how to sort this list of dates. (HINT: You can do this in one line.) 2. (2 pts) Let showMapbe a map from television shows to television networks. Let networkMapbe a map from television networks to sets of television shows. You may assume that a television show is shown on only one television network. a. Using Java, show how to output all of the television shows on the ABC television network using showMap. Do not create any additional data structures. b. Using Java, show how to output all of the television shows on the FOX television network using networkMap. Do not create any additional data structures. 3. (2 pts) Write a method that accepts an ArrayList and returns the number of unique elements in the list in O(n) expected time where n is the size of the list. HINT: Use one of the set or map data structures provided in the Java API....
View Full Document

Page1 / 4

homework10_001 - 15-121 FALL 2009 [CORTINA]HOMEWORK 10 -...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online