Advertisement
mnaufaldillah

Time2Test Tugas 1

Oct 11th, 2020
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.83 KB | None | 0 0
  1.  
  2. /**
  3.  * Write a description of class Time2Test here.
  4.  *
  5.  * @author Muhammad Naufaldillah
  6.  * @version 10 October 2020
  7.  */
  8. public class Time2Test
  9. {
  10.     public static void main( String[] args )
  11.     {
  12.        Time2 t1 = new Time2(); // 00:00:00
  13.        Time2 t2 = new Time2( 2 ); // 02:00:00
  14.        Time2 t3 = new Time2( 21, 34 ); // 21:34:00
  15.        Time2 t4 = new Time2( 12, 25, 42 ); // 12:25:42
  16.        Time2 t5 = new Time2( t4 ); // 12:25:42
  17.        
  18.        System.out.println( "Constructed with:" );
  19.        System.out.println( "t1: all arguments defaulted" );
  20.        System.out.printf( " %s\n", t1.toUniversalString() );
  21.        System.out.printf( " %s\n", t1.toString() );
  22.        
  23.        System.out.println( "t2: hour specified; minute and second defaulted" );
  24.        System.out.printf( " %s\n", t2.toUniversalString() );
  25.        System.out.printf( " %s\n", t2.toString() );
  26.        
  27.        System.out.println( "t3: hour and minute specified; second defaulted" );
  28.        System.out.printf( " %s\n", t3.toUniversalString() );
  29.        System.out.printf( " %s\n", t3.toString() );
  30.        
  31.        System.out.println( "t4: hour, minute and second specified" );
  32.        System.out.printf( " %s\n", t4.toUniversalString() );
  33.        System.out.printf( " %s\n", t4.toString() );
  34.        
  35.        System.out.println( "t5: Time2 object t4 specified" );
  36.        System.out.printf( " %s\n", t5.toUniversalString() );
  37.        System.out.printf( " %s\n", t5.toString() );
  38.        
  39.        // attempt to initialize t6 with invalid values
  40.        try
  41.        {
  42.            Time2 t6 = new Time2( 27, 74, 99 ); // invalid values
  43.        } // end try
  44.        catch ( IllegalArgumentException e )
  45.        {
  46.            System.out.printf( "\nException while initializing t6: %s\n", e.getMessage() );
  47.        } // end catch
  48.     } // end main
  49. } // end class Time2Test
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement