Advertisement
ilminottaken

Untitled

Sep 21st, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. public class Time2Test
  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.  
  11. System.out.println( "Constructed with:" );
  12. System.out.println( "t1: all arguments defaulted" );
  13. System.out.printf( " %s\n", t1.toUniversalString() );
  14. System.out.printf( " %s\n", t1.toString() );
  15. System.out.println(
  16. "t2: hour specified; minute and second defaulted" );
  17. System.out.printf( " %s\n", t2.toUniversalString() );
  18. System.out.printf( " %s\n", t2.toString() );
  19. System.out.println(
  20. "t3: hour and minute specified; second defaulted" );
  21. System.out.printf( " %s\n", t3.toUniversalString() );
  22. System.out.printf( " %s\n", t3.toString() );
  23. System.out.println( "t4: hour, minute and second specified" );
  24. System.out.printf( " %s\n", t4.toUniversalString() );
  25. System.out.printf( " %s\n", t4.toString() );
  26. System.out.println( "t5: Time2 object t4 specified" );
  27. System.out.printf( " %s\n", t5.toUniversalString() );
  28. System.out.printf( " %s\n", t5.toString() );
  29. try
  30. {
  31. Time2 t6 = new Time2( 27, 74, 99 );
  32. }
  33. catch ( IllegalArgumentException e )
  34. {
  35. System.out.printf( "\nException while initializing t6: %s\n",
  36. e.getMessage() );
  37. }
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement