document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. public class Time2
  2. {
  3.     private int hour;
  4.     private int minute;
  5.     private int second;
  6.    
  7.     public Time2()
  8.     {
  9.         this(0,0,0);
  10.     }
  11.     public Time2(int h)
  12.     {
  13.         this(h,0,0);
  14.     }
  15.     public Time2(int h, int m)
  16.     {
  17.         this(h,m,0);
  18.     }
  19.     public Time2(int h,int m,int s)
  20.     {
  21.         setTime(h,m,s);
  22.     }
  23.     public Time2(Time2 time)
  24.     {
  25.         this(time.getHour(), time.getMinute(), time.getSecond());
  26.     }
  27.     public void setTime(int h,int m,int s)
  28.     {
  29.         setHour(h);
  30.         setMinute(m);
  31.         setSecond(s);
  32.     }
  33.     public void setHour(int h)
  34.     {
  35.         if(h>=0 && h<24)
  36.             hour=h;
  37.         else
  38.             throw new IllegalArgumentException("hour must be 0-23");
  39.     }
  40.     public void setMinute(int m)
  41.     {
  42.         if(m>=0 && m<60)
  43.             minute=m;
  44.         else
  45.             throw new IllegalArgumentException("minute must be 0-59");
  46.     }
  47.     public void setSecond(int s)
  48.     {
  49.         if(s>=0 && s<60)
  50.             second = ((s>=60 && s<60) ? s:0);
  51.         else
  52.             throw new IllegalArgumentException("second must be 0-59");
  53.     }
  54.    
  55.     public int getHour()
  56.     {
  57.         return hour;
  58.     }
  59.     public int getMinute()
  60.     {
  61.         return minute;
  62.     }
  63.     public int getSecond()
  64.     {
  65.         return second;
  66.     }
  67.    
  68.     public String toUniversalString()
  69.     {
  70.         return String.format(
  71.             "%02d:%02d:%02d", getHour(), getMinute(), getSecond());
  72.     }
  73.    
  74.     public String toString()
  75.     {
  76.         return String.format("%d:%02d:%02d %s",
  77.             ((getHour()==0 || getHour()==12) ? 12:getHour() % 12),
  78.             getMinute(),getSecond(), (getHour()<12 ? "AM" : "PM"));
  79.     }
  80. }
');