402 Object-Based Programming Chapter 8 20 21 // (Web design conference)
402 Object-Based Programming Chapter 8 20 21 // Time3 constructor: hour supplied, minute and second 22 // defaulted to 0 23 public Time3( int h ) 24 { 25 setTime( h, 0, 0 ); 26 } 27 28 // Time3 constructor: hour and minute supplied, second 29 // defaulted to 0 30 public Time3( int h, int m ) 31 { 32 setTime( h, m, 0 ); 33 } 34 35 // Time3 constructor: hour, minute and second supplied 36 public Time3( int h, int m, int s ) 37 { 38 setTime( h, m, s ); 39 } 40 41 // Time3 constructor: another Time3 object supplied 42 public Time3( Time3 time ) 43 { 44 setTime( time.getHour(), time.getMinute(), 45 time.getSecond() ); 46 } 47 48 // Set Methods 49 // Set a new time value using universal time. Perform 50 // validity checks on data. Set invalid values to zero. 51 public void setTime( int h, int m, int s ) 52 { 53 setHour( h ); // set the hour 54 setMinute( m ); // set the minute 55 setSecond( s ); // set the second 56 } 57 58 // validate and set hour 59 public void setHour( int h ) 60 { 61 hour = ( ( h >= 0 && h < 24 ) ? h : 0 ); 62 } 63 64 // validate and set minute 65 public void setMinute( int m ) 66 { 67 minute = ( ( m >= 0 && m < 60 ) ? m : 0 ); 68 } 69 Fig. 8.8 Class Time3with set and get methods (part 2 of 3). Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/3/01