0

Plz help me to solve

1. Write a program using java to create : A class called Time, which models a time instance with hour, minute and second, is designed as shown in the class diagram. It contains the following members:  3 private instance variables hour, minute, and second.  Constructors, getters and setters.  A method setTime() to set hour, minute and second.  A toString() that returns "hh:mm:ss" with leading zero if applicable.  A method nextSecond() that advances this instance by one second. It returns this instance to support chaining (cascading) operations, e.g., t1.nextSecond().nextSecond(). Take note that the nextSecond() of 23:59:59 is 00:00:00. Write the Time class and a test driver to test all the public methods. No input validations are required.

1st Dec 2016, 6:35 AM
shaima
6 odpowiedzi
+ 3
@java4ever_tutorials telegram
1st Dec 2016, 7:34 AM
Saeed
Saeed - avatar
0
1. Write a program using java to create : A class called Time, which models a time instance with hour, minute and second, is designed as shown in the class diagram. It contains the following members:  3 private instance variables hour, minute, and second.  Constructors, getters and setters.  A method setTime() to set hour, minute and second.  A toString() that returns "hh:mm:ss" with leading zero if applicable.  A method nextSecond() that advances this instance by one second. It returns this instance to support chaining (cascading) operations, e.g., t1.nextSecond().nextSecond(). Take note that the nextSecond() of 23:59:59 is 00:00:00. Write the Time class and a test driver to test all the public methods. No input validations are required.
1st Dec 2016, 6:35 AM
shaima
0
Hi, in the first i don't understand what u want but i write this programe for u ,, i think the answer is : For (int h=1;h<=23;h++) For (int m=0;m<=59;m++) For (int s=0;s<=59;s++) System.out.println (h+":"+m+":"+s); }
1st Dec 2016, 7:33 AM
Hussam Ahmad
Hussam Ahmad - avatar
0
Show me what you already tried and I'll make the rest for you. No slackers.
1st Dec 2016, 11:43 AM
Seckar
Seckar - avatar
0
public class Time { private int hour, minute, second; Time () { hour = 0; minute = 0; second = 0; } Time (int hour, int minute, int second) { this.hour = hour; this.minute = minute; this.second = second; } public int get_hour() { return hour; } public int get_minute() { return minute; } public int get_second() { return second; } public void set_hour(int hour) { this.hour = hour; } public void set_minute(int minute) { this.minute = minute; } public void set_second(int second) { this.second = second; } public void set_time (int hour, int minute, int second) { this.hour = hour; this.minute = minute; this.second = second; } public String to_string() { StringBuffer time = new StringBuffer(); if(hour < 10) time.append('0'); time.append(hour); time.append(':'); if(minute < 10) time.append('0'); time.append(minute); time.append(':'); if(second < 10) time.append('0'); time.append(second); return time.toString(); } public Time next_second() { if (second == 59) { if (minute == 59) { if(hour == 23) { hour = 0; minute = 0; second = 0; } else { ++hour; minute = 0; second = 0; } } else { ++minute; second = 0; } } else ++second; return this; } } There, had nothing better to do, although your teacher might notice that the code is professionally done.
1st Dec 2016, 12:14 PM
Seckar
Seckar - avatar
0
The answer should be like this 03:02:01 00:00:00 04:05:06 Hour is: 4 Minute is: 5 Second is: 6 23:59:58 23:59:59 00:00:02
1st Dec 2016, 8:58 PM
shaima