Java Reference
In-Depth Information
Each condition has a specific effect on a comic's value:
“Mint” topics are worth three times their base price.
n
“Near mint” topics are worth two times their base price.
n
8
“Very fine” books are worth one and one-half times their base price.
n
“Fine” topics are worth their base price.
n
“Good” topics are worth one-half times their base price.
n
“Poor” topics are worth one-quarter times their base price.
n
To associate text such as “mint” or “very fine” with a numeric value, they are put into a
hash table. The keys to the hash table are the condition descriptions, and the values are
floating-point numbers such as 3.0, 1.5, and 0.25.
Enter the text of Listing 8.3 in your Java editor and save the class as ComicBooks.java .
LISTING 8.3
The Full Text of ComicBooks.java
1: import java.util.*;
2:
3: public class ComicBooks {
4:
5: public ComicBooks() {
6: }
7:
8: public static void main(String[] arguments) {
9: // set up hash table
10: Hashtable quality = new Hashtable();
11: float price1 = 3.00F;
12: quality.put(“mint”, price1);
13: float price2 = 2.00F;
14: quality.put(“near mint”, price2);
15: float price3 = 1.50F;
16: quality.put(“very fine”, price3);
17: float price4 = 1.00F;
18: quality.put(“fine”, price4);
19: float price5 = 0.50F;
20: quality.put(“good”, price5);
21: float price6 = 0.25F;
22: quality.put(“poor”, price6);
23: // set up collection
24: Comic[] comix = new Comic[3];
25: comix[0] = new Comic(“Amazing Spider-Man”, “1A”, “very fine”,
26: 9240.00F);
27: comix[0].setPrice( (Float) quality.get(comix[0].condition) );
28: comix[1] = new Comic(“Incredible Hulk”, “181”, “near mint”,
Search WWH ::




Custom Search