Review Sheet for Exam 3

This sheet is intended to help you prepare for exam 3. I do not promise you that it is complete. The exam will cover everything we've studied this semester.

1. Re-work the review sheets for the first two exams.

2. Write Java code that creates an array list of Integers. The integers that should go in the list are on the command line. Iterate through the array list and compute the sum of all the values in the list.

We did this one in class.

3. Describe one situation in which an array list would be more efficient than a linked list.

An array list is more efficient if you frequently need to access elements in the middle of the list.

4. Each line in the file definitions.txt contains a word, followed by a hyphen, and then the word's definition. Put all the words in the file in a set. Discuss why you chose the concrete Set class that you used.

Scanner defFile = new Scanner(new File("definitions.txt"));
TreeSet<String> defSet = new TreeSet<String>();
while(defFile.hasNextLine())
{
    String line = defFile.nextLine();
    int pos = line.indexOf(":");
    String word = line.substring(0, pos);
    defSet.add(word);
}

Note: The method in which this code is contained may throw an IOException, so it must be advertised or handled.

I used a TreeSet so the words would appear in alphabetical order if I print the Strings in the set.

5. Take the definitions.txt file in #4, and put the words and definitions in a Map. Print out all the words, and then separately print out all the definitions.

Omit this question.

6. Pick one method in Map.Entry and describe how it works. Give a few lines of code in which you call this method.

Omit this question.

7. What is the default layout for the content pane of a JFrame object? Describe how this layout works.

See the class notes.

8. Write a few lines of code that: create a JFrame with a title, make a panel that contains 2 buttons, and add the buttons to the panel and the panel to the frame. Handle button clicks so that the last clicked button says "on" and the other one says "off". Initially one button should be labeled "on" and the other "off".

Very similar to the online questions and in-class examples.

9. Write a few lines of code in which you are using an anonymous class.

See FirstGUI.java in the example programs.