PENEGENALAN OBJEK ORIENTED PADA VB.NET



Tujuan :
1.      Mahasiswa dapat menggunakan konsep pemrograman OO pada VB.net yaitu pembuatan class, method/fuction, serta properti.
2.      Mahasiswa dapat menggunakan konsep pemrograman OO pada VB.net yaitu menggunakan  inhertitance, multiple inhertitance, dan polimerfisme.


Latihan soal
Buatlah sebuah bform. Dalam aplikasi ini menggunakan konsep class dan method (function) sehingga memudahkan dalam pemrograman OO. Aplikasi ini digunakan untuk menghitung transaksi penjualan produk.
Source code:
Public Class market
    Public Kode As String = 5
    Public Nama As String = 10
    Public Satuan As Decimal
    Public Jumlah As Integer
    Public Uang As Decimal
    Public Property mKode() As String
        Get
            Return Kode
        End Get
        Set(ByVal value As String)
            Kode = value
        End Set
    End Property
    Public Property mNama() As String
        Get
            Return Nama
        End Get
        Set(ByVal value As String)
            Nama = value
        End Set
    End Property
    Public Property mSatuan() As Decimal
        Get
            Return Satuan
        End Get
        Set(ByVal value As Decimal)
            Satuan = value
        End Set
    End Property
    Public Property mJumlah() As Integer
        Get
            Return Jumlah
        End Get
        Set(ByVal value As Integer)
            Jumlah = value
        End Set
    End Property
    Public Function Harga(ByVal mSatuan As Decimal, ByVal mJumlah As Integer) As Double
        Return Satuan * Jumlah
    End Function
    Public Function Promo(ByVal Harga As Double) As Double
        If Harga >= 2000000 Then
            Return 0.06 * mSatuan * mJumlah
        ElseIf Harga >= 1500000 Then
            Return 0.05 * mSatuan * mJumlah
        ElseIf Harga >= 1000000 Then
            Return 0.03 * mSatuan * mJumlah
        ElseIf Harga >= 500000 Then
            Return 0.02 * mSatuan * mJumlah
        Else
            Return 0
        End If
    End Function
    Public Function Total(ByVal Harga As Double, ByVal Promo As Double) As Double
        Return Harga - Promo
    End Function
End Class

Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim objmarket As New market
        With objmarket
            .Kode = TextBox1.Text
            .Nama = TextBox2.Text
            .Satuan = TextBox3.Text
            .Jumlah = TextBox4.Text
            .Uang = TextBox5.Text
            Label11.Text = TextBox5.Text - Label10.Text
        End With
    End Sub
    Private Sub TextBox4_TextChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles TextBox4.TextChanged
        If TextBox3.Text * TextBox4.Text >= 2000000 Then
            Label9.Text = 0.06 * TextBox3.Text * TextBox4.Text
            Label10.Text = TextBox3.Text * TextBox4.Text - Label9.Text
        ElseIf TextBox3.Text * TextBox4.Text >= 1500000 Then
            Label9.Text = 0.05 * TextBox3.Text * TextBox4.Text
            Label10.Text = TextBox3.Text * TextBox4.Text - Label9.Text
        ElseIf TextBox3.Text * TextBox4.Text >= 1000000 Then
            Label9.Text = 0.03 * TextBox3.Text * TextBox4.Text
            Label10.Text = TextBox3.Text * TextBox4.Text - Label9.Text
        ElseIf TextBox3.Text * TextBox4.Text >= 500000 Then
            Label9.Text = 0.02 * TextBox3.Text * TextBox4.Text
            Label10.Text = TextBox3.Text * TextBox4.Text - Label9.Text
        Else
            Label9.Text = 0
            Label10.Text = TextBox3.Text * TextBox4.Text - Label9.Text
        End If
    End Sub
End Class


Tampilan

Tugas :
1.      Buatlah program kepegawaian untuk bebereapa perhitungan seperti PPH, total gaji, gaji bersih. Untuk perhitungan gaji sangat dipengaruhi oleh tunjangan istri dan anak serta status karyawan tersebut.
Ketentuan :
Jika status nikah maka tunjangan istri 250000 bila tidak 0
Jika memiliki anak maka tunjangan setiap anak = 200000 max anak 3. Tunjagan anak = 200000 * jumlah anak
Pph=5% dari gaji pokok
Total gaji = gaji pokok + tunjangan istri +tunjangan anak
Gaji bersih = total gaji – pph

Script
Public Class Hitung
    Public Nama As String
    Public TIstri As String
    Public Nikah As Integer
    Public TAnak As Integer
    Public TotalTAnak As Integer
    Public Hasil As Integer
    Public GPokok As Integer
    Public TGaji As Integer
    Public GBersih As Integer
    Public SBonus As Integer
    Public Function TunjanganIstri() As Integer
        If TIstri = "Nikah" Then
            Nikah = 250000
            Return Nikah
        Else
            Nikah = 0
            Return Nikah
        End If
    End Function
    Public Function TunjanganAnak() As Integer
        If TAnak < 3 Then
            TotalTAnak = TAnak * 200000
            Return TotalTAnak
        Else
            TotalTAnak = 3 * 200000
            Return TotalTAnak
        End If
    End Function
    Public Function PPH() As Integer
        Hasil = 0.05 * GPokok
        Return Hasil
    End Function
    Public Function TotalGaji() As Integer
        TGaji = GPokok + TunjanganIstri() + TunjanganAnak()
        Return TGaji
    End Function
    Public Function GajiBersih() As Integer
        GBersih = TGaji - Hasil
        Return GBersih
    End Function
    Public Function Bonus() As Integer
        SBonus = 0.5 * GPokok
        Return SBonus
    End Function
   
End Class

Public Class Kepegawaian

          
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Terserah As New Hitung
        With Terserah
            .Nama = TextBox1.Text
            .TIstri = ComboBox1.Text
            .TAnak = TextBox2.Text
            .GPokok = TextBox3.Text

            TextBox4.Text = .TunjanganIstri()
            TextBox5.Text = .TunjanganAnak()
            TextBox6.Text = .PPH()
            TextBox7.Text = .TotalGaji()
            TextBox8.Text = .GajiBersih()
            TextBox9.Text = .Bonus()

           

        End With
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Close()
    End Sub
End Class

Tampilan
2.      Buatlah program kepegawaian dengan mengacu pada latihan sebelumnya dimana untuk ketentuan sama dan tambahkan 0.5 dari gaji pokok dan gunakan sub untuk menyimpan setiap file pegawai tersebut dalam format.txt
script
    Public Sub SimpanData()
        Dim OutputFile As System.IO.StreamWriter
        OutputFile = System.IO.File.AppendText("kepegawaian.txt")
        OutputFile.WriteLine("Nama : " & Nama)
        OutputFile.WriteLine("Status : " & TIstri)
        OutputFile.WriteLine("Jumlah Anak : " & TAnak)
        OutputFile.WriteLine("Gaji Pokok : " & GPokok)
        OutputFile.WriteLine("Tunjangan Istri : " & TunjanganIstri())
        OutputFile.WriteLine("Tunjangan Anak : " & TunjanganAnak())
        OutputFile.WriteLine("PPH : " & PPH())
        OutputFile.WriteLine("Tota Gaji : " & TotalGaji())
        OutputFile.WriteLine("Gaji Bersih : " & GajiBersih())
        OutputFile.WriteLine("Bonus : " & Bonus())
        OutputFile.Close()

    End Sub

Public Class Kepegawaian


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Terserah As New Hitung
        With Terserah
            .Nama = TextBox1.Text
            .TIstri = ComboBox1.Text
            .TAnak = TextBox2.Text
            .GPokok = TextBox3.Text

            TextBox4.Text = .TunjanganIstri()
            TextBox5.Text = .TunjanganAnak()
            TextBox6.Text = .PPH()
            TextBox7.Text = .TotalGaji()
            TextBox8.Text = .GajiBersih()
            TextBox9.Text = .Bonus()

            'panggil sub rutin ambil data'
            .SimpanData()
            MessageBox.Show("data disimpan", "konfirmasi")

        End With
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Close()
    End Sub
End Class


Tampilan
Text Box: ROBY



3.      Buatlah program dengan konsep multiple inheritance dimana class induk memiliki anak kelas yaitu lebih dari 1 class. Tampilan aplikasi dealer mobil untuk pembayaran tunai.
Public Class Tunai
    Inherits Pembayaran
    Private cashBack As Long
    Private potongan As Long = 10000000

    Public Function kembalian() As Integer
        cashBack = HargaFlatForm() - potongan
        Return cashBack
    End Function

    Public Property mPotongan() As Long
        Get
            Return potongan
        End Get
        Set(ByVal value As Long)

        End Set
    End Property
End Class

Public Class Pembayaran
    Inherits Dealer
    Public jenisMobil, merek, jenisPembayaran As String
    Public volumeSilinder As Integer

    Public Function HargaFlatForm() As Integer
        If merek = "xenia x1 1.3" Then
            Return 140700000
        Else
            Return 135700000
        End If
    End Function
End Class

Public Class Kredit
    Inherits Pembayaran
    Private uangMuka, tenor As Long

    Public Property atenor() As Long
        Get
            Return tenor
        End Get
        Set(ByVal value As Long)
            tenor = value
        End Set
    End Property

    Public Property aUang() As Long
        Get
            Return uangMuka
        End Get
        Set(ByVal value As Long)
            uangMuka = value
        End Set
    End Property

    Public Function angsuran() As Integer
        Return (HargaFlatForm() - uangMuka) / tenor
    End Function

End Class
Public Class Dealer
    Public nama, alamat, debutir As String
    Public noKontrak As Integer
End Class

Public Class Form1

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim biodata As New Dealer
        With biodata
            .nama = TextBox1.Text
            .alamat = TextBox2.Text
            .noKontrak = TextBox3.Text
            .debutir = TextBox4.Text
        End With

        Dim harga As New Pembayaran
        With harga
            .merek = ComboBox1.Text
            .jenisMobil = ComboBox2.Text
            .volumeSilinder = TextBox6.Text
            .jenisPembayaran = ComboBox3.Text
        End With

        If harga.jenisPembayaran = "tunai" Then
            Dim tunai1 As New Tunai
            With tunai1
                TextBox5.Text = .HargaFlatForm()
                TextBox10.Text = .mPotongan()
                TextBox9.Text = .kembalian()
                TextBox7.Text = 0
                TextBox8.Text = 0
                TextBox11.Text = 0
            End With
        Else
            Dim kredit1 As New Kredit
            With kredit1
                TextBox5.Text = .HargaFlatForm()
                TextBox10.Text = 0
                TextBox9.Text = 0
                .aUang = TextBox7.Text
                .atenor = TextBox8.Text
                TextBox11.Text = .angsuran()
            End With
        End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Close()
    End Sub
End Class

Tampilan Tunai

Tampilan Kredit

0 Response to "PENEGENALAN OBJEK ORIENTED PADA VB.NET"

Post a Comment