Java Reference
In-Depth Information
20.12
( Clone PriorityQueue ) Define MyPriorityQueue class that extends
PriorityQueue to implement the Cloneable interface and implement the
clone() method to clone a priority queue.
**20.13
( Game: the 24-point card game ) The 24-point game is to pick any 4 cards
from 52 cards, as shown in Figure 20.19. Note that the Jokers are excluded.
Each card represents a number. An Ace, King, Queen, and Jack represent 1 ,
13 , 12 , and 11 , respectively. You can click the Shuffle button to get four new
cards. Enter an expression that uses the four numbers from the four selected
cards. Each number must be used once and only once. You can use the opera-
tors (addition, subtraction, multiplication, and division) and parentheses in the
expression. The expression must evaluate to 24 . After entering the expression,
click the Verify button to check whether the numbers in the expression are cur-
rently selected and whether the result of the expression is correct. Display the
verification in a label before the Shuffle button. Assume that images are stored
in files named 1.png , 2.png , . . . , 52.png , in the order of spades, hearts, dia-
monds, and clubs. So, the first 13 images are for spades 1, 2, 3, . . . , and 13.
F IGURE 20.19
The user enters an expression consisting of the numbers in the cards and clicks the Verify button to
check the answer.
**20.14
( Postfix notation ) Postfix notation is a way of writing expressions without
using parentheses. For example, the expression (1 + 2) * 3 would be
written as 1 2 + 3 * . A postfix expression is evaluated using a stack. Scan a
postfix expression from left to right. A variable or constant is pushed into the
stack. When an operator is encountered, apply the operator with the top two
operands in the stack and replace the two operands with the result. The follow-
ing diagram shows how to evaluate 1 2 + 3 * .
2
3
9
1
1
3
3
12+3*
12+3*
12+3*
12+3*
12+3*
scanned
scanned
scanned
scanned
scanned
 
 
Search WWH ::




Custom Search