home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1995 August / NEBULA.mdf / SourceCode / OOP_Course / Labs / IB_Fruit / Solution / Fruit.m < prev    next >
Encoding:
Text File  |  1993-01-18  |  1.2 KB  |  71 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. /* Action method for setting the color of the fruit. */
  17. -takeColorFrom:sender
  18. {
  19.     [self setColor:[sender stringValue]];
  20.     return self;
  21. }
  22.  
  23. /* Set the color of the fruit. */
  24. -setColor:(const char*)aColor
  25. {
  26.     color = aColor;
  27.     return self;
  28. }
  29.  
  30. /* Return the fruit's color. */
  31. - (const char*)color
  32. {
  33.     return color;
  34. }
  35.  
  36. /* Action method for setting the diameter of the fruit. */
  37. -takeDiameterFrom:sender
  38. {
  39.     [self setDiameter:[sender intValue]];
  40.     return self;
  41. }
  42.  
  43. /* Set the fruit's diameter. */
  44. -setDiameter: (int) aSize
  45. {
  46.     diameter = aSize;
  47.     return self;
  48. }
  49.  
  50. /* Return the fruit's diameter. */
  51. - (int) diameter
  52. {
  53.     return diameter;
  54. }
  55.  
  56. /* Tell the fruit to increase its diameter. */
  57. - grow:sender
  58. {
  59.     [self setDiameter:([self diameter] + 1)];
  60.     return self;
  61. }
  62.  
  63. - displayValues:sender
  64. {
  65.     [colorDisplay setStringValue:color];
  66.     [diameterDisplay setIntValue:diameter];
  67.     return self;
  68. }
  69.  
  70. @end
  71.