ilham_syamsuddin

Untitled

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