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