1. Write a program that emulates
GlobalCredit
using a Map
Specifically, create a Map
that
maps credit card numbers (as returned by
CreditCard.getNumber
) to
CreditCard
s.
Try adding one or two CreditCard
s
to the map. Try adding one or two RewardCard
s
to the map; does it work?
Finally, print out all of the cards
in the Map
using four different
traversals:
2. Study the type.lib.CharStack
API (there are only two constructors and
three methods). Modify the following program
so that it catches the thrown exception
and outputs the character that was being
added to the stack when the exception occurred:
import type.lib.CharStack; public class W11Q2 { public static void main(String[] args) { CharStack stack = new CharStack(); char c = 'a'; while (true) { stack.add(c); c = (char) (c + 1); } } }
Note: this is a particularly poor use of exception handling; the point is to get some practice writing try-catch blocks. In general, you should never use exceptions for flow control as is done in this problem.
3. eCheck 10D if you have not attempted it already.
4. eCheck 11D if you have not attempted it already.
5. Exam programming test from last Fall.
6. Exam programming test from last Fall.
7. Long Map example from last Fall.