ilminottaken

Untitled

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