home *** CD-ROM | disk | FTP | other *** search
/ OpenStep (Enterprise) / OpenStepENTCD.toast / OEDEV / DEV.Z / Department.m < prev    next >
Encoding:
Text File  |  1995-11-03  |  2.4 KB  |  124 lines

  1. /* Department.m
  2.  * A simple enterprise object.
  3.  * 
  4.  * You may freely copy, distribute, and reuse the code in this example.
  5.  * NeXT disclaims any warranty of any kind, expressed or  implied, as to its
  6.  * fitness for any particular use.
  7.  *
  8.  * Written by Mai Nguyen, NeXT Developer Support
  9.  */
  10.  
  11. #import "Department.h"
  12. #import "strings.h"
  13.  
  14.  
  15. @implementation Department
  16.  
  17. - init 
  18. {
  19.     [super init];
  20.     // You can add additional intialization here.
  21.     return self;
  22. }
  23.  
  24. - (void)dealloc
  25. {
  26.     [DepartmentName autorelease];
  27.     [FacilityLocation autorelease];
  28.     [toEmployee autorelease];
  29.     [super dealloc];
  30.    
  31. }
  32.  
  33.  
  34. // Accessor methods 
  35.  
  36. - (void) setDepartmentName:(NSString *)newName
  37. {
  38.     [DepartmentName autorelease];
  39.     DepartmentName = [newName retain];
  40.     return;
  41. }
  42.  
  43. - (NSString *)DepartmentName { return DepartmentName; }
  44.  
  45. - (void) setDeptId:(int)newId
  46. {
  47.     DeptId = newId;
  48.     return; 
  49.  
  50. - (int)DeptId { return DeptId; }
  51.  
  52.  
  53. - (void) setLocationId:(int)newLocation
  54. {
  55.     LocationId = newLocation;
  56.     return;     
  57.  
  58. - (int)LocationId { return LocationId; }
  59.  
  60. - (void)setToFacility:value
  61. {
  62.     // A TO-ONE relationship.
  63.     [toFacility autorelease];
  64.     toFacility = [value retain];
  65.     return;
  66. }
  67. - toFacility { return toFacility; }
  68.  
  69. - (void)setFacilityLocation:(NSString *)value
  70. {
  71.     [FacilityLocation autorelease];
  72.     FacilityLocation = [value retain];
  73.     return;
  74. }
  75. - (NSString *)FacilityLocation { return FacilityLocation; }
  76.  
  77. - (void)setToEmployee:(NSArray *)value
  78. {
  79.     // A TO-MANY relationship.
  80.     [toEmployee autorelease];
  81.     toEmployee = [value retain];
  82.     return;
  83. }
  84. - (NSArray *)toEmployee { return toEmployee; }
  85.  
  86. - (void) setAverageSalary:(int)aSalary
  87. {
  88.     averageSalary = aSalary;
  89.     return;
  90. }
  91.  
  92. - (int)averageSalary
  93. {
  94.     int            i;
  95.     unsigned    count = 0;
  96.     id            anEmployee, value;
  97.     int         totalSalaries = 0;
  98.     
  99.     averageSalary = 0; 
  100.     if (toEmployee) {
  101.         count = [toEmployee count];
  102.         totalSalaries = 0;
  103.         for (i = 0; i < count; i++) {
  104.             anEmployee = [toEmployee objectAtIndex:i];
  105.             value = [anEmployee objectForKey:@"Salary"];
  106.                 // skip Salary with Null values
  107.             if  (![value isEqual:[EONull null]])
  108.             totalSalaries += [[anEmployee objectForKey:@"Salary"] intValue];
  109.             } 
  110.     }
  111.     if (count > 0)
  112.          averageSalary = totalSalaries/count;
  113.         
  114.     return averageSalary;
  115. }
  116.  
  117. - (oneway void)printDepartmentReport: sender
  118. {
  119. }
  120.  
  121. @end
  122.