trizehn

Time2Test

Oct 14th, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.67 KB | None | 0 0
  1.  
  2. /**
  3.  * Write a description of class Time2Test here.
  4.  *
  5.  * @author Daffa Tristan Firdaus
  6.  * @version 0.1 8 Oktober 2020
  7.  */
  8. public class Time2Test
  9. {
  10.     public static void main(String[] args)
  11.     {
  12.         Time2 t1 = new Time2();
  13.         Time2 t2 = new Time2( 2 );
  14.         Time2 t3 = new Time2( 21, 34 );
  15.         Time2 t4 = new Time2( 12, 25, 42 );
  16.         Time2 t5 = new Time2( t4 );
  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 specified; minute and 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 specified; minute and second defaulted");
  32.         System.out.printf(" %s\n", t4.toUniversalString());
  33.         System.out.printf(" %s\n", t4.toString());
  34.        
  35.         System.out.println("t5: hour specified; minute and second defaulted");
  36.         System.out.printf(" %s\n", t5.toUniversalString());
  37.         System.out.printf(" %s\n", t5.toString());
  38.        
  39.         try
  40.         {
  41.             Time2 t6 = new Time2(27, 74, 99);
  42.         }
  43.         catch (IllegalArgumentException e)
  44.         {
  45.             System.out.printf( "\nException while initializing t6: %s\n",e.getMessage() );
  46.         }
  47.     }
  48. }
  49.  
Advertisement
Add Comment
Please, Sign In to add comment