Advertisement
mbah_bejo

8.2 Time1Test

Oct 11th, 2020
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.56 KB | None | 0 0
  1. // Objek Time1 diaplikasikan disini
  2.  
  3. import static org.junit.Assert.*;
  4. import org.junit.After;
  5. import org.junit.Before;
  6. import org.junit.Test;
  7.  
  8. /**
  9.  * 8.2 Time1Test.
  10.  *
  11.  * @thomasdwi
  12.  * @20201011
  13.  */
  14. public class Time1Test
  15. {
  16.  
  17.    public static void main( String[] args){
  18.  
  19.    //membuat dan menginisiasi objek Time1  
  20.    Time1 time = new Time1(); //memanggil konstruktur Time1
  21.    
  22.    //output string yang mempresentasikan waktu
  23.    System.out.print( "The Initial universal time is: " );
  24.    System.out.println( time.toUniversalString() );
  25.    System.out.print( "The initial standard time is: " );
  26.    System.out.println( time.toString() );
  27.    System.out.println();
  28.    
  29.    // merubah waktu dan memberi output waktu yang telah dirubah
  30.    time.setTime( 13, 27, 6);
  31.    System.out.print( "The Initial universal time is: " );
  32.    System.out.println( time.toUniversalString() );
  33.    System.out.print( "The initial standard time is: " );
  34.    System.out.println( time.toString() );
  35.    System.out.println();
  36.  
  37.    // memcoba untuk set nilai waktu yang tidak valid
  38.    try
  39.    {    
  40.        time.setTime(99, 99, 99); // semua nilai diluar range
  41.     }
  42.     catch ( IllegalArgumentException e )
  43.    {
  44.        System.out.printf("Exception: %s\n\n", e.getMessage());
  45.     }
  46.    
  47.  
  48.    //menampilkan waktu setelah percobaan diatas
  49.    System.out.println( "After attempting invalid settings: " );
  50.    System.out.print( "Universal time: " );
  51.    System.out.println( time.toUniversalString() );
  52.    System.out.print( "Standard time: " );
  53.    System.out.println( time.toString() );
  54.  
  55. }
  56. }
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement