public class Pegawai {
//atribute
private String nama;
private String jabatan;
private double gajipokok;
//constructor
public Pegawai(String nama, String jabatan, double gajipokok) {
this.nama = nama;
this.jabatan = jabatan;
this.gajipokok = gajipokok;
}
public Pegawai(String nama, double gajipokok) {
this.nama = nama;
this.gajipokok = gajipokok;
}
public Pegawai(){
}
//method
public double getGajiPokok() {
return gajipokok;
}
public String getJabatan() {
return jabatan;
}
public String getNama() {
return nama;
}
public double getTotalGaji(){
return gajipokok;
}
public void setGajiPokok(double gajipokok) {
this.gajipokok = gajipokok;
}
public void info(){
System.out.println("Data Pegawai : ");
System.out.println("Nama : "+ nama);
System.out.println("Jabatan : "+ jabatan);
System.out.println("Gaji Pokok : "+ gajipokok);
System.out.println("Total Gaji : "+ getTotalGaji());
}
}
package Pegawai;
public class Manager extends Pegawai {
//atribute
private double tunjangan;
//constructor
public Manager() {
}
public Manager(String nama, double gajipokok, double tunjangan) {
super(nama,"Manajer", gajipokok);
this.tunjangan=tunjangan;
}
public double getTunjangan() {
return tunjangan;
}
public void setTunjangan(double tunjangan) {
this.tunjangan = tunjangan;
}
@Override
public double getTotalGaji(){
return super.getGajiPokok()+tunjangan;
}
}
package Pegawai;
public class Programmer extends Pegawai {
//constructor
public Programmer(String nama, double gajipokok) {
super(nama,"Programmer", gajipokok);
}
public Programmer() {
}
}
package Pegawai;
public class Sales extends Pegawai {
//atribute
private double bonus;
//constructor
public Sales() {
}
public Sales(String nama, double gajipokok, double bonus) {
super(nama,"Sales", gajipokok);
this.bonus=bonus;
}
//method
public double getBonus() {
return bonus;
}
public void setBonus(double bonus) {
this.bonus = bonus;
}
@Override
public double getTotalGaji(){
return super.getGajiPokok() + bonus;
}
}
package Pegawai;
import java.util.ArrayList;
public class PayRoll {
private ArrayList
public PayRoll(ArrayList
this.daftarPegawai = daftarPegawai;
}
public PayRoll() {
}
public void cetakGaji(int a){
daftarPegawai.get(a).info();
}
public void addPegawai(Pegawai baru){
daftarPegawai.add(baru);
}
public int getJumlahData(){
return daftarPegawai.size();
}
}
package payroll_pegawai;
import Pegawai.*;
public class Payroll_pegawai {
public static void main(String[] args) {
Programmer bona = new Programmer("Bona", 1000000);
Programmer rongrong = new Programmer("Rongrong", 1000000);
Programmer oky = new Programmer("Oky", 1000000);
Sales nirmala = new Sales("Nirmala", 1000000, 500000);
Sales putri = new Sales("Putri", 1000000, 500000);
Manager upik = new Manager("Upik", 1000000, 2000000);
PayRoll pay = new PayRoll();
pay.addPegawai(bona);
pay.addPegawai(rongrong);
pay.addPegawai(oky);
pay.addPegawai(nirmala);
pay.addPegawai(putri);
pay.addPegawai(upik);
for(int i=0; i < pay.getJumlahData(); i++){
pay.cetakGaji(i);
}
}
}
Tidak ada komentar:
Posting Komentar