public class Driver{
public static void main(String[]args){
Manager m = new Manager("Arifin",1,500000);
Staff s1 = new Staff("a",3,100000);
Staff s2 = new Staff("b",2,100000);
s2.setJamLembur(3);
Staff s3 = new Staff("c",2,100000);
m.addStaff(s1);
m.addStaff(s2);
m.addStaff(s3);
m.displayData();
m.searchStaff("a");
m.searchStaff(2);
}
}
public class Karyawan{
protected String nama;
protected int golongan;
protected double gajiPokok;
public Karyawan(String n, int g){
this.nama = n;
this.golongan = g;
double a;
if(this.golongan==1){
a=4000000;
}
else if(this.golongan==2){
a=3000000;
}
else if(this.golongan==3){
a=2000000;
}
else {
a=1000000;
}
this.gajiPokok =a;
}
public String getNama(){
return this.nama;
}
public int getGolongan(){
return this.golongan;
}
public double getGajiPokok(){
return this.gajiPokok;
}
public void displayData(){
System.out.println("Nama: "+this.nama);
System.out.println("Golongan: "+this.golongan);
System.out.println("Gaji Pokok: "+this.gajiPokok);
}
}
public class Manager extends Karyawan{
protected int jumlahStaff=0;
protected double tunjangan;
protected double gajiTotal;
protected Staff[] arrayStaff = new Staff[5];
public Manager(String n, int g, double t){
super(n,g);
this.tunjangan =t;
}
public double getTunjangan(){
return this.tunjangan;
}
public double getGajiTotal(){
this.gajiTotal = this.getGajiPokok() + this.tunjangan;
return this.gajiTotal;
}
public void addStaff(Staff s){
arrayStaff[jumlahStaff] = s;
jumlahStaff++;
}
@Override
public void displayData(){
super.displayData();
System.out.println("Gaji Total: "+ this.getGajiTotal());
System.out.println("Staff:");
for(int i=0; i<jumlahStaff; i++){
arrayStaff[i].displayData();
}
}
public void searchStaff(String nama){
for(int i=0; i<jumlahStaff; i++){
if(arrayStaff[i].nama.equals(nama)){
arrayStaff[i].displayData();
}
}
}
public void searchStaff(int g){
for(int i=0; i<jumlahStaff; i++){
if(arrayStaff[i].golongan==g){
arrayStaff[i].displayData();
}
}
}
}
public class Staff extends Karyawan{
protected int jamLembur;
protected double gajiLemburPerJam;
protected double gajiTotal;
public Staff(String n, int g, double gj){
super(n,g);
this.gajiLemburPerJam = gj;
}
public int getJamLembur(){
return this.jamLembur;
}
public void setJamLembur(int j){
this.jamLembur = j;
}
public double getGajiLemburPerJam(){
return this.gajiLemburPerJam;
}
public double getGajiTotal(){
gajiTotal = getGajiPokok() + (this.jamLembur*this.gajiLemburPerJam);
return gajiTotal;
}
@Override
public void displayData(){
System.out.println("Nama: "+this.nama);
System.out.println("Golongan: "+this.golongan);
System.out.println("Gaji Pokok: "+this.gajiPokok);
System.out.println("Gaji Total: "+this.getGajiTotal());
}
}
0 komentar:
Post a Comment