// main class
Modify class Time2 to include a tick method that increments the time stored in a Time2 object by one second. Provide method incrementMinute to increment the minute and method incrementHour to increment the hour. The Time2 object should always remain
a) incrementing into the next minute,
b) incrementing into the next hour and
c) incrementing into the next day (i.e., 11:59:59 PM to 12:00:00 AM).
how to manage case 4 stuff and what's the problem of this CODE .. tnx
import java.util.Scanner; public class Time2Test { public static void main( String args[] ) { Scanner input = new Scanner( System.in ); Time2 time = new Time2(); // input System.out.println( "Enter the time" ); System.out.print( "Hours: " ); time.setHour( input.nextInt() ); System.out.print( "Minutes: " ); time.setMinute( input.nextInt() ); System.out.print( "Seconds: " ); time.setSecond( input.nextInt() ); // output System.out.printf( "Hour: %d Minute: %d Second: %d\n", time.getHour(), time.getMinute(), time.getSecond() ); System.out.printf( "Universal time: %s Standard time: %s\n", time.toUniversalString(), time.toString() ); //menu cases int choice = getMenuChoice(); while ( choice != 5 ) { switch ( choice ) { case 1: // add 1 second Time2 t = new Time2(); //create an object of type first t.tick(); t.newDisplay(); //use object to display. break; case 2: // add 1 minute Time2 m = new Time2(); //create an object of type first m.incrementMinute(); m.newDisplay(); break; case 3: // and 1 hour Time2 h = new Time2(); //create an object of type first h.incrementHour(); h.newDisplay(); break; case 4: // add arbitrary seconds System.out.print( "Enter seconds to tick: " ); break; } // end switch choice = getMenuChoice(); } // end while } // end main private static int getMenuChoice() { Scanner input = new Scanner( System.in ); //printing the menu System.out.println( "1. Add 1 second" ); System.out.println( "2. Add 1 Minute" ); System.out.println( "3. Add 1 Hour" ); System.out.println( "4. Add seconds" ); System.out.println( "5. Exit" ); System.out.print( "Choice: " ); return input.nextInt(); } // end method getMenuChoice } // end class Time2Test// class public class Time2 { private int hour; // 0 - 23 private int minute; // 0 - 59 private int second; // 0 - 5 public Time2() { this( 0, 0, 0 ); // invoke Time2 constructor with three arguments } // end Time2 no-argument constructor public Time2( int h, int m, int s ) { setTime( h, m, s ); // invoke setTime to validate time } // end Time2 three-argument constructor // Set Methods // set a new time value using universal time; perform // validity checks on data; set invalid values to zero public void setTime( int h, int m, int s ) { setHour( h ); // set the hour setMinute( m ); // set the minute setSecond( s ); // set the second } // end method setTime // validate and set hour public void setHour( int h ) { hour = ( ( h >= 0 && h < 24 ) ? h : 0 ); } // end method setHour // validate and set minute public void setMinute( int m ) { minute = ( ( m >= 0 && m < 60 ) ? m : 0 ); } // end method setMinute // validate and set second public void setSecond( int s ) { second = ( ( s >= 0 && s < 60 ) ? s : 0 ); } // end method setSecond // Get Methods // get hour value public int getHour() { return hour; } // end method getHour // get minute value public int getMinute() { return minute; } // end method getMinute // get second value public int getSecond() { return second; } // end method getSecond // convert to String in universal-time format (HH:MM:SS) public String toUniversalString() { return String.format("%02d:%02d:%02d", getHour(), getMinute(), getSecond() ); } // end method toUniversalString // convert to String in standard-time format (H:MM:SS AM or PM) public String toString() { return String.format( "%d:%02d:%02d %s", ( (getHour() == 0 || getHour() == 12) ? 12 : getHour() % 12 ), getMinute(), getSecond(), ( getHour() < 12 ? "AM" : "PM" ) ); } // end method toStandardString // Tick the time by one second public int tick() { setSecond(second+1) if ( second == 0 ) incrementMinute(); return( second + 1 ); } // Increment the minute public void incrementMinute() { setMinute( minute + 1 ); if ( minute == 0 ) incrementHour(); } // Increment the hour public void incrementHour() { setHour( hour + 1 ); } public void newDisplay() { System.out.printf( "Hour: %d Minute: %d Second: %d\n", getHour(), getMinute(), getSecond() ); System.out.printf( "Universal time: %s Standard time: %s\n", toUniversalString(),toString() ); } } /