Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Author: Austin Kurtz
- * Date: 2015-08-20
- * Description: (10.1) This program that creates an object where time can be displayed.
- */
- public class Time
- {
- //instance members (data fields)
- private int hour; //amount of hours
- private int minute; //amount of minutes
- private int second; //amount of seconds
- /*This method gets the converts (whatever) to an amount of time.
- */
- public Time()
- {
- convert2Time(System.currentTimeMillis());
- }//End time
- public Time(int t)
- {
- convert2Time(t);
- }//end time
- /*This method sets the amount of seconds, hours, and minutes.
- */
- public Time(int h, int m, int s)
- {
- setHour(h);
- setMinute(m);
- setSecond(s);
- }//End Time
- /*This method gets the amount of hours.
- */
- public int getHour()
- {
- return hour;
- }//End getHour
- /*This method gets the amount of minutes.
- */
- public int getMinute()
- {
- return minute;
- }//End getMinute
- /*This method gets the amount of seconds.
- */
- public int getSecond()
- {
- return second;
- }//End getSecond
- /*This method sets time in hours.
- */
- public void setHour(int h)
- {
- this.hour = h;
- }//End setHour
- /*This method sets time in minutes.
- */
- public void setMinute(int m)
- {
- this.minute = m;
- }//End setMinute
- /*This method sets time in seconds.
- */
- public void setSecond(int s)
- {
- this.second = s;
- }//End setSecond
- /*This method converts a long into hours, minutes, and seconds.
- */
- public void setTime(long elapsedTime)
- {
- convert2Time(System.currentTimeMillis());
- }//End setTime
- /* This method uses Gregorian Calendar to display time correctly.
- */
- public void convert2Time(long t)
- {
- java.util.GregorianCalendar gcal = new java.util.GregorianCalendar();
- gcal.setTimeInMillis(t);
- setHour(gcal.get(java.util.Calendar.HOUR));
- setMinute(gcal.get(java.util.Calendar.MINUTE));
- setSecond(gcal.get(java.util.Calendar.SECOND));
- }//End convert2Time
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement