Tugas Java 6 november
Program Makanan.java
public class Makanan {
Makanan(String jenis)
{
this.jenis=jenis;
}
protected void rasa()
{
}
public String toString()
{
return "Makan " +jenis;
}
private String jenis;
}
Program Gudeg.java
public class Gudeg extends Makanan
{
Gudeg(String nama)
{
super("Gudeg");
this.nama=nama;
}
public void suara()
{
System.out.println("manis");
}
public String toString()
{
return super.toString()+" "+nama;
}
private String nama;
}
Program Boby.java
import java.util.Random;
public class Boby
{
public static void main(String[] args)
{
Makanan[] kesukaanku={new Manis("Manisan"),new Gudeg("Yogyakarta"),new Mpekmpek("Palembang"),new Soto("Betawi")};
Makanan kesukaan;
Random pilihan=new Random();
kesukaan=makanan[pilihan.nextInt(makanan.length)];
System.out.println("Makanan adalah "+kesuakaan);
System.out.println("Rasanya ");
kesukaan.rasa();
}
}
public class Makanan {
Makanan(String jenis)
{
this.jenis=jenis;
}
protected void rasa()
{
}
public String toString()
{
return "Makan " +jenis;
}
private String jenis;
}
Program Gudeg.java
public class Gudeg extends Makanan
{
Gudeg(String nama)
{
super("Gudeg");
this.nama=nama;
}
public void suara()
{
System.out.println("manis");
}
public String toString()
{
return super.toString()+" "+nama;
}
private String nama;
}
Program Boby.java
import java.util.Random;
public class Boby
{
public static void main(String[] args)
{
Makanan[] kesukaanku={new Manis("Manisan"),new Gudeg("Yogyakarta"),new Mpekmpek("Palembang"),new Soto("Betawi")};
Makanan kesukaan;
Random pilihan=new Random();
kesukaan=makanan[pilihan.nextInt(makanan.length)];
System.out.println("Makanan adalah "+kesuakaan);
System.out.println("Rasanya ");
kesukaan.rasa();
}
}
2 Komentar:
▷ 10cric login【VIP】【WG98.VIP】
11cric login,【WG98.VIP】⚡,cric casino bonus 10cric login code,best online 카지노 casino,super bonus,casino with bonus code: ミスティーノ 1005021-2020,win
pg
Posting Komentar
Berlangganan Posting Komentar [Atom]
<< Beranda