Codingan :
public class RadioConstructor {
public String Nama;
public String ret;
public Boolean on = false;
public int volume = 0;
public double frekuensi = 0;
//constructor overloading
public RadioConstructor(double frekuensi) {
this.frekuensi = frekuensi;
}
public RadioConstructor(String Nama) {
this.Nama = Nama;
}
public RadioConstructor(int volume,boolean on ) {
this.volume = volume;
this.on = on;
}
//Method overloading
public void print_radio(String Temp) {
System.out.println("\nObjek Radio " + Nama + " Berhasil Di buat");
}
public void print_radio(double frekuensi) {
System.out.println("Frekuensi Radio adalah " + frekuensi + " FM");
}
public void print_radio(int volume, boolean on) {
if (on == true) {
ret = "Radio Nyala";
} else {
ret = "Radio Mati";
}
if (volume > 0) {
ret += " Dengan Volume " + volume;
}
System.out.println(ret);
}
//
public String getNama() {
return Nama;
}
public void setNama(String Temp) {
Nama = Temp;
}
public double getfrekuensi() {
return frekuensi;
}
public void setfrekuensi(double frekuensi) {
this.frekuensi = frekuensi;
}
public int getvolume() {
return volume;
}
public void setvolume(int volume) {
this.volume = volume;
}
public boolean geton() {
return on;
}
public void seton(boolean on) {
this.on = on;
}
public static void main(String[] args) {
//Constructor overloading
RadioConstructor a = new RadioConstructor("Gen FM");
RadioConstructor x = new RadioConstructor(108.9);
RadioConstructor y = new RadioConstructor(30, true);
//method overloading
a.print_radio(a.getNama());
x.print_radio(x.getfrekuensi());
y.print_radio(y.getvolume(), y.geton());
}
}
Output nya :
Constructor Dengan Objek Radio
Nama : Irwan Syah
KElas : A
Nim : 2012420052
Informatika
Unitomo
Posted by 03.43 and have
0
komentar
, Published at
Tidak ada komentar:
Posting Komentar