308 Object-Based Programming Chapter 8 ences of class (Tomcat web server)

308 Object-Based Programming Chapter 8 ences of class Date. The Employee constructor (lines 16 27) takes eight arguments (first, last, birthMonth, birthDay, birthYear, hireMonth, hireDay and hireYear). Line 24 passes arguments birthMonth, birthDay and birth- Yearto the Dateconstructor to create the birthDateobject. Similarly, line 25 passes arguments hireMonth, hireDayand hireYearto the Dateconstructor to create the hireDateobject. Method ToEmployeeString(lines 30 35) returns a stringcontaining the name of the Employee and the string representations of the Employee s birthDate and hireDate. Class CompositionTest (Fig. 8.10) runs the application with method Main. Lines 13 14 instantiate an Employeeobject and lines 16 17 display the string representation of the Employee to the user. 1 // Fig. 8.9: Employee.cs 2 // Employee class definition encapsulates employee’s first name, 3 // last name, birth date and hire date. 4 5 using System; 6 7 // Employee class definition 8 public class Employee 9 { 10 private string firstName; 11 private string lastName; 12 private Date birthDate; // reference to a Date object 13 private Date hireDate; // reference to a Date object 14 15 // constructor initializes name, birth date and hire date 16 public Employee( string first, string last, 17 int birthMonth, int birthDay, int birthYear, 18 int hireMonth, int hireDay, int hireYear ) 19 { 20 firstName = first; 21 lastName = last; 22 23 // create new Date objects 24 birthDate = new Date( birthMonth, birthDay, birthYear ); 25 hireDate = new Date( hireMonth, hireDay, hireYear ); 26 27 } // end Employee constructor 28 29 // convert Employee to String format 30 public string ToEmployeeString() 31 { 32 return lastName + “, ” + firstName + 33 ” Hired: ” + hireDate.ToDateString() + 34 ” Birthday: ” + birthDate.ToDateString(); 35 } 36 37 } // end class Employee Fig. 8.9 Fig. 8.9Fig. 8.FiFi9g. 8.9g. 8.9Employeeclass encapsulates employee name, birthday and hire date.
Visit our web design programs services for an affordable and reliable webhost to suit all your needs.

Leave a Reply