JML

org.jmlspecs.samples.prelimdesign
Class USMoney

java.lang.Object
  extended byorg.jmlspecs.samples.prelimdesign.MoneyAC
      extended byorg.jmlspecs.samples.prelimdesign.MoneyComparableAC
          extended byorg.jmlspecs.samples.prelimdesign.USMoney
All Implemented Interfaces:
Cloneable, JMLType, Money, MoneyComparable, MoneyOps, Serializable

public class USMoney
extends MoneyComparableAC
implements MoneyOps


Class Specifications

Specifications inherited from class MoneyAC
protected constraint_redundantly this.numCents == \old(this.numCents);
protected represents pennies <- this.numCents;

Specifications inherited from class Object
represents objectState <- org.jmlspecs.lang.JMLDataGroup.IT;
public represents _getClass <- \typeof(this);

Specifications inherited from interface Money
instance public constraint this.pennies == \old(this.pennies);

Model Field Summary
 
Model fields inherited from class java.lang.Object
_getClass, objectState, theString
 
Model fields inherited from interface org.jmlspecs.samples.prelimdesign.Money
pennies
 
Ghost Field Summary
 
Ghost fields inherited from class java.lang.Object
objectTimesFinalized, owner
 
Field Summary
 
Fields inherited from class org.jmlspecs.samples.prelimdesign.MoneyAC
numCents
 
Constructor Summary
USMoney(double amt)
           
USMoney(long cs)
           
 
Model Method Summary
 
Model methods inherited from class java.lang.Object
hashValue
 
Model methods inherited from interface org.jmlspecs.samples.prelimdesign.MoneyOps
can_add, can_scaleBy, inRange
 
Method Summary
 MoneyOps minus(Money m2)
           
 MoneyOps plus(Money m2)
           
 MoneyOps scaleBy(double factor)
           
 String toString()
           
 
Methods inherited from class org.jmlspecs.samples.prelimdesign.MoneyComparableAC
greaterThan, greaterThanOrEqualTo, lessThan, lessThanOrEqualTo, totalCents
 
Methods inherited from class org.jmlspecs.samples.prelimdesign.MoneyAC
cents, clone, dollars, equals, hashCode
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.jmlspecs.samples.prelimdesign.MoneyComparable
greaterThan, greaterThanOrEqualTo, lessThan, lessThanOrEqualTo
 
Methods inherited from interface org.jmlspecs.samples.prelimdesign.Money
cents, clone, dollars, equals
 
Methods inherited from interface org.jmlspecs.models.JMLType
hashCode
 

Constructor Detail

USMoney

public USMoney(long cs)
Specifications: (class)pure
public normal_behavior
assignable pennies;
ensures this.pennies == cs;
    implies_that
protected normal_behavior
assignable pennies, numCents;
ensures this.numCents == cs;

USMoney

public USMoney(double amt)
Specifications: (class)pure
public normal_behavior
assignable pennies;
ensures this.pennies == (long)(100.0*amt);
Method Detail

plus

public MoneyOps plus(Money m2)
Specified by:
plus in interface MoneyOps
Specifications: (class)pure
Specifications inherited from overridden method plus(Money m2) in interface MoneyOps:
       (class)pure
public normal_behavior
old boolean can_add = this.can_add(m2);
requires m2 != null&&can_add;
assignable \nothing;
ensures \result != null&&\result .pennies == this.pennies+m2.pennies;
    for_example
public normal_example
requires this.pennies == 300&&m2.pennies == 400;
assignable \nothing;
ensures \result != null&&\result .pennies == 700;

minus

public MoneyOps minus(Money m2)
Specified by:
minus in interface MoneyOps
Specifications: (class)pure
Specifications inherited from overridden method minus(Money m2) in interface MoneyOps:
       (class)pure
public normal_behavior
old boolean inRange = this.inRange(this.pennies-m2.pennies);
requires m2 != null&&inRange;
assignable \nothing;
ensures \result != null&&\result .pennies == this.pennies-m2.pennies;
    for_example
public normal_example
requires this.pennies == 400&&m2.pennies == 300;
assignable \nothing;
ensures \result != null&&\result .pennies == 100;

scaleBy

public MoneyOps scaleBy(double factor)
Specified by:
scaleBy in interface MoneyOps
Specifications: (class)pure
Specifications inherited from overridden method scaleBy(double factor) in interface MoneyOps:
       (class)pure
public normal_behavior
requires this.can_scaleBy(factor);
assignable \nothing;
ensures \result != null&&\result .pennies == (long)(factor*this.pennies);
    for_example
public normal_example
requires this.pennies == 400&&factor == 1.01;
assignable \nothing;
ensures \result != null&&\result .pennies == 404;

toString

public String toString()
Overrides:
toString in class Object
Specifications: (class)pure
Specifications inherited from overridden method in class Object:
       non_null
public normal_behavior
assignable objectState;
ensures \result != null&&\result .equals(this.theString);
ensures (* \result is a string representation of this object *);
     also
public code normal_behavior
assignable \nothing;
ensures \result != null&&(* \result is the instance's class name, followed by an @, followed by the instance's hashcode in hex *);
     also
public code model_program { ... }
    implies_that
assignable objectState;
ensures \result != null;

JML

JML is Copyright (C) 1998-2002 by Iowa State University and is distributed under the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This release depends on code from the MultiJava project and is based in part on the Kopi project Copyright (C) 1990-99 DMS Decision Management Systems Ges.m.b.H.