Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Time2 {
- private int hour;
- private int minute;
- private int second;
- public Time2() {
- //this(0,0,0);
- setTime(0,0,0);
- }
- public Time2(int h) {
- //this(h, 0, 0);
- setTime(h, 0, 0);
- }
- public Time2(int usrhour, int usrminute){
- setTime(usrhour, usrminute, 0);
- }
- public Time2(int h, int m, int s) {
- setTime(h, m, s);
- }
- public Time2(Time2 t) {
- this.hour = t.getHour();
- this.minute = t.getMinute();
- this.second = t.getSeconds();
- }
- private void setTime(int h, int m, int s) {
- setHour(h);
- setMinute(m);
- setSecond(s);
- }
- private void setHour(int h) {
- hour = ( ( h >=0 && h < 24) ? h%12 : 0 );
- }
- private void setMinute(int m) {
- minute = ( ( m >= 0 && m < 60) ? m : 0 );
- }
- private void setSecond(int s) {
- second = ( ( s >= 0 && s < 60) ? s : 0 );
- }
- public int getHour(){ return this.hour; }
- public int getMinute() { return this.minute; }
- public int getSeconds() { return this.second; }
- public void addTime(int h, int m, int s) {
- setTime(this.hour + h, this.minute + m, this.second + s);
- }
- public void UpdateTime(Time2 t) {
- this.hour = t.hour;
- this.minute = t.minute;
- this.second = t.second;
- }
- public String toString() {
- return String.format("The Time is: %02d:%02d:%02d %s",
- this.hour, this.minute, this.second, ((hour < 12)? "AM" : "PM"));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement