Web hosting provider - Chapter 8 Object-Based Programming 307 18 // validate
Chapter 8 Object-Based Programming 307 18 // validate month 19 if ( theMonth > 0 && theMonth <= 12 ) 20 month = theMonth; 21 22 else 23 { 24 month = 1; 25 Console.WriteLine( 26 "Month {0} invalid. Set to month 1.", theMonth ); 27 } 28 29 year = theYear; // could validate year 30 day = CheckDay( theDay ); // validate day 31 32 } // end Date constructor 33 34 // utility method confirms proper day value 35 // based on month and year 36 private int CheckDay( int testDay ) 37 { 38 int[] daysPerMonth = 39 { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; 40 41 // check if day in range for month 42 if ( testDay > 0 && testDay <= daysPerMonth[ month ] ) 43 return testDay; 44 45 // check for leap year 46 if ( month == 2 && testDay == 29 && 47 ( year % 400 == 0 || 48 ( year % 4 == 0 && year % 100 !=0 ) ) ) 49 return testDay; 50 51 Console.WriteLine( 52 "Day {0} invalid. Set to day 1.", testDay ); 53 54 return 1; // leave object in consistent state 55 } 56 57 // return date string as month/day/year 58 public string ToDateString() 59 { 60 return month + "/" + day + "/" + year; 61 } 62 63 } // end class Date Fig. 8.8 Fig. 8.8Fig. 8.FiFi8g. 8.8g. 8.8Dateclass encapsulates day, month and year information. (Part 2 of 2.) Class Employee (Fig. 8.9) encapsulates information relating to an employee s birthday and hire date (lines 10 13) using instance variables firstName, lastName, birthDateand hireDate. Members birthDateand hireDateare references to Date objects, each of which contains instance variables month, day and year. In this example, class Employeeis composed of two references of type stringand two refer
From our experience, we can recommend PHP Web Hosting services, if you need affordable webhost to host and run your web application.