hsbsb

Time1Test

Sep 16th, 2017
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.72 KB | None | 0 0
  1. /**
  2.  * Contoh aplikasi Time1 sebagai object
  3.  *
  4.  *
  5.  *
  6.  */
  7. public class Time1Test
  8. {
  9.     public static void main( String[] args )
  10.     {
  11.         // membuat dan menginisialisasi object Time1
  12.         Time1 time = new Time1(); // invokes Time1 constructor
  13.        
  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.         // ganti dengan input waktu yang baru
  22.         time.setTime(13, 30, 4);
  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.         // coba input waktu dengan nilai yang invalid
  30.         try
  31.         {
  32.             time.setTime( 99,99, 99 ); // semua nilai yang out of range
  33.         } // akhir dari try
  34.         catch ( IllegalArgumentException e )
  35.         {
  36.             System.out.printf( "Exception: %s\n\n", e.getMessage() );
  37.         } // akhir dari catch
  38.        
  39.         // menampilkan waktu setelah mencoba menginput dengan data yang invalid
  40.         System.out.println( "After attempting invalid settings:" );
  41.         System.out.print( "Universal time: " );
  42.         System.out.println( time.toUniversalString() );
  43.         System.out.print( "Standard time: " );
  44.         System.out.println( time.toString() );
  45.     } // akhir dari main
  46. }  // akhir dari class Time1Test
Advertisement
Add Comment
Please, Sign In to add comment