You are on page 1of 2

/** * Write a description of class Time2 here. * * @author Arnon Van.

* @version (a version number or a date) */ public class Time2 { private long _secFromMid; public Time2 (int h,int m,int s) { this._secFromMid = h*60*60+m*60+s; } public Time2 (Time2 other) { this._secFromMid = other._secFromMid; } public { return } public { return } public { return } int getHour() (int) (_secFromMid/(60*60)); int getMinute() (int) ((_secFromMid%(60*60))/60); int getSecond() (int) ((_secFromMid%(60*60))%60);

public void setHour(int num) { // check if num is between 0 and 23 (including 0,23) long tempTime = _secFromMid; if (getHour()>0) { tempTime = _secFromMid%(60*60); } if ( num>-1 && num<24 ) { tempTime += num*60*60; } _secFromMid = tempTime; } public void setMinute(int num) { long tempTime = _secFromMid; if (getMinute()>0) { tempTime = _secFromMid - getMinute()*60; } if (num>-1 && num<60) { tempTime += num*60;

} _secFromMid = tempTime; } public void setSecond(int num) { long tempTime = _secFromMid; if (getSecond()>0) { tempTime = _secFromMid - getSecond(); } if (num>-1 && num<60) { tempTime += num; } _secFromMid = tempTime; } public String toString () { String h,m,s; h = ""+getHour(); m = ""+getMinute(); s = ""+getSecond(); if (getHour() < 10) h = "0"+getHour(); if (getMinute() < 10) m = "0"+getMinute(); if (getSecond() < 10) s = "0"+getSecond(); return h+":"+m+":"+s; }

//Not Needed // //public long _secFromMid () //{ //long sec = (this._h*60*60)+(this._m*60)+this._s; //_secFromMid = sec; //return this._secFromMid; //} public boolean equals (Time2 other) { if (this._secFromMid == other._secFromMid) { return true; } return false; } }

You might also like