home *** CD-ROM | disk | FTP | other *** search
- // LAB DEMO: Fruit and Apple classes
-
- // Main program for testing the Fruit and Apple classes
-
- #import "Fruit.h"
- #import "Apple.h"
-
- main ( argc, argv )
- int argc;
- char *argv[];
- {
- id aFruit, anApple;
-
- printf ("\nCreate a Fruit instance...\n");
- aFruit = [[Fruit alloc] init]; //allocate and initialize
- printf("aFruit, address %lx\n\t The diameter is %d and color is %s.\n",
- aFruit, //address of aFruit
- [aFruit diameter], //diameter of aFruit
- [aFruit color]); //color of aFruit
-
- printf ("Grow the Fruit...\n");
- [aFruit grow];
- printf("aFruit, address %lx\n\t The diameter is %d and color is %s.\n",
- aFruit, //address of aFruit
- [aFruit diameter],
- [aFruit color]);
-
- printf ("Create an Apple instance...\n");
- anApple = [[Apple alloc] init];
- printf("anApple, address %lx\n\t The diameter is %d, color is %s, and flavor is %s.\n",
- anApple, // address of anApple
- [anApple diameter],
- [anApple color],
- [anApple flavor]);
-
- printf ("Change the apple's color, flavor, and diameter...\n");
- [[[anApple setColor:"bright red"] setFlavor:"Macintosh"] setDiameter: 7] ;
- printf("anApple, address %lx\n\t The diameter is %d, color is %s, and flavor is %s.\n",
- anApple, // address of anApple
- [anApple diameter],
- [anApple color],
- [anApple flavor]);
-
- printf ("Grow the apple...\n");
- [anApple grow];
- printf("anApple, address %lx\n\t The diameter is %d, color is %s, and flavor is %s.\n",
- anApple, // address of anApple
- [anApple diameter],
- [anApple color],
- [anApple flavor]);
-
- /* Additions to Create, Change, and Grow a Banana. */
-
- // You are to add code here, similar to above, to do this.
-
-
- } // end of program
-