KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > collections > ship > tuple > Weight


1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2002,2006 Oracle. All rights reserved.
5  *
6  * $Id: Weight.java,v 1.9 2006/10/30 21:14:03 bostic Exp $
7  */

8
9 package collections.ship.tuple;
10
11 import java.io.Serializable JavaDoc;
12
13 /**
14  * Weight represents a weight amount and unit of measure.
15  *
16  * <p> In this sample, Weight is embedded in part data values which are stored
17  * as Java serialized objects; therefore Weight must be Serializable. </p>
18  *
19  * @author Mark Hayes
20  */

21 public class Weight implements Serializable JavaDoc {
22
23     public final static String JavaDoc GRAMS = "grams";
24     public final static String JavaDoc OUNCES = "ounces";
25
26     private double amount;
27     private String JavaDoc units;
28
29     public Weight(double amount, String JavaDoc units) {
30
31         this.amount = amount;
32         this.units = units;
33     }
34
35     public final double getAmount() {
36
37         return amount;
38     }
39
40     public final String JavaDoc getUnits() {
41
42         return units;
43     }
44
45     public String JavaDoc toString() {
46
47         return "[" + amount + ' ' + units + ']';
48     }
49 }
50
Popular Tags