Bulletproof web design - Chapter 8 Object-Based Programming 391 1 // Fig.
Chapter 8 Object-Based Programming 391 1 // Fig. 8.4: Time1.java 2 // Time1 class definition in a package 3 package com.deitel.jhtp4.ch08; 4 5 // Java core packages 6 import java.text.DecimalFormat; 7 8 public class Time1 extends Object { 9 private int hour; // 0 - 23 10 private int minute; // 0 - 59 11 private int second; // 0 - 59 12 13 // Time1 constructor initializes each instance variable 14 // to zero. Ensures that each Time1 object starts in a 15 // consistent state. 16 public Time1() 17 { 18 setTime( 0, 0, 0 ); 19 } 20 21 // Set a new time value using universal time. Perform 22 // validity checks on the data. Set invalid values to zero. 23 public void setTime( int h, int m, int s ) 24 { 25 hour = ( ( h >= 0 && h < 24 ) ? h : 0 ); 26 minute = ( ( m >= 0 && m < 60 ) ? m : 0 ); 27 second = ( ( s >= 0 && s < 60 ) ? s : 0 ); 28 } 29 30 // convert to String in universal-time format 31 public String toUniversalString() 32 { 33 DecimalFormat twoDigits = new DecimalFormat( "00" ); 34 35 return twoDigits.format( hour ) + ":" + 36 twoDigits.format( minute ) + ":" + 37 twoDigits.format( second ); 38 } 39 40 // convert to String in standard-time format 41 public String toString() 42 { 43 DecimalFormat twoDigits = new DecimalFormat( "00" ); 44 45 return ( (hour == 12 || hour == 0) ? 12 : hour % 12 ) + 46 ":" + twoDigits.format( minute ) + 47 ":" + twoDigits.format( second ) + 48 ( hour < 12 ? " AM" : " PM" ); 49 } 50 51 } // end class Time1 Fig. 8.4 Placing Class Time1in a package for reuse. Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/3/01
Note: If you are looking for cheap and reliable webhost to host and run your web application check Vision coldfusion web hosting services