Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1.  
  2. /**
  3.  * Write a description of class Time1 here.
  4.  *
  5.  * @author (your name)
  6.  * @version (a version number or a date)
  7.  */
  8. public class Time1
  9. {
  10.     private int hour;
  11.     private int minute;
  12.     private int second;
  13.    
  14.     public void setTime( int h, int m, int s)
  15.     {
  16.         if ((h>=0 && h<24) && (m>=0 && m<60) && (s>=0 && s<60))
  17.         {
  18.             hour=h;
  19.             minute=m;
  20.             second=s;
  21.         }
  22.         else
  23.             throw new IllegalArgumentException("Data diluar batas");
  24.     }
  25.    
  26.     public String toUniversalString()
  27.     {
  28.         return String.format("%02d:%02d:%02d", hour, minute, second);
  29.     }
  30.    
  31.     public String toString()
  32.     {
  33.         return String.format("%d:%02d:%02d %s", ((hour == 0 || hour == 12) ? 12 : hour % 12), minute, second, (hour<12 ? "AM" : "PM"));
  34.  
  35.     }
  36. }