Laman

Senin, 10 Agustus 2015

Program Grosir Lele - C++ (Abstract - Interface - Innerclass - Enkapsulasi)


Program Grosir Lele berikut saya posting untuk memenuhi tugas UAS Semester 4 mata kuliah OOP 2. Program terdiri dari beberapa class dengan masing-masing type OOP.

Kodingnya sebagai berikut :


#include <iostream>

using namespace std;

class rinci_interface
{
    void perkg();
};

class rinci : rinci_interface
{
    public :

    int hargaperkg;
    int kode;

    virtual void perkg()
    {
        if (kode == 1)
        {
            cout<<"Isi 12 ekor per KG"<<endl;
        }
        else if (kode == 2)
        {
            cout<<"Isi 8 ekor per KG"<<endl;
        }
        else if (kode == 3)
        {
            cout<<"Isi 5 ekor per KG"<<endl;
        }

    }

    class umurikan
    {
        public :

        void umur(int kode)
        {
            if (kode == 1)
            {
                cout<<"Umur 4 Bulan"<<endl;
            }
            else if (kode == 2)
            {
                cout<<"Umur 8 Bulan"<<endl;
            }
            else if (kode == 3)
            {
                cout<<"Umur 10 Bulan"<<endl;
            }
        }
    };
};

class total_abstract
{
    public :

    void totalh_abstract (int jumlahkg, int kode);
};

class totalh : total_abstract
{
    public :

    int totalhrg;

    virtual void totalh_abstract (int jumlahkg, int kode)
    {
        int hargaperkg = 0;

        if (kode == 1)
        {
            hargaperkg = 6000;
        }
        else if (kode == 2)
        {
            hargaperkg = 10000;
        }
        else if (kode == 3)
        {
            hargaperkg = 12000;
        }

        totalhrg = hargaperkg * jumlahkg;
    }
};

class diskon_enkapsulasi
{
    public :

    int jdiskon;

    void Setdisk(int value)
    {
        if (value < 500000)
        {
            value = value * 5 / 100;
        }

        else if (value >= 500000 && value < 1000000)
        {
            value = value * 10 / 100;
        }

        else if (value >= 1000000 && value < 5000000)
        {
            value = value * 15 / 100;
        }

        else if (value >= 5000000)
        {
            value = value * 20 / 100;
        }

        jdiskon = value;
    }

    int Getdisk()
    {
        return jdiskon;
    }
};

int main()
{
    rinci rc;
    int berat;

    cout<<"Penjualan Ikan Lele Grosir"<<endl;
    cout<<"Masukkan kode 1, 2 atau 3 : ";
    cin>>rc.kode;
    cout<<"Masukkan Berat Pesanan : ";
    cin>>berat;
    cout<<rc.kode;

    rc.perkg ();

    rinci::umurikan ui = rinci::umurikan();
    ui.umur (rc.kode);

    totalh th;
    th.totalh_abstract(berat,rc.kode);

    cout<<"Harga Awal : Rp "<<th.totalhrg<<endl;

    diskon_enkapsulasi dsk;
    dsk.Setdisk(th.totalhrg);

    cout<<"Dapat Diskon : Rp "<<dsk.Getdisk()<<endl;
    cout<<"Harga Akhir : Rp "<<th.totalhrg - dsk.Getdisk()<<endl;

    return 0;
}
Program memang sangat sederhana, namun terdiri dari berbagai teknik pemrograman dalam object oriented programing. Mohon koreksi.

Gambarnya sebagai berikut :

contoh abstract oop, contoh enkapsulasi, contoh inner class, contoh interface, enkapsulasi oop 2, oo, oop innerclass, oop2

Program Grosir Lele - Java (Abstract - Interface - Innerclass - Enkapsulasi)

Program Grosir Lele berikut saya posting untuk memenuhi tugas UAS Semester 4 mata kuliah OOP 2. Program terdiri dari beberapa class dengan masing-masing type OOP. Kodingnya sebagai berikut :

1. Program Utama
 package juallele;
import java.util.Scanner;

public class juallele {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
      
        rinci rc = new rinci ();
        Scanner input = new Scanner(System.in);
      
        System.out.println ("Penjualan Ikan Lele Grosir");
        System.out.print ("Masukkan kode 1, 2 atau 3 : ");
        rc.kode = input.nextInt();
        System.out.print ("Masukkan Berat Pesanan : ");
        int berat = input.nextInt();

        rc.perkg ();

        totalh th = new totalh ();
        th.totalh_abstract (berat,rc.kode);

        System.out.println ("Harga Awal : Rp "+th.totalhrg);

        diskon_enkapsulasi dsk = new diskon_enkapsulasi ();
        dsk.Setdisk(th.totalhrg);

        System.out.println ("Dapat Diskon : Rp "+dsk.Getdisk());
        System.out.println ("Harga Akhir : Rp "+(th.totalhrg - dsk.Getdisk()));
    }

}
2. Abstract
 package juallele;

public abstract class total_abstract {

    public abstract void totalh_abstract (int jumlahkg, int hargakg);

}
3. Total Harga yang tersambung dengan Abstract
 package juallele;

public class totalh extends total_abstract {

    public int totalhrg;

    @Override
    public void totalh_abstract (int jumlahkg, int kode)
    {  
        int hargaperkg = 0;

        if (kode == 1)
        {
            hargaperkg = 6000;
        }
        else if (kode == 2)
        {
            hargaperkg = 10000;
        }
        else if (kode == 3)
        {
            hargaperkg = 12000;
        }

        totalhrg = hargaperkg * jumlahkg;
    }
}
4. Interface
 package juallele;

public interface rinci_interfaces {

    void perkg();
  
}
5. Rinci yang tersambung dengan Interface
 package juallele;

public class rinci implements rinci_interfaces {

    public int hargaperkg;
    public int kode;
  
    @Override
    public void perkg()
    {
        if (kode == 1)
        {
            System.out.println ("Isi 12 ekor per KG");
        }
        else if (kode == 2)
        {
            System.out.println ("Isi 8 ekor per KG");
        }
        else if (kode == 3)
        {
            System.out.println ("Isi 5 ekor per KG");
        }
      
        umurikan ui = new umurikan();
        ui.umur(kode);
    }
  
    public class umurikan
    {
        public void umur(int kode)
        {
            if (kode == 1)
            {
                System.out.println ("Umur 4 Bulan");
            }
            else if (kode == 2)
            {
                System.out.println ("Umur 8 Bulan");
            }
            else if (kode == 3)
            {
                System.out.println ("Umur 10 Bulan");
            }
        }
    }

}
6. Enkapsulasi (Diskon)
 package juallele;

public class diskon_enkapsulasi {

    public int jdiskon;

    public void Setdisk(int value)
    {
        if (value < 500000)
        {
            value = value * 5 / 100;
        }

        else if (value >= 500000 && value < 1000000)
        {
            value = value * 10 / 100;
        }

        else if (value >= 1000000 && value < 5000000)
        {
            value = value * 15 / 100;
        }

        else if (value >= 5000000)
        {
            value = value * 20 / 100;
        }

        jdiskon = value;
    }
  
    public int Getdisk()
    {
        return (jdiskon);
    }

}
Program memang sangat sederhana, namun terdiri dari berbagai teknik pemrograman dalam object oriented programing. Mohon koreksi.

Gambarnya sebagai berikut :


Program Grosir Lele - Csharp (Abstract - Interface - Innerclass - Enkapsulasi)

Program Grosir Lele berikut saya posting untuk memenuhi tugas UAS Semester 4 mata kuliah OOP 2. Program terdiri dari beberapa class dengan masing-masing type OOP. Kodingnya sebagai berikut :

1. Program Utama
using System;

namespace OOP2UASjuallele
{
    class MainClass
    {
        public static void Main (string[] args)
        {
            rinci rc = new rinci ();

            Console.WriteLine ("Penjualan Ikan Lele Grosir");
            Console.Write ("Masukkan kode 1, 2 atau 3 : ");
            rc.kode = Convert.ToInt32 (Console.ReadLine ());
            Console.Write ("Masukkan Berat Pesanan : ");
            int berat = Convert.ToInt32 (Console.ReadLine ());

            rc.perkg ();

            rinci.umurikan ru = new rinci.umurikan ();
            ru.umur (rc.kode);

            totalh th = new totalh ();
            th.totalh_abstract (berat,rc.kode);

            Console.WriteLine ("Harga Awal : Rp "+th.totalhrg);

            diskon_enkapsulasi dsk = new diskon_enkapsulasi ();
            dsk.disk = th.totalhrg;

            Console.WriteLine ("Dapat Diskon : Rp "+dsk.jdiskon);
            Console.WriteLine ("Harga Akhir : Rp "+(th.totalhrg - dsk.jdiskon));
        }
    }
}
2. Abstract
using System;

namespace OOP2UASjuallele
{
    public abstract class total_abstract
    {
        public abstract void totalh_abstract (int jumlahkg, int hargakg);
        
    }
}
3. Total Harga yang tersambung dengan Abstract
using System;

namespace OOP2UASjuallele
{
    public class totalh : total_abstract
    {
        public int totalhrg;

        public override void totalh_abstract (int jumlahkg, int kode)
        {
            int hargaperkg = 0;

            if (kode == 1)
            {
                hargaperkg = 6000;
            }
            else if (kode == 2)
            {
                hargaperkg = 10000;
            }
            else if (kode == 3)
            {
                hargaperkg = 12000;
            }

            totalhrg = hargaperkg * jumlahkg;
        }
    }
}

4. Interface

using System;

namespace OOP2UASjuallele
{
    public interface rinci_interface
    {
        void perkg();
    }
}

5. Rinci yang tersambung dengan Interface
using System;

namespace OOP2UASjuallele
{
    public class rinci : rinci_interface
    {
        public int hargaperkg;
        public int kode;

        public virtual void perkg()
        {
            if (kode == 1)
            {
                Console.WriteLine ("Isi 12 ekor per KG");
            }
            else if (kode == 2)
            {
                Console.WriteLine ("Isi 8 ekor per KG");
            }
            else if (kode == 3)
            {
                Console.WriteLine ("Isi 5 ekor per KG");
            }
        }

        public class umurikan
        {
            public virtual void umur(int kode)
            {
                if (kode == 1)
                {
                    Console.WriteLine ("Umur 4 Bulan");
                }
                else if (kode == 2)
                {
                    Console.WriteLine ("Umur 8 Bulan");
                }
                else if (kode == 3)
                {
                    Console.WriteLine ("Umur 10 Bulan");
                }
            }
        }

    }
}

6. Enkapsulasi (Diskon)
using System;

namespace OOP2UASjuallele
{
    public class diskon_enkapsulasi
    {
        public int jdiskon;

        public int disk {
            set {

                if (value < 500000)
                {
                    value = value * 5 / 100;
                }

                else if (value >= 500000 && value < 1000000)
                {
                    value = value * 10 / 100;
                }

                else if (value >= 1000000 && value < 5000000)
                {
                    value = value * 15 / 100;
                }

                else if (value >= 5000000)
                {
                    value = value * 20 / 100;
                }

                jdiskon = value;
            }

            get {
                return (jdiskon);
            }
        }
    }
}

Program memang sangat sederhana, namun terdiri dari berbagai teknik pemrograman dalam object oriented programing. Mohon koreksi.

Gambarnya sebagai berikut :

oop2, oo, contoh inner class, contoh abstract oop, contoh interface, contoh enkapsulasi, enkapsulasi oop 2, oop innerclass