Advertisement
GSculerlor

Untitled

Sep 14th, 2017
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.49 KB | None | 0 0
  1. public class MainTime2  
  2.  {  
  3.    public static void main( String[] args )  
  4.    {  
  5.      Time2 t1 = new Time2();  
  6.      Time2 t2 = new Time2( 2 );  
  7.      Time2 t3 = new Time2( 21, 34 );  
  8.      Time2 t4 = new Time2( 12, 25, 42 );  
  9.      Time2 t5 = new Time2( t4 );  
  10.      System.out.println( "Constructed with:" );  
  11.      System.out.println( "t1: all arguments defaulted" );  
  12.      System.out.printf( " %s\n", t1.toUniversalString() );  
  13.      System.out.printf( " %s\n", t1.toString() );  
  14.      System.out.println(  
  15.        "t2: hour specified; minute and second defaulted" );  
  16.      System.out.printf( " %s\n", t2.toUniversalString() );  
  17.      System.out.printf( " %s\n", t2.toString() );  
  18.      System.out.println(  
  19.      "t3: hour and minute specified; second defaulted" );  
  20.      System.out.printf( " %s\n", t3.toUniversalString() );  
  21.      System.out.printf( " %s\n", t3.toString() );  
  22.      System.out.println( "t4: hour, minute and second specified" );  
  23.      System.out.printf( " %s\n", t4.toUniversalString() );  
  24.      System.out.printf( " %s\n", t4.toString() );  
  25.      System.out.println( "t5: Time2 object t4 specified" );  
  26.      System.out.printf( " %s\n", t5.toUniversalString() );  
  27.      System.out.printf( " %s\n", t5.toString() );  
  28.      try  
  29.      {  
  30.       Time2 t6 = new Time2( 27, 74, 99 );  
  31.      }  
  32.      catch ( IllegalArgumentException e )  
  33.      {  
  34.        System.out.printf( "\nException while initializing t6: %s\n", e.getMessage() );  
  35.      }  
  36.    }  
  37.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement