public class Karyawan {
private String nama;
private int tglLahir;
private int blnLahir;
private int thnLahir;
public Karyawan() {
}
public void setNama(String nama) {
this.nama = nama;
}
public void setTglLahir(int tanggal) throws Exception {
if (tanggal > 0 && tanggal <= 31) {
this.tglLahir = tanggal;
} else {
throw new Exception("Salah Tanggal");
}
}
public void setBlnLahir(int bulan) throws Exception {
if (bulan > 0 && bulan <= 12) {
this.blnLahir = bulan;
} else {
throw new Exception("Salah Bulan");
}
}
public void setThnLahir(int tahun) throws Exception {
if (tahun > 0 && tahun >= 1900) {
this.thnLahir = tahun;
} else {
throw new Exception("Salah Tahun");
}
}
}
private String nama;
private int tglLahir;
private int blnLahir;
private int thnLahir;
public Karyawan() {
}
public void setNama(String nama) {
this.nama = nama;
}
public void setTglLahir(int tanggal) throws Exception {
if (tanggal > 0 && tanggal <= 31) {
this.tglLahir = tanggal;
} else {
throw new Exception("Salah Tanggal");
}
}
public void setBlnLahir(int bulan) throws Exception {
if (bulan > 0 && bulan <= 12) {
this.blnLahir = bulan;
} else {
throw new Exception("Salah Bulan");
}
}
public void setThnLahir(int tahun) throws Exception {
if (tahun > 0 && tahun >= 1900) {
this.thnLahir = tahun;
} else {
throw new Exception("Salah Tahun");
}
}
}
Tidak ada komentar:
Posting Komentar