Postingan lainnya
Kelas Premium!
Belajar Javascript untuk website
Gunakan kupon "mulaijs" untuk diskon 75 ribu!
Bagaimana Cara Menginputkan Data ke Arrayof object dan loop Pemrograman Berorientasi Objek
Selamat siang, salam sejahtera, saya mau bertanya mengenai script berikut, dimana kesalahannya, dan bagaimana benarnya?
import java.io.*;
import javax.swing.JOptionPane;
public class ClsIdentitas {
protected String nama, alamat, telp;
public ClsIdentitas (String nama, String alamat, String telp) {
this.nama = nama;
this.alamat = alamat;
this.telp = telp;
}
public void Output() {
System.out.println("Nama : " + nama + "\nAlamat : " + alamat + "\nTelp : " + telp);
}
}
public class Karyawanx extends ClsIdentitas {
private String nik;
public Karyawanx(String nama, String alamat, String telp, String pNik) {
super(nama, alamat, telp);
this.pNik = pNik;
}
public String get(){
return nik;
}
public String getNama(){
return nama;
}
public void Output(){
System.out.println("NIK : " + nik);
this.Output();
}
}
public class C1GajiKar {
private String Gol;
private int JmlLembur;
public void Gol(String Gol){
this.gol = gol;
}
public void JmlLembur(int JmlLembur){
this.JmlLembur = JmlLembur;
}
public void tampilHitung(){
double Gaji;
double lembur = JmlLembur * 10000;
if(Gol == 1){
Gaji = 2500000;
}
else if(Gol == 2){
Gaji = 2000000;
}
else if(Gol == 3){
Gaji = 1750000;
}
else {
Gaji = 1500000;
}
System.out.println("Gaji Pokok : " + Gaji);
System.out.println("Uang Lembur : " + lembur);
System.out.println((Gaji+lembur));
}
}
public class Main {
public static void main(String[] args){
String input;
Karyawanx = new Karyawanx[3];
Karyawanx[0] = new Karyawanx("Riyanti", "Jl.Angkasa 20", "084242242", "16.0289");
Karyawanx[1] = new Karyawanx("Rahmat Wa", "Jl.Bebek 121", "0746334", "16.0325");
Karyawanx[2] = new Karyawanx("Dwi Ary", "Jl.Hasyim 100", "084854", "16.0254");
input = new input[3];
for(int i = 0; i < 3 ; i++) {
input[i] = new Karyawanx();
String data = input[i].get() + " - " + input[i].getNama();
input = JOptionPane.showInputDialog(data + "\nMasukkan Golongan : ");
input[i].Gol(Integer.parseDoub(Gol));
input = JOptionPane.showInputDialog(data + "\nMasukkan jml Lembur : ");
input[i].JmlLembur(Integer.parseInt(JmlLembur));
}
System.out.println("===== TAMPIL DATA GAJI KARYAWAN =====");
for (int i = 0; i<=3; i++){
System.out.println("Data " + (i+1));
Karyawanx[i].Karyawanx();
Karyawanx[i].tampilHitung();
System.out.println("=====================================");
}
}
}
0
1 Jawaban:
tulis kode nya di tag kode gan...
import java.io.*; import javax.swing.JOptionPane; public class ClsIdentitas { protected String nama, alamat, telp; public ClsIdentitas (String nama, String alamat, String telp) { this.nama = nama; this.alamat = alamat; this.telp = telp; } public void Output() { System.out.println("Nama : " + nama + "\nAlamat : " + alamat + "\nTelp : " + telp); } } public class Karyawanx extends ClsIdentitas { private String nik; public Karyawanx(String nama, String alamat, String telp, String pNik) { super(nama, alamat, telp); this.pNik = pNik; } public String get(){ return nik; } public String getNama(){ return nama; } public void Output(){ System.out.println("NIK : " + nik); this.Output(); } } public class C1GajiKar { private String Gol; private int JmlLembur; public void Gol(String Gol){ this.gol = gol; } public void JmlLembur(int JmlLembur){ this.JmlLembur = JmlLembur; } public void tampilHitung(){ double Gaji; double lembur = JmlLembur * 10000; if(Gol == 1){ Gaji = 2500000; } else if(Gol == 2){ Gaji = 2000000; } else if(Gol == 3){ Gaji = 1750000; } else { Gaji = 1500000; } System.out.println("Gaji Pokok : " + Gaji); System.out.println("Uang Lembur : " + lembur); System.out.println((Gaji+lembur)); } } public class Main { public static void main(String[] args){ String input; Karyawanx = new Karyawanx[3]; Karyawanx[0] = new Karyawanx("Riyanti", "Jl.Angkasa 20", "084242242", "16.0289"); Karyawanx[1] = new Karyawanx("Rahmat Wa", "Jl.Bebek 121", "0746334", "16.0325"); Karyawanx[2] = new Karyawanx("Dwi Ary", "Jl.Hasyim 100", "084854", "16.0254"); input = new input[3]; for(int i = 0; i < 3 ; i++) { input[i] = new Karyawanx(); String data = input[i].get() + " - " + input[i].getNama(); input = JOptionPane.showInputDialog(data + "\nMasukkan Golongan : "); input[i].Gol(Integer.parseDoub(Gol)); input = JOptionPane.showInputDialog(data + "\nMasukkan jml Lembur : "); input[i].JmlLembur(Integer.parseInt(JmlLembur)); } System.out.println("===== TAMPIL DATA GAJI KARYAWAN ====="); for (int i = 0; i<=3; i++){ System.out.println("Data " + (i+1)); Karyawanx[i].Karyawanx(); Karyawanx[i].tampilHitung(); System.out.println("====================================="); } } }
0