Another constructs a Quantity out of just a String:

 

class Quantity
{
double multiplier;
StringList numerator;
StringList denominator;

 

.... other constructors  for Quantity ....

 

Quantity(String unit) 		// constructor head
  {				// constructor body
  this.multiplier = 1.0;
  this.numerator = Stringlist.cons(unit, Stringlist.nil);
  this.denominator = Stringlist.nil;
  }

 

.... other constructors and methods for Quantity ....
}

 

Notice that outside the class Stringlist we must qualify the value or method by prefixing the classname: Stringlist.cons

Next Slide Previous Slide Contents