Advertisement
Guest User

Untitled

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