Java Reference
In-Depth Information
P ROJECTS
1.
Define a class of bags that implements the interface BagInterface , as defined in Listing 1-1 in Chapter 1. Use an
instance of the class ArrayList to contain a bag's entries. Then write a program that adequately demonstrates
your new class. Note that you might have to handle exceptions thrown by methods of ArrayList .
2.
Repeat Project 1, but instead define a class of stacks that implements the interface StackInterface , as defined in
Listing 5-1 in Chapter 5.
3.
Repeat Project 1, but instead define a class of queues that implements the interface QueueInterface , as defined in
Listing 10-1 in Chapter 10.
4.
Repeat Project 1, but instead define a class of deques that implements the interface DequeInterface , as defined in
Listing 10-4 in Chapter 10.
5.
Repeat Project 1, but instead define a class of sets that implements the interface SetInterface . Recall from
Project 1 in Chapter 1 that a set is a bag whose entries are distinct. Define SetInterface by extending
BagInterface , as defined in Listing 1-1 in Chapter 1.
6.
Santa Claus allegedly keeps lists of those who are naughty and those who are nice. On the naughty list are the names of
those who will get coal in their stockings. On the nice list are those who will receive gifts. Each object in this list contains a
name (an instance of Name , as defined in Appendix B) and a list of that person's gifts (an instance of an ADT list).
Design an ADT for the objects in the nice list. Specify each ADT operation by stating its purpose, by describing
its parameters, and by writing preconditions, postconditions, and a pseudocode version of its header. Then write a
Java interface for the ADT that includes javadoc -style comments.
7.
A recipe contains a title, a list of ingredients, and a list of directions. An entry in the list of ingredients contains an
amount, a unit, and a description. For example, an object that represents 2 cups of flour could be an entry in this
list. An entry in the list of directions is a string.
Design an ADT that represents any entry in a list of ingredients, assuming that you have the class MixedNumber ,
which was described in the online Project 3 of Appendix D. Then design another ADT to represent any recipe. Specify
each ADT operation by stating its purpose, by describing its parameters, and by writing preconditions, postconditions,
and a pseudocode version of its header. Then write a Java interface for the ADT that includes javadoc -style comments.
8.
Define and test a class that implements the interface for the ADT recipe that the previous project describes. Use an
instance of ArrayList for each list that you need. Using a text editor, create a text file of recipes for your demon-
stration program to read.
9.
Repeat Project 7 of Chapter 4, but use an instance of ArrayList instead of a bag.
10.
As early as the tenth century, mathematicians studied the following triangular pattern of integers, now known as
Pascal's Triangle :
1
11
121
1331
14641
...
Despite the early advent of this pattern, it was named after the 17th-century mathematician Blaise Pascal.
Staggering the entries, as we have here, is traditional. Each row begins and ends with 1. Each interior entry is
the sum of the two entries above it. For example, in the last row given here, 4 is the sum of 1 and 3, 6 is the sum of
3 and 3, and 4 is the sum of 3 and 1.
Search WWH ::




Custom Search