Wednesday 15 October 2014

Tugas UML

Diagram UML :

Penyelesaian : 

1. buatlah project baru namanya terserah anda
lalu buatlah class bernama Penggunahp
dan copy code di bawah ini :
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package tugas.uml;

/**
 *
 * @author Novianto
 */
public class Penggunahp {
    nokai Handphoneku;
    manusia Manusiaku;
   
    void Daftar(manusia Penggunahp, nokai HP)
    {
        Manusiaku=Penggunahp;
        Handphoneku=HP;
    }
   
    void LihatData()
    {
        System.out.println ("Nama : " +Manusiaku.getNama());
        System.out.println ("Alamat : " +Manusiaku.getAlamat());
        System.out.println ("Umur : " +Manusiaku.getUmur() +" tahun");
       
        System.out.println ("Data HP : ");
        System.out.println ("Jenis : " +Handphoneku.getJenis());
        System.out.println ("Merek : " +Handphoneku.getMerek());
        System.out.println ("Harga : " +Handphoneku.getHarga());
        System.out.println ("Warna : " +Handphoneku.getWarna());

    }

}

2. lalu buat class lagi bernama manusia
dan copy code di bawah ini :
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package tugas.uml;

/**
 *
 * @author Novianto
 */
public class manusia {
 String Nama;
 String Alamat;
    int Umur;
   
    void setNama (String Nama)
    {
        this.Nama=Nama;
    }
   
    String getNama ()
    {
        return Nama;
    }
    void setAlamat (String Alamat)
    {
        this.Alamat=Alamat;
    }
   
    String getAlamat ()
    {
        return Alamat;
    }
   
    void setUmur (int Umur)
    {
        this.Umur=Umur;
    }
   
    int getUmur()
    {
        return Umur;
    } 
}

3. buat lagi class bernama handphone
copy lagi code di bawah ini :
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package tugas.uml;

/**
 *
 * @author Novianto
 */
public class Handphone {
    String Merek;
    int Harga;
    String Warna;
   

   
    void setMerek (String Merek)
    {
        this.Merek=Merek;
    }
   
    String getMerek()
    {
        return Merek;
    }
   
    void setHarga (int Harga)
    {
        this.Harga=Harga;
    }
   
    int getHarga()
    {
        return Harga;
    }
    void setWarna (String Warna)
    {
        this.Warna=Warna;
    }
   
    String getWarna()
    {
        return Warna;
    }    

}

4. buat class lagi bernama nokai
copy juga code ini :
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package tugas.uml;

/**
 *
 * @author Novianto
 */
public class nokai extends Handphone {
    String Jenis;
   
    void setJenis (String Jenis)
    {
        this.Jenis=Jenis;
    }
   
    String getJenis ()
    {
        return Jenis;
    }
}

5. terakhir buat class untuk tes namanya terserah anda pada kasus ini saya menggunakan nama main 
ini code nya :
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package tugas.uml;

/**
 *
 * @author Novianto
 */
public class Main
{
    public static void main (String [] args)
    {
        nokai nokaiku = new nokai();
        manusia Manusiaku = new manusia();
        Penggunahp User = new Penggunahp();
       
        Manusiaku.setNama ("Novianto A.P");
        Manusiaku.setAlamat ("Rembang Desa Waru Rt 04 Rw 03");
        Manusiaku.setUmur (19);

        nokaiku.setJenis ("Smart Phone");
        nokaiku.setMerek ("Nokai");
        nokaiku.setHarga (5000000);
        nokaiku.setWarna ("Hitam");
       
        User.Daftar(Manusiaku,nokaiku);
        User.LihatData();
    }
}

dan hasilnya akan seperti ini :


Sekian dari saya terimakasih.