Advertisement
hendroprwk08

Untitled

Sep 30th, 2022 (edited)
995
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.24 KB | None | 0 0
  1. import java.text.DecimalFormat;
  2. import java.util.Scanner;
  3.  
  4. public class Karyawan {
  5.     String nik, nama, bagian;
  6.     double gaji_pokok;
  7.    
  8.     double getGajiPokok(){
  9.         if(bagian.equalsIgnoreCase("Keuangan") ){
  10.             gaji_pokok = 12000;
  11.         }else if(bagian.equalsIgnoreCase("Produksi") ){
  12.             gaji_pokok = 11000;
  13.         }else{
  14.             gaji_pokok = 10000;
  15.         }
  16.        
  17.         return gaji_pokok;
  18.     }
  19.    
  20.     void cetak(){
  21.         DecimalFormat df = new DecimalFormat("##0,000");
  22.        
  23.         System.out.println("------ Detil Karyawan ------");
  24.         System.out.println("No: "+ this.nik);
  25.         System.out.println("Nama: "+ this.nama);
  26.         System.out.println("Bagian: "+ this.bagian);
  27.         System.out.println("Gaji Pokok: "+ df.format(getGajiPokok()));
  28.     }
  29. }
  30.  
  31. class MainKaryawan{
  32.     public static void main(String[] args){
  33.         Scanner sc = new Scanner(System.in);
  34.         Karyawan k = new Karyawan();
  35.        
  36.         System.out.print("Nomer Karyawan: ");
  37.         k.nik = sc.next();
  38.        
  39.         System.out.print("Nama: ");
  40.         k.nama = sc.next();
  41.        
  42.         System.out.print("Bagian: ");
  43.         k.bagian = sc.next();
  44.        
  45.         k.cetak();
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement