01: // Copyright (c) 2002 Cunningham & Cunningham, Inc.
02: // Released under the terms of the GNU General Public License version 2 or later.
03:
04: package fat;
05:
06: public class Money {
07: long cents;
08:
09: public Money(String s) {
10: String stripped = "";
11: for (int i = 0; i < s.length(); i++) {
12: char c = s.charAt(i);
13: if (Character.isDigit(c) || c == '.') {
14: stripped += c;
15: }
16: }
17: cents = (long) (100 * Double.parseDouble(stripped));
18: }
19:
20: public boolean equals(Object value) {
21: return (value instanceof Money)
22: && cents == ((Money) value).cents;
23: }
24:
25: public int hashCode() {
26: return (int) cents;
27: }
28:
29: public String toString() {
30: return cents + " cents";
31: }
32: }
|