Practice Questions: Week 10


Lists

1. Write a program that creates a List and populates it using arguments from the command line. Your program should then output the elements of the List one element per line. Sample output (assuming integer command line arguments):

java Week10_1.java 7 6 3 4 5
List has 5 elements:
7
6
3
4
5

2. Extend your solution to Question 1 so that the List is output in sorted order (from smallest to largest).

3. Extend your solution to Question 1 so that the List is output in sorted order (from largest to smallest).

4. Modify the dictionary program Dictionary.java so that it uses binary search instead of contains. The dictionary file is here.

5. Modify your solution to Question 1 so that it solves Exercise 10.14 in the textbook (finds the median of a list of numbers).

6. Modify your solution to Question 1 so that it solves Exercise 10.16 in the textbook (finds the mode of a list of numbers).

Sets

7. Write a program that creates a Set and populates it using arguments from the command line. Every time a command line argument is repeated your program should output a message indicating that the value was repeated. Your program should then output the elements of the Set one element per line. Sample output (assuming integer command line arguments):

java Week10_7.java 7 6 3 4 6 7 5 3
6 was repeated
7 was repeated
3 was repeated
Set has 5 elements:
3
4
5
6
7

8. Modify your solution to Question 7 so that the values are output in reverse order (from largest to smallest).

9. Write a program that computes the union of two Sets. Hint: read the Java Tutorial on the Set interface

10. Write a program that computes the intersection of two Sets. Hint: read the Java Tutorial on the Set interface