document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. public class Time1 extends Time1Test
  2. {
  3. private int hour;
  4. private int minute;
  5. private int second;
  6.  
  7. public void setTime( int h, int m, int s ){
  8. if ( (h >= 0 && h < 24 ) && ( m >= 0 && m < 60 ) && (s>=0 && s<60)){
  9. hour = h;
  10. minute = m;
  11. second = s;
  12. }
  13. else throw new IllegalArgumentException( "hour, minute and/or second was out of range" );
  14. }
  15. public String toUniversalString()
  16. {
  17. return String.format( "%02d:%02d:%02d", hour,minute,second);
  18. }
  19. public String toString()
  20. {
  21. return String.format( "%d:%02d:%02d %s",((hour==0 || hour==12) ? 12 : hour % 12),minute,second,(hour<12 ? "AM" : "PM"));
  22. }
  23. }
  24.  
  25. TIME1TEST
  26.  
  27. public class Time1Test
  28. {
  29. // instance variables - replace the example below with your own
  30.  
  31.  
  32. /**
  33. * Constructor for objects of class timetime
  34. */
  35. public static void main( String[] args)
  36. {
  37. // initialise instance variables
  38. Time1 time = new Time1();
  39.  
  40. System.out.print( "The initial universal time is: ");
  41. System.out.println( time.toUniversalString() );
  42. System.out.print( "The initial standard time is: ");
  43. System.out.println( time.toString() );
  44. System.out.println();
  45.  
  46. time.setTime( 13, 27, 6);
  47. System.out.print( "Universal time after setTime is:");
  48. System.out.println( time.toUniversalString() );
  49. System.out.print( "Standard time after setTime is:");
  50. System.out.println( time.toString() );
  51. System.out.println();
  52.  
  53. try{
  54. time.setTime( 99, 99, 99);
  55. }
  56. catch (IllegalArgumentException e){
  57. System.out.printf( "Exception: %s\\n\\n", e.getMessage() );
  58. }
  59.  
  60. System.out.println("After attempting invalid settings:");
  61. System.out.print( "Universal time:");
  62. System.out.println( time.toUniversalString() );
  63. System.out.print( "Standard time:");
  64. System.out.println( time.toString() );
  65. }
');