public class Driver{
public static void main(String[]args){
Kompetisi k = new Kompetisi("GP","2013");
Tim a= new Tim("Ferari",2000000);
Tim b= new Tim("Mercadez",2500000);
Pembalap p = new Pembalap("Febri",19);
Pembalap q = new Pembalap("Izzan",19);
Pembalap r = new Pembalap("Irfan",19);
Pembalap s = new Pembalap("Firman",19);
a.addPembalap(p);
a.addPembalap(q);
b.addPembalap(r);
b.addPembalap(s);
k.addTim(a);
k.addTim(b);
k.showKompetisi();
}
}
public class Kompetisi{
private String namaKompetisi;
private String musim;
private Tim[] tim = new Tim[12];
private int jumTim;
public Kompetisi(String n, String m){
this.namaKompetisi = n;
this.musim=m;
}
public void setNamaKompetisi(String n){
this.namaKompetisi=n;
}
public void setMusim(String m){
this.musim = m;
}
public String getNamaKompetisi(){
return this.namaKompetisi;
}
public String getMusim(){
return this.musim;
}
public void addTim(Tim t){
this.tim[jumTim] = t;
jumTim++;
}
public void showKompetisi(){
System.out.println("Nama Kompetisi: "+this.namaKompetisi);
System.out.println("Musim: "+this.musim);
System.out.println();
for(int i=0; i<this.jumTim; i++){
this.tim[i].showTim();
System.out.println();
}
}
}
public class Pembalap{
private String nama;
private int umur;
public Pembalap(String n, int u){
this.nama = n;
this.umur = u;
}
public int getUmur(){
return this.umur;
}
public String getNama(){
return this.nama;
}
}
public class Tim{
private String namaTim;
private double finansial;
private Pembalap[] racer = new Pembalap[4];
private int jumPembalap;
public Tim(String n, double f){
this.namaTim = n;
this.finansial = f;
}
public String getNamaTim(){
return this.namaTim;
}
public double getFinansial(){
return this.finansial;
}
public void addPembalap(Pembalap p){
this.racer[jumPembalap]=p;
jumPembalap++;
}
public void showTim(){
System.out.println("Nama Tim: "+this.namaTim);
System.out.println("Finansial: "+this.finansial);
for(int i=0; i<this.jumPembalap; i++){
System.out.println("Pembalap ke- "+(i+1)+this.racer[i].getNama());
}
}
}
0 komentar:
Post a Comment