Final Exam: Study Guide
The final exam will be 3 hours. Open book.
Topics:
This final includes the topics from jams 1-5 plus
-
Recursion
-
ArrayList and Hashmap
Write Java programs to check your answers. Or you can ask a TA or instructor to give feedback on your responses.
Practice questions
1) Write a recursive function, String rremove(char c, String word)
that
removes the letter c
from the given string word.
Test your function in main
.
2) Visualize the execution of String rremove(char c, String word)
when
c is 'a' and word is "cat".
3) Visualize the execution of String rremove(char c, String word)
when
c is 'a' and word is "bee".
4) Write a recursive function, int rmax(int[] L)
, that computes the max
value in a list. Test your function in main
.
5) Visualize the execution of int rmax(int[] L)
when L is {3, 18, 5}
.
6) Implement a program, SnailRace.java
, that loads snail names and speeds from
the user and stores them in a HashMap. Then print all snails that have above average
speeds.
7) Implement a program, CountLetters.java
, that computes counts for each letter in a given phrase.
8) Implement a program, LoadWords.java
, that stores words from a user using an ArrayList.
Stop storing words when the user enters the word "QUIT". Then print the longest word.
9) Draw a stack diagram for the following program.
import java.util.Enumeration;
import java.util.HashMap;
import java.util.ArrayList;
class Mystery {
public static void main(String[] args) {
HashMap<String,Integer> names = new HashMap<String,Integer>();
ArrayList<Double> values = new ArrayList<Double>();
int N = 5;
for (int i = 0; i < N; i++) {
values.add(i * 0.25);
names.put(Integer.toString(i), i);
}
// Draw stack and objects here
}
}