document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. /**
  2.  * Fig. 8.1 : Deklarasi Time1 class.
  3.  *
  4.  * @author Naufaliando Yudo Kusumo
  5.  * @version 10 Oktober 2020
  6.  */
  7. public class Time1
  8. {
  9.     private int hour; // 0 - 23
  10.     private int minute; // 0 - 59
  11.     private int second; // 0 - 59
  12.  
  13.     public void setTime( int h, int m, int s )
  14.     {
  15.         if ((h >= 0 && h < 24) && (m >= 0 && m < 60) && (s >= 0 && s < 60))
  16.         {
  17.             hour = h;
  18.             minute = m;
  19.             second = s;
  20.         }
  21.         else
  22.             throw new IllegalArgumentException("hour, minute and/or second was out of range");
  23.     }
  24.    
  25.     public String toUniversalString()
  26.     {
  27.         return String.format("%02d:%02d:%02d", hour, minute, second);
  28.     }
  29.    
  30.     public String toString()
  31.     {
  32.         return String.format("%d:%02d:%02d %s",((hour==0 || hour==12) ? 12 : hour%12),minute, second, (hour<12 ? "AM" : "PM"));
  33.     }
  34. }
  35.  
');