Java Reference
In-Depth Information
΢΢Exercise P15.15. Modify the Invoice class of Chapter 12 so that it
implements the Iterable<LineItem> interface. Then demonstrate
how an Invoice object can be used in a Ȓfor eachȓ loop.
΢΢GExercise P15.16. Write a program to display a linked list graphically.
Draw each element of the list as a box, and indicate the links with line
segments. Draw an iterator as in Figure 3 . Supply buttons to move the
iterator and to add and remove elements.
Additional programming exercises are available in WileyPLUS.
PROGRAMMING PROJECTS
΢΢΢Project 15.1. Implement a class Polynomial that describes a
polynomial such as
x 10
x 7
p( x) = 5
+9 ɨ x ɨ 10
Store a polynomial as a linked list of terms. A term contains the
coefficient and the power of x. For example, you would store p(x) as
(5, 10), (9, 7), ( ɨ 1, 1), (10, 0)
Supply methods to add, multiply, and print polynomials, and to compute
the derivative of a polynomial.
695
696
΢΢΢Project 15.2. Make the list implementation of this chapter as powerful as
the implementation of the Java library. (Do not implement type
parameters, though.)
ȗ Provide bidirectional iteration.
ȗ Make Node a static inner class.
ȗ Implement the standard List and ListIterator interfaces
and provide the missing methods. (Tip: You may find it easier to
extend AbstractList instead of implementing all List
methods from scratch.)
Search WWH ::




Custom Search