Friday, August 29, 2014

Program Kepegawaian (extends) [Java]

Untuk menggunakan banyak class dalam satu program kita bisa menggunakan extends

Pertama, buatlah sebuah class dengan nama manusia


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author MIFTAHUL ILMI
 */
import javax.swing.*;
public class manusia {

    protected String nama="";
    protected String sex="";
    protected String tgl="";
    protected String alamat="";
    public manusia(){
        this.nama="";
        this.sex="";
        this.tgl="";
        this.alamat="";
    }
    public void setnama(){
        this.nama="";
    }
    public void setsex(){
        this.sex="";
    }
    public void settgl(){
        this.tgl="";
    }
    public void setalamat(){
        this.alamat="";
    }

    public String getnama(){
        return nama=JOptionPane.showInputDialog("nama : ");
    }
    public String getsex(){
        return sex=JOptionPane.showInputDialog("Jenis kelamin : ");
    }
    public String gettgl(){
        return tgl=JOptionPane.showInputDialog("Tangal Lahir : ");
    }
    public String getalamat(){
        return alamat=JOptionPane.showInputDialog("alamat : ");
    }
 


}

Selanjutnya buat class dengan nama pegawai


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author MIFTAHUL ILMI
 */
import javax.swing.*;
public class pegawai extends manusia {  
    private String nip="";
    private String dep="";
    private String gaji="";
    public pegawai(){
        this.nip="";
        this.dep="";
        this.gaji="";
    }
       public void setnip(){
           this.nip="";
       }
       public void setgaji(){
           this.gaji="";
       }
       public void setdep(){
           this.dep="";
       }
       public String getnip(){
           return nip=JOptionPane.showInputDialog("NIP : ");
       }
       public String getgaji(){
           return gaji=JOptionPane.showInputDialog("Gaji : ");
       }
       public String getdep(){
           return dep=JOptionPane.showInputDialog("Departemen : ");
       }

}


Setelah itu buat class pegawai tetap untuk memberi keunggulan daripada pegawai tidak tetap


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author MIFTAHUL ILMI
 */
import javax.swing.*;
public class pegawaitetap extends pegawai {
    private String gol="";
    private String tunj="";


    public pegawaitetap(){
        this.gol="";
        this.tunj="";
     }

 
    public void setgol(){
        this.gol="";
    }
    public void settunj(){
        this.tunj="";
    }
    public String getgol(){
        return gol=JOptionPane.showInputDialog("Golongan : ");
    }
    public String gettunj(){
        return tunj=JOptionPane.showInputDialog("Tunjangan : ");
    }

   
}


Selanjutnya buat class honor agar kita bisa menentukan honor tiap karyawan


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author MIFTAHUL ILMI
 */
import javax.swing.*;
public class honor extends pegawai {
    private String shf="";
    public honor(){
        this.shf="";
    }
    public void setshf(){
        this.shf="";
    }
    public String getshf(){
        return shf="Shift : ";
    }

}


dan yang terakhir buatlah class demo

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author MIFTAHUL ILMI
 */
import javax.swing.*;
public class demo {

     public static void main( String[] args){    
         pegawaitetap d=new pegawaitetap();
         honor r=new honor();
         System.out.println("Nama          : "+d.getnama());
         System.out.println("Jenis Kelamin : "+d.getsex());
         System.out.println("Alamat        : "+d.getalamat());
         System.out.println("NIP           : "+d.getnip());
         System.out.println("Depatemen     : "+d.getdep());
         System.out.println("Gaji          : "+d.getgaji());
         String z= JOptionPane.showInputDialog("Status :\n1.Pegawai Tetap\n2.Pegawai Honor");
         int s=Integer.parseInt(z);
         switch(s){
             case 1 :
                 System.out.println("Golongan      : "+d.getgol());
                 System.out.println("Tunjangan     : "+d.gettunj());
                 break;
             case 2 :
                 System.out.println("Shift         : "+r.getshf());
                 break;
         }

     }

}

Latihan JOptiaonPane [Java]

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author MIFYAHUL ILMI
 */
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import javax.swing.JOptionPane;
public class Latihan2JOP {
    public static void main(String[]args){
   BufferedReader dataIn = new BufferedReader(new
InputStreamReader(System.in) );
int[] tampung=new int [11];
int ukuranLarik=10;
int i=1;
while(1<=10){
String x="";
x=JOptionPane.showInputDialog("Masukkan Angka ke "+i);
tampung [i]=Integer.valueOf(x).intValue();
i++;
}
int a = tampung [0];
for (int max = 0; max

Latihan BufferedReader Java

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author MIFTAHUL ILMI
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Latihan1 {
 public static void main(String[]args)
    {
        BufferedReader dataIn = new BufferedReader(new InputStreamReader( System.in) );
        String name="";
        System.out.print("Please Enter Your Name : ");
        try
        {
            name = dataIn.readLine();
        }
        catch(IOException e)
        {
            System.out.println("Error!");
                }
        System.out.println("Hello"+name+"!");
    }


}

Operator kondisi Java

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author MIFTAHUL ILMI
 */
public class OperatorKondisi {
    public static void main (String[] args) {
        String status = "";
        int grade = 80;

        status = (grade >= 60)?"Passed":"Fail";
        System.out.println(status);
    }

}

Logika Exlusif Java

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author MIFTAHUL ILMI
 */
public class LogikaEkslusif {
public static void main (String[]args){

    boolean val1 = true;
    boolean val2 = true;

    System.out.println(val1 ^ val2);

    val1 = false;
    val2 = true;
    System.out.println(val1 ^ val2);


    val1 = false;
    val2 = true;
    System.out.println(val1 ^ val2);

    val1 = true; val2=false;
    System.out.println(val1^val2);

}
}

Logika Boolean Java

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author MIFTAHUL ILMI
 */
public class LogikadanBolean {
    public static void main (String[]args) {
        int i = 0;
        int j = 10;
        boolean test=false;

        //Demonstrasi&&
        test = (i>10) && (j++ > 9);
        System.out.println(i);
        System.out.println(j);
        System.out.println(test);

        //Demonstrasi
        test = (i>10) & (j++ > 9);
        System.out.println(i);
        System.out.println(j);
        System.out.println(test);

    }

}

Aritmatika Java

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author MIFTAHUL ILMI
 */
public class Aritmatika {
    public static void main (String[] args){
        int i = 37;
        int j = 42;
        double x = 27.475;
        double y = 7.22;
        System.out.println("Variable values...");
        System.out.println("  i = "+i);
        System.out.println("  j = "+j);
        System.out.println("  x = "+x);
        System.out.println("  y = "+y);

        System.out.println("Adding...");
        System.out.println("i + j ="+(i+j));
        System.out.println("x + y ="+(x+y));

        System.out.println("Subtracting...");
        System.out.println("i - j ="+(i-j));
        System.out.println("x - y ="+(x-y));

        System.out.println("Multiplying...");
        System.out.println("i * j = "+(i*j));
        System.out.println("x * y = "+(x*y));

        System.out.println("Dividing...");
        System.out.println("i : j = "+(i/j));
        System.out.println("x : y = "+(x/y));

        System.out.println("Computing The Remainder...");
        System.out.println("i % j = "+(i%j));
        System.out.println("x % y = "+(x%y));

        System.out.println("Mixing types...");
        System.out.println("j + y = "+(j+y));
        System.out.println("i + x = "+(i+x));

        }

}