dewimardanic

Untitled

Oct 10th, 2020
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.72 KB | None | 0 0
  1.  
  2. /**
  3.  * Fig 8.2 : Time1Test.java
  4.  * Time1 object used in an application.
  5.  * @author (Dewi Mardani C)
  6.  * @version (09/10/2020)
  7.  */
  8.  public class Time1Test
  9.  {
  10.      public static void main( String[] args )
  11.      {
  12.          // create and initialize a Time1 object
  13.          Time1 time = new Time1(); // invokes Time1 constructor
  14.          // output string representations of the time
  15.          System.out.print( "The initial universal time is: " );
  16.          System.out.println(time.toUniversalString());
  17.          System.out.print( "The initial standard time is: " );
  18.          System.out.println( time.toString() );
  19.          System.out.println(); // output a blank line
  20.  
  21.          // change time and output updated time
  22.         time.setTime( 13, 27, 6 );
  23.         System.out.print( "Universal time after setTime is: " );
  24.         System.out.println( time.toUniversalString() );
  25.         System.out.print( "Standard time after setTime is: " );
  26.         System.out.println( time.toString() );
  27.         System.out.println(); // output a blank line
  28.  
  29.         // attempt to set time with invalid values
  30.         try
  31.         {
  32.             time.setTime( 99, 99, 99 ); // all values out of range
  33.  
  34.         } // end try
  35.         catch ( IllegalArgumentException e )
  36.         {
  37.             System.out.printf( "Exception: %s\n\n", e.getMessage() );
  38.         } // end catch
  39.  
  40.         // display time after attempt to set invalid values
  41.         System.out.println( "After attempting invalid settings:" );
  42.         System.out.print( "Universal time: " );
  43.         System.out.println( time.toUniversalString() );
  44.         System.out.print( "Standard time: " );
  45.         System.out.println( time.toString() );
  46.     } // end main
  47.  } // end class Time1Test
Advertisement
Add Comment
Please, Sign In to add comment