Advertisement
Guest User

Softcok Nappys Codes.

a guest
Aug 29th, 2015
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.25 KB | None | 0 0
  1. /* Author: Austin Kurtz
  2.  * Date: 2015-08-20
  3.  * Description: (10.1)  This program that creates an object where time can be displayed.
  4.  */
  5.  
  6. public class Time
  7. {
  8.    //instance members (data fields)
  9.    private int hour;                                    //amount of hours
  10.    private int minute;                                  //amount of minutes
  11.    private int second;                                  //amount of seconds
  12.    
  13.    /*This method gets the converts (whatever) to an amount of time.
  14.    */  
  15.    public Time()
  16.    {
  17.       convert2Time(System.currentTimeMillis());
  18.      
  19.    }//End time
  20.  
  21.    public Time(int t)
  22.    {
  23.        
  24.       convert2Time(t);
  25.        
  26.    }//end time
  27.  
  28.    /*This method sets the amount of seconds, hours, and minutes.
  29.    */  
  30.    public Time(int h, int m, int s)
  31.    {
  32.       setHour(h);
  33.       setMinute(m);
  34.       setSecond(s);
  35.    
  36.    }//End Time
  37.    
  38.    /*This method gets the amount of hours.
  39.    */  
  40.    public int getHour()
  41.    {
  42.       return hour;
  43.      
  44.    }//End getHour
  45.    
  46.    /*This method gets the amount of minutes.
  47.    */  
  48.    public int getMinute()
  49.    {
  50.       return minute;
  51.      
  52.    }//End getMinute
  53.  
  54.    /*This method gets the amount of seconds.
  55.    */  
  56.    public int getSecond()
  57.    {
  58.       return second;
  59.      
  60.    }//End getSecond
  61.    
  62.    /*This method sets time in hours.
  63.    */
  64.    public void setHour(int h)
  65.    {
  66.       this.hour = h;
  67.      
  68.    }//End setHour
  69.    
  70.    /*This method sets time in minutes.
  71.    */
  72.    public void setMinute(int m)
  73.    {
  74.       this.minute = m;
  75.      
  76.    }//End setMinute
  77.    
  78.    /*This method sets time in seconds.
  79.    */
  80.    public void setSecond(int s)
  81.    {
  82.       this.second = s;
  83.      
  84.    }//End setSecond
  85.    
  86.    /*This method converts a long into hours, minutes, and seconds.
  87.    */
  88.     public void setTime(long elapsedTime)
  89.    {
  90.       convert2Time(System.currentTimeMillis());
  91.      
  92.    }//End setTime
  93.    
  94.    /* This method uses Gregorian Calendar to display time correctly.
  95.    */
  96.    public void convert2Time(long t)
  97.    {
  98.       java.util.GregorianCalendar gcal = new java.util.GregorianCalendar();
  99.      
  100.       gcal.setTimeInMillis(t);
  101.      
  102.       setHour(gcal.get(java.util.Calendar.HOUR));
  103.       setMinute(gcal.get(java.util.Calendar.MINUTE));
  104.       setSecond(gcal.get(java.util.Calendar.SECOND));
  105.      
  106.    }//End convert2Time
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement