Senin, 29 Maret 2021

Learning Program

 

 

Dasar Program Java Berorientasi Objek

Seri 3


 
 
APLIKASI FISHCEANID : DASAR CONTAINER OOP





Yes it is us again! Adapun kali ini kita akan membahas tentang penggunaan Container. Container merupakan suatu konsep metode yang umumnya diterapkan untuk menghubungkan operasi dan menampung objek dan hasil query beragama dari operasi tersebut. Kurang lebih akan mudah dianalogikan seperti Container / penampung yang umum kita temui di kehidupan sehari - hari.
 
Target Kelas Kontainer

            Selama proses penerapan metode atau kelas kontainer ini tentunya kami menginginkan pembentukan kelas penampung yang cukup fungsional untuk digunakan dalam aplikasi. Adapun pengembangan dilakukan di kelas - kelas berikut.

 

Source Code & Class Provider

  • Main Class

package Fishceanid;

import java.util.Scanner;
public class appFishceanid {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int pilih=0;
        cPenjual pjl = null; //Object Penjual
        cPenjualan penjualan= null;
        cToko tko = null; //Object Toko
        cIkan ikn[] = new cIkan[5];
        ikn[0] = new cIkan("IKN01","Bawal","Air laut","Tangkap",100);
        ikn[1] = new cIkan("IKN02","Tuna","Air laut","Tangkap",20);
        ikn[2] = new cIkan("IKN03","Louhan","Air tawar","Hias",50);
        ikn[3] = new cIkan("IKN04","Cupang","Air tawar","Hias",200);
        ikn[4] = new cIkan("IKN05","Gupi","Air tawar","Hias",120);
        int jmk= 5;

        do {
            System.out.println("Sistem Fishceanid");
            System.out.println("1. Market");
            System.out.println("2. Shipment");
            System.out.println("3. About");
            System.out.println("4. Close");
            System.out.print("Opsi = ");
            pilih = scan.nextInt();

            System.out.println("");

            switch(pilih) {
                case 1 :
                    System.out.println("Menu Market");
                        System.out.println("1. Penjual");
                        System.out.println("2. Toko");
                        System.out.println("3. Ikan");
                        System.out.print("Opsi = ");
                        int pilih2 = scan.nextInt();

                        System.out.println("");

                        switch(pilih2) {
                            case 1 :
                                System.out.println("Tentang Penjual");
                                System.out.println("1. Tambah");
                                System.out.println("2. Update");
                                System.out.println("3. Lihat");
                                System.out.println("4. Hapus");
                                System.out.println("5. Query");
                                System.out.print("Pilihannya : ");
                                int pilih3 = scan.nextInt();

                                System.out.println("");

                                switch(pilih3) {
                                    case 1 :
                                        System.out.println("Menambahkan Data Penjual");
                                        System.out.print("ID Penjual = ");
                                        String idpj = scan.next();

                                        System.out.print("Nama = ");
                                        scan = new Scanner(System.in);
                                        String npj = scan.nextLine();

                                        System.out.print("Kontak = ");
                                        String kpj = scan.next();

                                        System.out.print("Alamat = ");
                                        String apj = scan.next();

                                        pjl = new cPenjual(idpj, npj, kpj, apj);
                                        System.out.println("Data Penjual Berhasil Ditambahkan");
                                        break;

                                    case 2 :
                                        System.out.println("Memperbarui Data Penjual");
                                        System.out.print("ID = ");
                                        idpj = scan.next();

                                        if(pjl!=null && pjl.getid_pjual().equalsIgnoreCase(idpj)) {
                                            System.out.print("Nama Baru = ");
                                            scan = new Scanner(System.in);
                                            npj = scan.nextLine();

                                            System.out.print("Kontak Baru = ");
                                            scan = new Scanner(System.in);
                                            kpj = scan.nextLine();

                                            System.out.print("Alamat Baru = ");
                                            scan = new Scanner(System.in);
                                            apj = scan.nextLine();

                                            pjl.setnama_pjual(npj);
                                            pjl.setkontak_pjual(kpj);
                                            pjl.setalamat_pjual(apj);

                                            System.out.println("Data Penjual Berhasil Diupdate");
                                        }
                                        else System.out.println("Data Penjual Tidak Ditemukan");
                                        break;

                                    case 3 :
                                        System.out.println("Melihat Data Penjual");
                                        if(pjl!=null) {
                                            System.out.println("ID = " + pjl.getid_pjual());
                                            System.out.println("Nama = " + pjl.getnama_pjual());
                                            System.out.println("Kontak = " + pjl.getkontak_pjual());
                                            System.out.println("Alamat = " + pjl.getalamat_pjual());
                                        }
                                        else System.out.println("Data Penjual Kosong");
                                        break;

                                    case 4 :
                                        System.out.println("Menghapus Data Penjual");
                                        System.out.print("ID Penjual = ");
                                        idpj = scan.next();
                                        if(pjl!=null && pjl.getid_pjual().equalsIgnoreCase(idpj)) {
                                            System.out.println("Data Penjual Telah Ditemukan");
                                            System.out.println("Apakah Yakin Ingin Dihapus? 1.Yes, 2.No");
                                            System.out.print("Opsi : ");
                                            int menghapus = scan.nextInt();
                                            
                                            if(menghapus==1) {
                                                pjl=null;
                                                System.out.println("Data Penjual Berhasil Dihapus");
                                            }
                                            else System.out.println("Data Penjual Tidak Dihapus");
                                        }
                                        else System.out.println("Data Penjual yang Dimaksud Tidak Ditemukan");
                                        break;

                                    case 5 :
                                        System.out.println("Query Data Penjual");
                                        if(pjl!=null) {
                                            System.out.println(pjl.toString());
                                        }
                                        else System.out.println("Data Penjual Kosong");

                                        break;
                                        default : System.out.println("Tidak Bisa Melakukan Hal Tersebut");
                                }
                                break;


                            case 2 :
                                System.out.println("Tentang Toko");
                                System.out.println("1. Tambah");
                                System.out.println("2. Update");
                                System.out.println("3. Lihat Toko");
                                System.out.println("4. Lihat Identitas Pemilik");
                                System.out.println("5. Lihat Detail Produk Toko");
                                System.out.println("6. Hapus");
                                System.out.println("7. Query");
                                System.out.print("Opsional : ");
                                int pilih4 = scan.nextInt();

                                System.out.println("");

                                switch(pilih4) {
                                    case 1 :
                                        System.out.println("Menambah Data Toko");
                                        System.out.print("ID Toko = ");
                                        String kdtk = scan.next();

                                        System.out.print("Nama Toko = ");
                                        scan = new Scanner(System.in);
                                        String ntk = scan.nextLine();

                                        System.out.print("Suplai = ");
                                        String stk = scan.next();

                                        System.out.print("Deskripsi Toko = ");
                                        scan = new Scanner(System.in);
                                        String desktk = scan.nextLine();

                                        System.out.print("Alamat Toko = ");
                                        scan = new Scanner(System.in);
                                        String atk = scan.next();

                                        tko = new cToko(kdtk, ntk, stk, desktk, atk);
                                        System.out.println("Data Toko Berhasil Ditambahkan");
                                        break;


                                    case 2 :
                                        System.out.println("Memperbarui Data Toko");
                                        System.out.print("Kode = ");
                                        kdtk = scan.next();

                                        if(tko!=null && tko.getkd_toko().equalsIgnoreCase(kdtk)) {
                                            System.out.print("Nama Baru Toko = ");
                                            scan = new Scanner(System.in);
                                            ntk = scan.nextLine();

                                            System.out.print("Suplai Baru = ");
                                            scan = new Scanner(System.in);
                                            stk = scan.nextLine();

                                            System.out.print("Deskripsi Baru = ");
                                            scan = new Scanner(System.in);
                                            desktk = scan.nextLine();

                                            System.out.print("Alamat Baru Toko = ");
                                            scan = new Scanner(System.in);
                                            atk = scan.nextLine();

                                            tko.setnama_toko(ntk);
                                            tko.setsuplai_toko(stk);
                                            tko.setdesk_toko(desktk);
                                            tko.setalamat_toko(atk);

                                            System.out.println("Data Toko Berhasil Diupdate");
                                        }
                                        else System.out.println("Data Toko Tidak Ditemukan");
                                        break;

                                    case 3 :
                                        System.out.println("Melihat Data Toko");
                                        if(tko!=null) {
                                            System.out.println("Kode Toko = " + tko.getkd_toko());
                                            System.out.println("Nama Toko = " + tko.getnama_toko());
                                            System.out.println("Suplai Toko = " + tko.getsuplai_toko());
                                            System.out.println("Deskripsi Toko = " + tko.getdesk_toko());
                                            System.out.println("Alamat Toko = " + tko.getalamat_toko());
                                        }
                                        else System.out.println("Data Toko Tidak Tersedia");
                                        break;

                                    case 4 :
                                        System.out.println("Melihat Data Pemilik");
                                        if(pjl!=null) {
                                            System.out.println("ID Pemilik = " + pjl.getid_pjual());
                                            System.out.println("Nama Pemilik = " + pjl.getnama_pjual());
                                            System.out.println("Kontak Pemilik = " + pjl.getkontak_pjual());
                                            System.out.println("Alamat Pemilik = " + pjl.getalamat_pjual());
                                        }
                                        else System.out.println("Data Pemilik Kosong");
                                        break;

                                    case 5 :
//                                        System.out.println("Melihat Data Ikan Toko");
//                                        if(ikn!=null) {
//                                            System.out.println("Kode Ikan di Toko = " + ikn.getkd_ikan());
//                                            System.out.println("Nama Ikan di Toko = " + ikn.getnama_ikan());
//                                            System.out.println("Spesies Ikan di Toko = " + ikn.getspesies_ikan());
//                                            System.out.println("Tipe Ikan di Toko = " + ikn.gettipe_ikan());
//                                            System.out.println("Jumlah Ikan = " + ikn.getjumlah_ikan());
//                                        }
//                                        else System.out.println("Data Toko Kosong");
                                        break;

                                    case 6 :
                                        System.out.println("Menghapus Data Toko");
                                        System.out.print("Kode Toko = ");
                                        kdtk = scan.next();
                                        if(tko!=null && tko.getkd_toko().equalsIgnoreCase(kdtk)) {
                                            System.out.println("Data Toko Telah Ditemukan");
                                            System.out.println("Apakah Yakin Ingin Dihapus? 1.Yes, 2.No");
                                            System.out.print("Opsi : ");
                                            int menghapus = scan.nextInt();
                                            
                                            if(menghapus==1) {
                                                tko=null;
                                                System.out.println("Data Toko Berhasil Dihapus");
                                            }
                                            else System.out.println("Data Toko Tidak Dihapus");
                                        }
                                        else System.out.println("Data Toko yang Dimaksud Tidak Ditemukan");

                                        break;

                                    case 7 :
                                        System.out.println("Query Data Toko");
                                        if(tko!=null) {
                                            System.out.println(tko.toString());
                                        }
                                        else System.out.println("Data Toko Kosong");

                                        break;
                                        default : System.out.println("Tidak Bisa Melakukan Hal Itu");

                                    }
                                    break;


                            case 3 :
                                System.out.println("Tentang Ikan");
                                System.out.println("1. Tambah Data Ikan");
                                System.out.println("2. Update Data Ikan");
                                System.out.println("3. Lihat Data Ikan");
                                System.out.println("4. Hapus Data Ikan");
                                System.out.println("5. Query Data Ikan");
                                System.out.print("Pilihannya : ");
                                int pilih5 = scan.nextInt();

                                System.out.println("");
                                
                                switch(pilih5) {
                                    case 1 :
//                                        System.out.println("Menambah Data Ikan");
//                                        System.out.print("Kode Ikan = ");
//                                        String kdik = scan.next();
//
//                                        System.out.print("Nama Ikan = ");
//                                        scan = new Scanner(System.in);
//                                        String namik = scan.nextLine();
//
//                                        System.out.print("Spesies Ikan = ");
//                                        String spik = scan.nextLine();
//
//                                        System.out.print("Tipe Ikan = ");
//                                        scan = new Scanner(System.in);
//                                        String tipik = scan.nextLine();
//
//                                        ikn = new cIkan(kdik, namik, spik, tipik);
//                                        System.out.println("Data Ikan Berhasil Ditambahkan");

                                        break;

                                    case 2 :
//                                        System.out.println("Memperbarui Data Ikan");
//                                        System.out.print("Kode Ikan yang Diperbarui = ");
//                                        kdik = scan.next();
//
//                                        if(ikn!=null && ikn.getkd_ikan().equalsIgnoreCase(kdik)) {
//                                            System.out.print("Nama Baru Ikan = ");
//                                            scan = new Scanner(System.in);
//                                            namik = scan.nextLine();
//
//                                            System.out.print("Spesies Baru Ikan = ");
//                                            scan = new Scanner(System.in);
//                                            spik = scan.nextLine();
//
//                                            System.out.print("Tipe Baru Ikan = ");
//                                            scan = new Scanner(System.in);
//                                            tipik = scan.nextLine();
//
//                                            System.out.print("Jumlah Baru Ikan = ");
//                                            scan = new Scanner(System.in);
//                                            int jumik = scan.nextInt();
//
//                                            ikn.setnama_ikan(namik);
//                                            ikn.setspesies_ikan(spik);
//                                            ikn.settipe_ikan(tipik);
//                                            ikn.setjumlah_ikan(jumik);
//
//                                            System.out.println("Data Ikan Berhasil Diupdate");
//                                        }
//                                        else System.out.println("Data Ikan Tidak Ditemukan");

                                        break;

                                    case 3 :
                                        System.out.println("Melihat Data Ikan");
                                            for (int i = 0; i < jmk; i++) {
                                                System.out.println(ikn[i].getkd_ikan()+"\t"+ikn[i].getnama_ikan()+"\t"+
                                                ikn[i].getspesies_ikan()+"\t"+ikn[i].gettipe_ikan()+"\t"+ikn[i].getjumlah_ikan());
                                             }
                                        break;

                                    case 4 :
//                                        System.out.println("Menghapus Data Ikan");
//                                        System.out.print("Kode Ikan yang Ingin Dihapus = ");
//                                        kdik = scan.next();
//                                        if(ikn!=null && ikn.getkd_ikan().equalsIgnoreCase(kdik)) {
//                                            System.out.println("Data Ikan Telah Ditemukan");
//                                            System.out.println("Apakah Yakin Ini Dihapus? 1.Yes, 2.No");
//                                            System.out.print("Opsional : ");
//                                            int menghapus = scan.nextInt();
//                                            
//                                            if(menghapus==1) {
//                                                ikn=null;
//                                                System.out.println("Data Ikan Berhasil Dihapus");
//                                            }
//                                            else System.out.println("Data Ikan Tidak Dihapus");
//                                        }
//                                        else System.out.println("Data Ikan yang Dimaksud Tidak Ditemukan");

                                        break;

                                    case 5 :
                                        System.out.println("Query Data Ikan");
                                        if(ikn!=null) {
                                            System.out.println(ikn.toString());
                                        }
                                        else System.out.println("Data Ikan Kosong");

                                        break;
                                        default : System.out.println("Tidak Bisa Melakukan Hal Itu");
                                }

                                break;
                                default : System.out.println("Opsi Tersebut Tidak Tersedia");
                                
                                case4:
                                    System.out.println("    Menu Pembelian");
                                    System.out.println("    1. Tambah");
                                    System.out.println("    2. Ubah");
                                    System.out.println("    3. Lihat");
                                    System.out.println("    4. Hapus");
                                    System.out.print("pilih = ");
                                    int pilih6 = scan.nextInt();
                                        switch(pilih6) {
                                            case 1:
                                                System.out.print("    Kode Transaksi = ");
                                                String kdt= scan.next();
                                                System.out.print("    Masukan Nama Toko  = ");
                                                String nmtk = scan.next();
                                                System.out.print("    Masukan Nama Penjual   = ");
                                                String nmpjl = scan.next();
                                                //validasi nama pembeli dan kode barang
                                                if(tko!=null && tko.getnama_toko().equalsIgnoreCase(nmtk)) {
                                                    if(pjl!=null && pjl.getnama_pjual().equalsIgnoreCase(nmpjl)) {
                                                        penjualan = new cPenjualan (kdt,pjl,tko);
                                                        System.out.println("Penjualan sukses...");
                                                    }
                                                    else System.out.println("Nama Penjual Tidak Ada!");
                                                }
                                                else
                                                    System.out.println("Nama toko Tidak Ada!");
                                                break;
                                            case 2:
                                                break;
                                            case 3:
                                                System.out.println("Lihat Pembelian");
                                                if (penjualan!=null) {
                                                    System.out.println("Kode\tPembeli\tBarang");
                                                    System.out.println(penjualan.ToString());

                                                }
                                                else System.out.println("penjualan masih kosong!");
                                                break;
                                            case 4:
                                                break;
                                        }
                                break;
                        }
                        
                        
                        
                        
                    break;
                    
                


                case 2 :
                    System.out.println("Menu Shipment");
                    break;
                case 3 :
                    System.out.println("Menu About");
                    break;
                case 4 :
                    System.out.println("Terimakasih");
                    break;

                    default : System.out.println("Opsi Tersebut Tidak Tersedia");
            }
            System.out.println("");
        }while(pilih!=4);
            System.out.println("Sampai Jumpa");
    }
}

 

  • cIkan

 package Fishceanid;

public class cIkan {
    private String kd_ikan;
    private String nama_ikan;
    private String spesies_ikan;
    private String tipe_ikan;
    private int jumlah_ikan;
 
    cIkan(String kdik, String namik, String spik, String tipik, int jmikn) {
        kd_ikan=kdik; nama_ikan=namik; spesies_ikan=spik;
        tipe_ikan=tipik; jumlah_ikan= jmikn;
    }
    public void setkd_ikan(String kdik) {
        kd_ikan=kdik;
    }
    public void setnama_ikan(String namik) {
        nama_ikan=namik;
    }
    public void setspesies_ikan(String spik) {
        spesies_ikan=spik;
    }
    public void settipe_ikan(String tipik) {
        tipe_ikan=tipik;
    }
    public void setjumlah_ikan(int jumik) {
        jumlah_ikan=jumik;
    }
    public String getkd_ikan() {
        return kd_ikan;
    }
    public String getnama_ikan() {
        return nama_ikan;
    }
    public String getspesies_ikan() {
        return spesies_ikan;
    }
    public String gettipe_ikan() {
        return tipe_ikan;
    }
    public int getjumlah_ikan() {
        return jumlah_ikan;
    }
    public String toString() {
        return kd_ikan+"\t"+nama_ikan+"\t"+spesies_ikan+"\t"+tipe_ikan+"\t"+
    jumlah_ikan;
    }
}

  • cPenjual

package Fishceanid;

public class cPenjual {
    private String id_pjual;
    private String nama_pjual;
    private String kontak_pjual;
    private String alamat_pjual;
 
    cPenjual(String idpj, String npj, String kpj, String apj) {
        id_pjual=idpj; nama_pjual=npj; kontak_pjual=kpj;
    alamat_pjual=apj;
    }
    public void setid_pjual(String idpj) {
        id_pjual=idpj;
    }
    public void setnama_pjual(String npj) {
        nama_pjual=npj;
    }
    public void setkontak_pjual(String kpj) {
        kontak_pjual=kpj;
    }
    public void setalamat_pjual(String apj) {
        alamat_pjual=apj;
    }
    public String getid_pjual() {
        return id_pjual;
    }
    public String getnama_pjual() {
        return nama_pjual;
    }
    public String getkontak_pjual() {
        return kontak_pjual;
    }
    public String getalamat_pjual() {
        return alamat_pjual;
    }
    public String ToString() {
        return id_pjual+"/t"+nama_pjual+"/t"+kontak_pjual+"/t"+
    alamat_pjual;
    }
}


  • cToko

package Fishceanid;

public class cToko {
    public String kd_toko;
    public String nama_toko;
    public String suplai_toko;
    public String desk_toko;
    public String alamat_toko;

    cToko(String kdtk, String ntk, String stk, String desktk, String atk)
    {
        kd_toko=kdtk; nama_toko=ntk; suplai_toko=stk; desk_toko=desktk;  
        alamat_toko=atk;
    }
    public void setkd_toko(String kdtk) {
        kd_toko=kdtk;
    }
    public void setnama_toko(String ntk) {
        nama_toko=ntk;
    }
    public void setsuplai_toko(String stk) {
        suplai_toko=stk;
    }
    public void setdesk_toko(String desktk) {
        desk_toko=desktk;
    }
    public void setalamat_toko(String atk) {
        alamat_toko=atk;
    }
    public String getkd_toko() {
        return kd_toko;
    }
    public String getnama_toko() {
        return nama_toko;
    }
    public String getsuplai_toko() {
        return suplai_toko;
    }
    public String getdesk_toko() {
        return desk_toko;
    }
    public String getalamat_toko() {
        return alamat_toko;
    }
    public String ToString() {
        return kd_toko+"\t"+nama_toko+"/t"+suplai_toko+"/t"+desk_toko+"/t"+
    alamat_toko;
    }
}

 

  • cPenjualan

 
package Fishceanid;

public class cPenjualan {
   private String kode;
    private cToko tko;
    private cPenjual pjl;
    
    
    cPenjualan(String kd, cToko t,cPenjual p){
        kode=kd; tko=t; pjl=p;
        System.out.println("Object pembeli dibuat...");
    }
    public String ToString() {
        return kode+"\t"+tko.getnama_toko()+"\t"+pjl.getnama_pjual();
    }
}


Our team :

Fransiskus Ramaditya AN

Septian Aditya P

Galuh Widiana P


That's all, have a nice day :))

Tidak ada komentar:

Posting Komentar