Percentage.java

00001 package edu.stanford.hci.r3.units;
00002 
00015 public class Percentage extends Units {
00016 
00021         public static final Units ONE = new Percentage(100, new Inches(8.5));
00022 
00026         private Units actualValue;
00027 
00031         private Units maximumValue;
00032 
00040         public Percentage(double percentage, Units maxValue) {
00041                 super(percentage);
00042                 setMaximumValue(maxValue);
00043                 actualValue = maxValue.getUnitsObjectOfSameTypeWithValue(maxValue.getValue() * percentage
00044                                 / 100.0);
00045         }
00046 
00050         public Units getActualValue() {
00051                 return actualValue;
00052         }
00053 
00057         public Units getMaximumValue() {
00058                 return maximumValue;
00059         }
00060 
00064         @Override
00065         protected double getNumberOfUnitsInOneInch() {
00066                 return actualValue.getNumberOfUnitsInOneInch() * 100.0 / maximumValue.getValue();
00067         }
00068 
00072         private void setMaximumValue(Units maxVal) {
00073                 maximumValue = maxVal;
00074         }
00075 
00079         public String toString() {
00080                 return getValue() + " Percent of " + maximumValue + " (" + actualValue + ")";
00081         }
00082 }

Generated on Sat Apr 14 18:21:37 2007 for R3 Paper Toolkit by  doxygen 1.4.7