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

  1. /*Objective_C Implementation of the Apple Class: Apple.m*/
  2.  
  3. #import "Apple.h"
  4.  
  5. @implementation Apple : Fruit
  6.  
  7. /* Initialize a new apple object. */
  8. -init
  9. {
  10.     [super init];    // Do Fruit's init.  Now my own:
  11.     [self setFlavor:"Delicious" diameter:3 color:"red"]; // initialize
  12.     return self;     // return the new instance
  13. }
  14.  
  15. /* Set the flavor instance variable. */
  16. -setFlavor:(char*)aFlavor
  17. {
  18.     flavor=aFlavor;
  19.     return self;
  20. }
  21.  
  22. /* Return the value of the flavor instance variable. */
  23. -(char*)flavor
  24. {
  25.     return flavor;
  26. }
  27.  
  28. /*  Set all the instance variables in the Apple objects. */
  29. -setFlavor:(char*)aFlavor diameter: (int) aSize color:(char*)aColor
  30. {
  31.     [self setFlavor:aFlavor];            //set flavor
  32.     [self setDiameter:aSize];        //set diameter
  33.     [self setColor:aColor];            //set color
  34.     return self;
  35. }
  36.  
  37. /* Tell an apple to increase its diameter. */
  38. -grow
  39. {
  40.     [self setDiameter:([self diameter] + 2)];    //grow by 2
  41.     return self;
  42. }
  43.  
  44. @end
  45.