Advertisement
Aminpro

Set and Get method for Time Class

Dec 29th, 2013
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.86 KB | None | 0 0
  1.  
  2. public class Tuna {
  3.     private int hour;
  4.     private int minute;
  5.     private int second;
  6.  
  7.     public Tuna(){
  8.         this(0,0,0);
  9.     }
  10.     public Tuna(int h){
  11.         this(h,0,0);
  12.     }
  13.     public Tuna(int h, int m){
  14.         this(h,m,0);
  15.     }
  16.     public Tuna(int h, int m, int s){
  17.         setTime(h,m,s);
  18.     }
  19.     public void setTime(int h, int m, int s){
  20.         setHour(h);
  21.         setMinute(m);
  22.         setSecond(s);  
  23.     }
  24.     //Check for hours and seconds
  25.     public void setHour(int h){
  26.         hour = ((h>=0 && h <24)? h:0);
  27.     }
  28.     public void setMinute(int m){
  29.         minute = ((m>=0 && m <60)? m:0);
  30.     }
  31.     public void setSecond(int s){
  32.         second = ((s>=0 && s <60)? s:0);
  33.     }
  34.     public int getHour(){
  35.         return hour;
  36.     }
  37.     public int getMinute(){
  38.         return minute;
  39.     }
  40.     public int getSecond(){
  41.         return second;
  42.     }
  43.    
  44.     public String toMilitary(){
  45.         return String.format("%02d:%02d:%02d", getHour(), getMinute(), getSecond());
  46.     }
  47.  
  48.        
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement