Advertisement
thenewboston

Java Programming Tutorial - 36 - Time Class

Aug 22nd, 2014
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.63 KB | None | 0 0
  1. public class apples {
  2.    public static void main(String[] args) {
  3.       tuna tunaObject = new tuna();
  4.       System.out.println(tunaObject.toMilitary());
  5.       tunaObject.setTime(13, 27, 6);
  6.       System.out.println(tunaObject.toMilitary());
  7.    }
  8.  
  9. }
  10.  
  11. public class tuna {
  12.    private int hour;
  13.    private int minute;
  14.    private int second;
  15.    
  16.    public void setTime(int h, int m, int s){
  17.       hour = ((h>=0 && h<24) ? h : 0);
  18.       minute = ((m>=0 && m<60) ? m : 0);
  19.       hour = ((s>=0 && s<60) ? s : 0);
  20.    }
  21.    
  22.    public  String toMilitary(){
  23.       return String.format("%02d:%02d:%02d", hour, minute, second);
  24.    }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement