Contoh menghitung gaji dengan array
Code:
import java.io.*;
public class tugas {
public static void main(String [] args)
throws IOException {
InputStreamReader key=new
InputStreamReader (System.in);
BufferedReader input=new
BufferedReader(key);
int i,n,z,l;
String no_induk[],nama[],gol[];
int gapok[],tunj[],jml[];
int tot_gaji=0;
System.out.println("FORM INPUT GAJI
PEGAWAI");
System.out.println("Masukkan jumlah
pegawai yang akan di input: ");
n=Integer.parseInt(input.readLine());
/** Variabel di deklarasikan */
no_induk=new String[n];
nama=new String[n];
gol=new String[n];
gapok=new int[n];
tunj=new int[n];
jml=new int[n];
/** Looping untuk input data */
System.out.println
("=================================
");
System.out.println(" DATA GAJI
PEGAWAI");
System.out.println
("=================================
");
l=1;
for(i=0; i
System.out.println("Input data gaji
ke : "+l);
System.out.println("Masukkan
nomor induk pegawai\t :");
no_induk[i]=input.readLine();
System.out.println("Masukkan
nama pegawai \t\t :");
nama[i]=input.readLine();
System.out.println("Pilih golongan
[1/2/3] \t\t :");
gol[i]=input.readLine();
/** Logical 1 2 dan 3 */
if(gol[i].equalsIgnoreCase("1"))
{gapok[i]=2000000;tunj[i]
=1500000;jml[i]=gapok[i]+tunj[i];}
else if(gol[i].equalsIgnoreCase("2"))
{gapok[i]=1500000;tunj[i]
=1000000;jml[i]=gapok[i]+tunj[i];}
else if(gol[i].equalsIgnoreCase("3"))
{gapok[i]=1000000;tunj[i]
=500000;jml[i]=gapok[i]+tunj[i];}
else {gapok[i]=0;tunj[i]=0;jml[i]
=gapok[i]+tunj[i];}
System.out.println("Gaji pokok
"+nama[i]+" adalah:\t\t Rp."+gapok[i]);
System.out.println("Tunjangan
"+nama[i]+" adalah:\t\t Rp."+tunj[i]);
System.out.println("Total Gaji yang
diperoleh:\t Rp."+jml[i]);
l++;
}
/** Output */
z=1;
for(i=0; i
("------------------------------");
System.out.println("Pegawai ke-"+z);
System.out.println
("------------------------------");
System.out.println("Nomor pegawai
\t: "+no_induk[i]);
System.out.println("Nama pegawai\t:
"+nama[i]);
System.out.println("Golongan\t: "+gol
[i]);
System.out.println("Gaji pokok\t:
"+gapok[i]);
System.out.println("Tunjangan\t:
"+tunj[i]);
System.out.println("Gaji diterima\t:
"+jml[i]);
tot_gaji=tot_gaji+jml[i];
z++;
}
System.out.println
("-----------------------------------");
System.out.println("Total alokasi
untuk gaji\t: Rp."+tot_gaji);
}
}
Selamat mencoba.
Langganan:
Posting Komentar (Atom)
0 komentar: