Advertisement
mnaufaldillah

Time1Test Tugas 1

Oct 11th, 2020
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.71 KB | None | 0 0
  1.  
  2. /**
  3.  * Write a description of class Time1Test here.
  4.  *
  5.  * @author Muhammad Naufaldillah
  6.  * @version 10 October 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.  
  15.         // output string representations of the time
  16.         System.out.print( "The initial universal time is: " );
  17.         System.out.println( time.toUniversalString() );
  18.         System.out.print( "The initial standard time is: " );
  19.         System.out.println( time.toString() );
  20.         System.out.println(); // output a blank line
  21.        
  22.         // change time and output updated time
  23.         time.setTime( 13, 27, 6 );
  24.         System.out.print( "The initial universal time is: " );
  25.         System.out.println( time.toUniversalString() );
  26.         System.out.print( "The initial standard time is: " );
  27.         System.out.println( time.toString() );
  28.         System.out.println(); // output a blank line
  29.        
  30.         // attempt to set time with invalid values
  31.         try
  32.         {
  33.             time.setTime( 99, 99, 99 ); // all values out of range
  34.         }
  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
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement