Advertisement
Aminpro

Time class

Dec 29th, 2013
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.51 KB | None | 0 0
  1.  
  2. public class Tuna {
  3.     private int hour;
  4.     private int minute;
  5.     private int second;
  6.    
  7.     public void setTime(int h, int m, int s){
  8.         hour = ((h>=0 && h<24) ? h : 0);
  9.         minute = ((m>=0 && m<60) ? m : 0);
  10.         second = ((s>=0 && s<60) ? s : 0);
  11.     }
  12.     public String toMilitary(){
  13.         return String.format("%02d:%02d:%02d", hour, minute, second);
  14.        
  15.     }
  16.    
  17.     public String toString(){
  18.         return String.format("%d:%02d:%02d %s", (((hour == 0 || hour == 12 ) ? 12:hour%12)), minute, second, (hour <12 ? "am": "pm"));
  19.        
  20.     }
  21.  
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement