INHERITANCE (Class Pegawai, Class Manager, Class Karyawan)
Nama : Wahyu Nurfian
NIM : 12.12.0062
Kelas : SI 12 A
SEKOLAH TINGGI MANAJEMEN INFORMATIKA
DAN KOMPUTER
AMIKOM PURWOKERTO
JL.LET.JEND.POL SUMARTO PURWOKERTO
2013
Class
Utama
using System;
using
System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Praktikum3
{
class Program
{
static void Main(string[]
args)
{
{
//memanggil
Class Pegawai
Pegawai
pg1 = new Pegawai(2000000,
"Nurvina Dwi Andari");
pg1.pegawai();
pg1.bayaran();
//memanggil
Class Manager
Manager
mn1 = new Manager(2000000,
"Muhammad Ficky Budiarto",
4200000);
mn1.manager();
mn1.bayaran();
//memanggil
class Karyawan
Karyawan
kry1 = new Karyawan("Stefan William", 2000000, 4200000, 4,
10000);
kry1.karyawan();
kry1.bayaran();
Console.Read();
}
}
}
}
Class
Pegawai
using System;
using
System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Praktikum3
{
class Pegawai
{
//Field
protected
int gajipokok;
protected
string nama;
//constructor
public
Pegawai(int gajipokok, string
nama)
{
this.gajipokok
= gajipokok;
this.nama
= nama;
}
//Method
Bayaran
public void bayaran()
{
Console.WriteLine("Nama \t\t: {0} \nGaji Pokok\t: Rp {1}",
nama,
Gajipokok);
}
//Method
Pegawai
public void pegawai()
{
Console.WriteLine("---------------------------------------------");
Console.WriteLine("
Menampilkan Class Pegawai\n");
Console.WriteLine("----------------------------------------------");
Console.WriteLine("Nama Pegawai \t: {0}\n", nama);
}
}
}
Class
Manager
using System;
using
System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Praktikum3
{
class Manager:Pegawai
{
//field
protected
int tunjangan;
//constructor
public
Manager(int gajipokok, string
nama, int tunjangan)
:base
(gajipokok,nama)
{
this.tunjangan
= tunjangan;
}
//Method
bayar
public new void bayaran()
{
base.bayaran();
Console.WriteLine("Tunjangan \t: Rp {0}",tunjangan);
int
hasil = gajipokok + tunjangan;
Console.WriteLine("Total Gaji \t: Rp {0}", hasil);
}
//Method
Pegawai
public void manager()
{
Console.WriteLine("\n\n");
Console.WriteLine("---------------------------------------------");
Console.WriteLine("
Menampilkan Class Manager\n");
Console.WriteLine("---------------------------------------------");
Console.WriteLine("Nama Manager \t: {0}\n", nama);
}
}
}
Class
Karyawan
using System;
using
System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Praktikum3
{
class Karyawan:Manager
{
//field
int
jamLembur, upahLembur;
//Contructor
public
Karyawan(string nama, int
gajipokok, int tunjangan, int jamLembur, int
upahLembur)
: base(gajipokok,nama,tunjangan)
{
this.jamLembur
= jamLembur;
this.upahLembur
= upahLembur;
}
public new void bayaran()
{
base.bayaran();
int
total_gaji = gajipokok + tunjangan;
int
total_upah_lembur = jamLembur * upahLembur;
int
total_pendapatan = total_upah_lembur + total_gaji;
Console.WriteLine("Jam Lembur\t: {0} Jam\nUpah Lembur\t: Rp {1}\nTotal
Upah Lembur\t: Rp {2}\nTotal Pendapatan\t: Rp {3}", jamLembur,
upahLembur,total_upah_lembur, total_pendapatan);
}
//Method
Karyawan
public void karyawan()
{
Console.WriteLine("\n\n");
Console.WriteLine("----------------------------------------------");
Console.WriteLine("
Menampilkan Class Karyawan\n");
Console.WriteLine("----------------------------------------------");
Console.WriteLine("Nama Karyawan\t: {0}\n", nama);
}
}
}
Hasil
Outputnya :
Tidak ada komentar:
Posting Komentar