I have two classes. time_runner is used for testing my code.
This is what I'm using to test my code:
class time_runner { public static void main(String str[]) throws IOException { Time time1 = new Time(14, 56); System.out.println("time1: " + time1); System.out.println("convert time1 to standard time: " + time1.convert()); System.out.println("time1: " + time1); System.out.print("increment time1 five times: "); time1.increment(); time1.increment(); time1.increment(); time1.increment(); time1.increment(); System.out.println(time1 + "\n"); Time time2 = new Time(-7, 12); System.out.println("time2: " + time2); System.out.print("increment time2 67 times: "); for (int i = 0; i < 67; i++) time2.increment(); System.out.println(time2); System.out.println("convert to time2 standard time: " + time2.convert()); System.out.println("time2: " + time2 + "\n"); Time time3 = new Time(5, 17); System.out.println("time3: " + time3); System.out.print("convert time3: "); System.out.println(time3.convert()); Time time4 = new Time(12, 15); System.out.println("\ntime4: " + time4); System.out.println("convert time4: " + time4.convert()); Time time5 = new Time(0, 15); System.out.println("\ntime5: " + time5); System.out.println("convert time5: " + time5.convert()); Time time6 = new Time(24, 15); System.out.println("\ntime6: " + time6); System.out.println("convert time6: " + time6.convert()); Time time7 = new Time(23,59); System.out.println("\ntime7: " + time7); System.out.println("convert time7: " + time7.convert()); time7.increment(); System.out.println("increment time7: " + time7); System.out.println("convert time7: " + time7.convert()); } }
This is what I'm working on completing. The two constructors are "Time()", which is the default constructor that sets the time to 1200, and "Time(int h, int m)" Which says If h is between 1 and 23 inclusive, set the hour to h. Otherwise, set the hour to 0. If m is between 0 and 59 inclusive, set the minutes to m. Otherwise, set the minutes to 0. Those are my two constructors that I pretty much have down. The three methods however I'm having trouble with. The "String toString()" Returns the time as a String of length 4. The "String convert()" Returns the time as a String converted from military time to standard time. The "void increment()" Advances the time by one minute.
public class Time { private int hour; private int minute; public Time(int h, int m) { if(h > 1 && h < 23) hour = h; else hour = 0; if(m > 0 && m < 59) minute = m; else minute = 0; } public String toString(){ return null; } public String convert(){ return null; } void increment(){ } }
I've got one of the constructors pretty much down, I just have no clue what I'm doing with the three methods. Any insight would be appreciated. Tyvm!