Konstruktor dan Overloading

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package konstruktordanoverloadingikanburungkomputer;

// KELAS IKAN——————————————————————-
class ikan{
String namaIkan,makananIkan,jenisAir;
int harga;
boolean bersisik,mamalia;

public ikan(String nama,String makanan,String air,int hrg,boolean sisik,boolean mamalia){
namaIkan=nama;
makananIkan=makanan;
jenisAir=air;
harga=hrg;
bersisik=sisik;
this.mamalia=mamalia;
}
public ikan(String nama,boolean mamalia){
namaIkan=nama;
this.mamalia=mamalia;
}
}

// KELAS BURUNG—————————————————————–
class burung{
String namaBurung,warnaBurung,makananBurung;
int masaHidup;

public burung(String burung,String warna,String makanan,int umur){
namaBurung=burung;
warnaBurung=warna;
makananBurung=makanan;
masaHidup=umur;
}
}

// KELAS KOMPUTER—————————————————————
class komputer{
String jenisKomputer,cpu,vga,os;
int kapasitasRam,kapasitasHardisk,ukuranLayar;
boolean bergaransi;

public komputer(String komputer,String prosesor,String graphic,String operatingSystem,int layar, int ram,int hdd,boolean garansi){
jenisKomputer=komputer;
cpu=prosesor;
vga=graphic;
os=operatingSystem;
kapasitasRam=ram;
kapasitasHardisk=hdd;
ukuranLayar=layar;
bergaransi=garansi;
}
public komputer(String komputer,String prosesor,int ram,int hdd){
jenisKomputer=komputer;
cpu=prosesor;
kapasitasRam=ram;
kapasitasHardisk=hdd;
vga=”AMD ATI M Radeon HD5470″;
os=”Linux Ubuntu 11.04″;
ukuranLayar=14;
bergaransi=true;
}

}
/**
*
* @author ANGGA
*/
public class Main {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
//ikan
ikan piranha=new ikan(“Piranha”,”Daging”,”Tawar”,40000,true,false);
System.out.println(“Nama Ikan       : “+piranha.namaIkan);
System.out.println(“Makanan Ikan    : “+piranha.makananIkan);
System.out.println(“Jenis Air       : “+piranha.jenisAir);
System.out.println(“Harga Ikan       : “+piranha.harga+” Rupiah”);
System.out.println(“Bersisik        : “+piranha.bersisik);
System.out.println(“Mamalia         : “+piranha.mamalia);
System.out.println();

// burung
burung elang=new burung(“Elang”,”Merah Hitam”,”Daging”,10);
System.out.println(“Nama Burung     : “+elang.namaBurung);
System.out.println(“Warna Burung    : “+elang.warnaBurung);
System.out.println(“Makanan         : “+elang.makananBurung);
System.out.println(“Umur            : “+elang.masaHidup+” tahun”);
System.out.println();

// komputer
komputer pc=new komputer(“pc”,”Core i7 3.5 Ghz Extreme Edition”,”Nvidia Quadro FX 5000″,”windows 7″,17,2,500,true);
System.out.println(“Jenis Komuputer     : “+pc.jenisKomputer);
System.out.println(“Prosesor            : “+pc.cpu);
System.out.println(“VGA                 : “+pc.vga);
System.out.println(“Operating System    : “+pc.os);
System.out.println(“Layar               : “+pc.ukuranLayar);
System.out.println(“RAM                 : “+pc.kapasitasRam+” GB”);
System.out.println(“HDD                 : “+pc.kapasitasHardisk+” GB”);
System.out.println(“Bergaransi          : “+pc.bergaransi);
System.out.println();

komputer laptop=new komputer(“Notebook”,”AMD Turion 3.0 Ghz”,4,500);
System.out.println(“Jenis Komuputer     : “+laptop.jenisKomputer);
System.out.println(“Prosesor            : “+laptop.cpu);
System.out.println(“VGA                 : “+laptop.vga);
System.out.println(“Operating System    : “+laptop.os);
System.out.println(“Layar               : “+laptop.ukuranLayar);
System.out.println(“RAM                 : “+laptop.kapasitasRam+” GB”);
System.out.println(“HDD                 : “+laptop.kapasitasHardisk+” GB”);
System.out.println(“Bergaransi          : “+laptop.bergaransi);
}

}

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout /  Ubah )

Foto Google

You are commenting using your Google account. Logout /  Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout /  Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout /  Ubah )

Connecting to %s