home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / OOP_Course / Labs / Fruit / Solution / fruitMain.m < prev    next >
Encoding:
Text File  |  1995-06-12  |  2.5 KB  |  80 lines

  1. //  LAB SOLUTION:  Fruit, Apple, and Banana classes
  2.  
  3. // Main program for testing the Fruit, Apple, and Banana classes
  4.  
  5. #import "Fruit.h"
  6. #import "Apple.h"
  7. #import "Banana.h"
  8.  
  9. main ( argc, argv )
  10. int argc;
  11. char *argv[];
  12. {
  13.     id aFruit, anApple, aBanana;
  14.  
  15.     printf ("\nCreate a Fruit instance...\n");
  16.         aFruit = [[Fruit alloc] init];    //allocate and initialize
  17.         printf("aFruit, address %lx\n\t The diameter is %d and color is %s.\n",
  18.             aFruit,                //address of aFruit
  19.             [aFruit diameter],        //diameter of aFruit
  20.             [aFruit color]);        //color of aFruit
  21.  
  22.     printf ("Grow the Fruit...\n");
  23.         [aFruit grow];
  24.         printf("aFruit, address %lx\n\t The diameter is %d and color is %s.\n",
  25.             aFruit,                //address of aFruit
  26.             [aFruit diameter],
  27.             [aFruit color]);
  28.         
  29.     printf ("Create an Apple instance...\n");
  30.         anApple = [[Apple alloc] init];
  31.         printf("anApple, address %lx\n\t The diameter is %d, color is %s, and flavor is %s.\n",
  32.             anApple,              // address of anApple
  33.             [anApple diameter],
  34.             [anApple color],
  35.             [anApple flavor]);
  36.  
  37.     printf ("Change the apple's color, flavor, and diameter...\n");
  38.         [[[anApple setColor: "bright red"] setFlavor: "Macintosh"] setDiameter: 7] ;
  39.         printf("anApple, address %lx\n\t The diameter is %d, color is %s, and flavor is %s.\n",
  40.             anApple,              // address of anApple
  41.             [anApple diameter],
  42.             [anApple color],
  43.             [anApple flavor]);
  44.  
  45.     printf ("Grow the apple...\n");
  46.         [anApple grow];
  47.         printf("anApple, address %lx\n\t The diameter is %d, color is %s, and flavor is %s.\n",
  48.             anApple,              // address of anApple
  49.             [anApple diameter],
  50.             [anApple color],
  51.             [anApple flavor]);
  52.  
  53. /* Additions to Create, Change, and Grow a Banana. */
  54.  
  55.     printf ("Create a Banana instance...\n");
  56.         aBanana = [[Banana alloc] init];
  57.         printf("aBanana, address %lx\n\t The diameter is %d, length is %d, and color is %s.\n",
  58.             aBanana,                // address of aBanana
  59.             [aBanana diameter], 
  60.             [aBanana length],
  61.             [aBanana color]);
  62.  
  63.     printf ("Change the banana's diameter, length, and color...\n");
  64.         [[[aBanana setColor: "green"]  setLength: 6] setDiameter: 3] ;
  65.         printf("aBanana, address %lx\n\t The diameter is %d, length is %d, and color is %s.\n",
  66.             aBanana,                // address of aBanana
  67.             [aBanana diameter], 
  68.             [aBanana length],
  69.             [aBanana color]);
  70.     
  71.     printf ("Grow the banana...\n");
  72.         [aBanana grow];
  73.         printf("aBanana, address %lx\n\t The diameter is %d, length is %d, and color is %s.\n",
  74.             aBanana,                // address of aBanana
  75.             [aBanana diameter], 
  76.             [aBanana length],
  77.             [aBanana color]);
  78.  
  79. } // end of program
  80.