home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1995 August / NEBULA.mdf / SourceCode / OOP_Course / Labs / Fruit / Fruit.m < prev    next >
Encoding:
Text File  |  1993-01-18  |  791 b   |  50 lines

  1. /* Objective_C Implementation of the Fruit Class: Fruit.m */
  2.  
  3. #import "Fruit.h"
  4.  
  5. @implementation Fruit : Object
  6.  
  7. /* Initialize a new fruit. */
  8. -init
  9. {
  10.     [super init];            // do Object's init.  Now my own:
  11.     [self setDiameter:1];        // init the diameter
  12.     [self setColor:"green"];     // init the color
  13.     return self;            // return the new instance
  14. }
  15.  
  16. /* Set the color of the fruit. */
  17. -setColor:(char*)aColor
  18. {
  19.     color = aColor;
  20.     return self;
  21. }
  22.  
  23. /* Return the fruit's color. */
  24. - (char*)color
  25. {
  26.     return color;
  27. }
  28.  
  29. /* Set the fruit's diameter. */
  30. -setDiameter: (int) aSize
  31. {
  32.     diameter = aSize;
  33.     return self;
  34. }
  35.  
  36. /* Return the fruit's diameter. */
  37. - (int) diameter
  38. {
  39.     return diameter;
  40. }
  41.  
  42. /* Tell the fruit to increase its diameter. */
  43. - grow
  44. {
  45.     [self setDiameter:([self diameter] + 1)];
  46.     return self;
  47. }
  48.  
  49. @end
  50.