Tugas Kelompok Pemrograman Berorientasi Objek
Nama : 1. Agam Praditya Anggawira
2. Dadan Ramdani
Cd.java
class Cd
//superclass
|
protected String
judul;
protected String
publiser;
protected String
kategori;
protected int stok;
}
CdFilm.java
class CdFilm extends
Cd // kelas CdFilm merupakan turunan kelas Cd
|
private String
pemain;
private String
sutradra;
public CdFilm(String
j,String pemain,String sutradra,String p,String k,int s)
{
super.judul = j;
this.pemain =
pemain;
this.sutradra =
sutradra;
super.publiser = p;
super.kategori = k;
super.stok = s;
}
public String
toString()
{
return ("Judul
: " + super.judul + "\nPemain : " + pemain + "\nSutradara :
"
+ sutradra +
"\nPubliser : " + super.publiser + "\nKategori : " +
super.kategori + "\nStok :" + stok);
}
}
CdMusik.java
class CdMusik
extends Cd //kelas CdMusik merupakan
turunan kelas Cd
|
private String
penyanyi;
private String
produser;
private String topHits;
public
CdMusik(String j,String penyanyi,String produser,String p,String topHits,String
k,int s)
{
super.judul = j;
this.penyanyi =
penyanyi;
this.produser =
produser;
super.publiser =
publiser;
this.topHits =
topHits;
super.kategori = k;
super.stok = s;
}
public String
toString()
{
return ("Judul
:" + super.judul + "\nPenyanyi : " + penyanyi + "\nProduser
: " + produser + "\nPubliser : " + super.publiser +
"\nTopHits :
" + topHits + "\nKategori : " + super.kategori + "\nStok :
" + super.stok);
}
}
DemoExtends.java
import java.io.*;
class DemoExtends
{
public static void
main(String[]args)throws IOException
{
BufferedReader br =
new BufferedReader(new InputStreamReader(System.in));
for(int i=0;
i<2;);
{
System.out.println("1.
CdFilm");
System.out.println("2.
CdMusik");
System.out.println("3.
Keluar");
System.out.print("pilihan
?? ");
int pil=
Integer.parseInt(br.readLine());
if(pil==1)
{
CdFilm cf = new
CdFilm("Ada Apa Dengan Cinta","Dian
Sastro","Rudi","label Film","Remaja",200);
System.out.println("\n"
+ cf.toString() + "\n");
}
else if(pil==2)
{
CdMusik cm = new
CdMusik("Dilema Cinta","UNGU","Rampa","Label
Rekaman","Demi waktu","Pop",290);
System.out.println("\n"
+ cm.toString() + "\n");
}
else if(pil==3)
{
System.exit(0);
}
}
}
}
Tidak ada komentar:
Posting Komentar