Java Reference
In-Depth Information
3.
A ring is a collection of items that has a reference to a current item. An operation —let's call it advance —moves
the reference to the next item in the collection. When the reference reaches the last item, the next advance opera-
tion will move the reference back to the first item. A ring also has operations to get the current item, add an item,
and remove an item. The details of where an item is added and which one is removed are up to you.
Design an ADT to represent a ring of objects. Specify each operation by stating its purpose, by describing its
parameters, and by writing a pseudocode version of its header. Then write a Java interface for a ring's methods.
Include javadoc -style comments in your code.
4.
A shoe of playing cards contains some number of standard decks of cards. Cards in the shoe can be shuffled
together and dealt one at a time. The number of cards in the shoe can also be calculated.
After a hand is complete, you should be able to return all cards to the shoe and shuffle them. Some card
games require that the discard pile be returned to the shoe when the shoe becomes empty. Then the cards in the
shoe can be shuffled. In this case, not all cards are in the shoe; some are held by the players.
Design an ADT for a shoe, assuming that you have the class PlayingCard , which was described in Project 6
of the online projects for Appendix C. You do not need an ADT deck, since a deck is a shoe whose number of
decks is 1.
Specify each ADT operation by stating its purpose, by describing its parameters, and by writing a pseudocode ver-
sion of its header. Then write a Java interface for a shoe's methods. Include javadoc -style comments in your code.
5.
A bid for installing an air conditioner consists of the name of the company, a description of the unit, the perfor-
mance of the unit, the cost of the unit, and the cost of installation.
Design an ADT that represents any bid. Then design another ADT to represent a collection of bids. The sec-
ond ADT should include methods to search for bids based on price and performance. Also note that a single com-
pany could make multiple bids, each with a different unit.
Specify each ADT operation by stating its purpose, by describing its parameters, and by writing a pseudocode
version of its header. Then write a Java interface for a bid's methods. Include javadoc -style comments in your code.
6.
A matrix is a rectangular array of numerical values. You can add or multiply two matrices to form a third matrix.
You can multiply a matrix by a scalar, and you can transpose a matrix. Design an ADT that represents a matrix
that has these operations.
Specify each ADT operation by stating its purpose, by describing its parameters, and by writing a pseudocode
version of its header. Then write a Java interface for the methods of a matrix. Include javadoc -style comments in
your code.
A NSWERS TO S ELF -T EST Q UESTIONS
// aBag is empty
do
1.
ddo
do
{
entry = next string read from user
aBag.add(entry)
} while
while (!aBag.isFull())
// aBag is full
while
2.
No. The two methods have identical signatures. Recall that a method's return type is not a part of its signature.
These methods have the same name and parameter list.
3.
Yes. The two methods have different signatures. They are overloaded methods.
 
Search WWH ::




Custom Search