Anda di halaman 1dari 5

Implementasi Dalam Program Java

SuperClass Pegawai

package gaji.pegawai;

public class Pegawai {

private String nama;

private int nip;

private String alamat;

public Pegawai(){

public Pegawai(int nip, String nama, String alamat) {

this.nip = nip;

this.nama = nama;

this.alamat = alamat;

public void setNama(String nama){

this.nama = nama;

public String getNama(){

return this.nama;

public int getNip(){


return this.nip;

public int getGaji(){

return 1800000;

SubClass Staf

package gaji.pegawai;

public class Staf extends Pegawai {

private int jmlhJamLembur;

private final int upahLemburPerJam = 15000;

public Staf(int nip, String nama, String alamat) {

super(nip, nama, alamat);

public void setJmlhJamLembur(int jmlhJamLembur){

this.jmlhJamLembur = jmlhJamLembur;

@Override

public int getGaji(){

int total_gaji = jmlhJamLembur * upahLemburPerJam ;

return total_gaji+super.getGaji();

}
SubClass Manager

package gaji.pegawai;

public class Manager extends Pegawai{

private int jmlhKehadiran;

private final int tarifHarian = 100000;

public Manager(int nip, String nama, String alamat) {

super(nip, nama, alamat);

public void setKehadiran(int jmlhKehadiran){

this.jmlhKehadiran = jmlhKehadiran;

@Override

public int getGaji(){

int total_gaji = jmlhKehadiran*tarifHarian;

return total_gaji+super.getGaji();

}
TampilData MainGaji

package gaji.pegawai;

public class MainGaji {

public static void main(String[] args) {

Manager managerKu = new Manager(1605551013,"Yudi","Nangka");

Staf stafKu = new Staf(160551013,"Pratistha","Bikini Bottom");

managerKu.setKehadiran(27);

stafKu.setJmlhJamLembur(16);

System.out.println(managerKu.getNama() + " NIP " +


managerKu.getNip() + " anda mendapatkan gaji sebagai Manager " +
managerKu.getGaji());

System.out.println(stafKu.getNama() + " NIP " + stafKu.getNip() + "


anda mendapatkan gaji sebagai Staf " + stafKu.getGaji());