ilham_syamsuddin

Untitled

Sep 19th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. public class Time1
  2. {
  3. private int hour;
  4. private int minute;
  5. private int second;
  6.  
  7. public void setTime(int h, int m, int s)
  8. {
  9. if((h>=0 && h<24) && (m>=0 && m<60) &&(s>=0 && s<60))
  10. {
  11. hour=h;
  12. minute=m;
  13. second=s;
  14. }
  15. else
  16. throw new IllegalArgumentException( "hour, minute, and/or second was out of range");
  17. }
  18. public String toUniversalString()
  19. {
  20. return String.format( "%02d:%02d:%02d",hour,minute,second);
  21. }
  22. public String toString()
  23. {
  24. return String.format( "%d:%02d:%02d %s",
  25. ( ( hour == 0 || hour==12 ) ? 12 : hour % 12),
  26. minute, second, ( hour <12 ? "AM" : "PM") );
  27. }
  28.  
  29. }
Advertisement
Add Comment
Please, Sign In to add comment