document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1.     /**
  2.  * Write a description of class Time2 here.
  3.  *
  4.  * @author (Muhammad Bagus Istighfar)
  5.  * @version (14.10.20)
  6.  */
  7. public class Time2
  8. {
  9.     private int hours;
  10.     private int minute;
  11.     private int second;
  12.    
  13.     public Time2()
  14.     {
  15.         this (0,0,0);
  16.     }
  17.    
  18.     public Time2( int h)
  19.     {
  20.        this (h,0,0);
  21.     }
  22.     public Time2(int h,int m)
  23.     {
  24.         this(h,m,0);
  25.     }
  26.     public Time2(int h, int m, int s)
  27.     {
  28.         setTime (h,m,s);
  29.     }
  30.    
  31.     public Time2( Time2 time)
  32.     {
  33.         this (time.getHours(), time.getMinute(),
  34.         time.getSecond());
  35.     }
  36.     public void setTime (int h, int m, int s)
  37.     {
  38.         setJam ( h ) ;
  39.         setMenit( m );
  40.         setDetik( s );
  41.     }
  42.    
  43.     public void setJam (int h)
  44.     {
  45.         if (h>= 0 && h<24)
  46.         {
  47.             hours=h;
  48.         }
  49.         else
  50.         {
  51.             throw new IllegalArgumentException(
  52.             "hour must be 0-23");
  53.         }
  54.     }
  55.       public void setMenit (int m)
  56.     {
  57.         if (m>= 0 && m<60)
  58.         {
  59.             minute=m;
  60.         }
  61.         else
  62.         {
  63.             throw new IllegalArgumentException(
  64.             "minute must be 0-59");
  65.         }
  66.     }
  67.       public void setDetik (int s)
  68.     {
  69.         if (s>= 0 && s<60)
  70.         {
  71.             second=(( s>=0 && s<60) ? s:0);
  72.         }
  73.         else
  74.         {
  75.             throw new IllegalArgumentException(
  76.             "second must be 0-59");
  77.         }
  78.     }
  79.    
  80.     public int getHours()
  81.     {
  82.         return hours;
  83.     }
  84.     public int getMinute()
  85.     {
  86.         return minute;
  87.     }
  88.     public int getSecond()
  89.     {
  90.         return second;
  91.     }
  92.     public String toString()
  93.     {
  94.         return String.format( "%d:%02d:%02d %s",
  95.         ((getHours()==0||getHours()==12)?12:getHours()%12),
  96.         getMinute(), getSecond(), (getHours()<12? "AM" :"PM"
  97.         ));
  98.     }
  99.     public String toUniversalString()
  100.     {
  101.         return String.format("%02d:%02d:%02d",
  102.         getHours(), getMinute(), getSecond());
  103.     }  
  104. }
');