Facebook
From rozaq, 4 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 232
  1. ITransaksi.cs
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace Chapter3
  9. {
  10.     interface ITransaksi
  11.     {
  12.         void Setor(int jumlah);
  13.         void Tarik(int jumlah);
  14.     }
  15. }
  16.  
  17. IIdentitas.cs
  18. using System;
  19. using System.Collections.Generic;
  20. using System.Linq;
  21. using System.Text;
  22. using System.Threading.Tasks;
  23.  
  24. namespace Chapter3
  25. {
  26.     interface IIdentitas
  27.     {
  28.         int Id { get; set; }
  29.         string Password { get; set; }
  30.         int Saldo { get; set; }
  31.     }
  32. }
  33.  
  34. AkunPremium.cs
  35. using System;
  36. using System.Collections.Generic;
  37. using System.Linq;
  38. using System.Text;
  39. using System.Threading.Tasks;
  40.  
  41. namespace Chapter3
  42. {
  43.     public class AkunPremium : Akun
  44.     {
  45.         public AkunPremium(int id,int saldo, string password) : base(id,saldo,password)
  46.         {
  47.             Id = id;
  48.            Password = password;
  49.             Saldo = saldo;
  50.         }
  51.         public new int Saldo
  52.         {
  53.             get
  54.             {
  55.                 return _saldo;
  56.             }
  57.             set
  58.             {
  59.                 if (value < 0)
  60.                     throw new InvalidOperationException("Saldo tidak bisa kurang dari 0 rupiah");
  61.                 else
  62.                     _saldo = value;
  63.             }
  64.         }
  65.         public override void Setor(int jumlah)
  66.         {
  67.             Saldo += jumlah+500;
  68.         }
  69.  
  70.         public override void Tarik(int jumlah)
  71.         {
  72.             Saldo -= jumlah+500;
  73.         }
  74.  
  75.  
  76.     }
  77. }
  78.  
  79. Akun.cs
  80. using System;
  81. using System.Collections.Generic;
  82. using System.Linq;
  83. using System.Text;
  84. using System.Threading.Tasks;
  85.  
  86. namespace Chapter3
  87. {
  88.     public class Akun:IIdentitas,ITransaksi
  89.     {
  90.         private const int maxSaldo = 2000000;
  91.         protected int _saldo;
  92.         protected string password;
  93.        
  94.  
  95.        public int Id { get; set; }
  96.         public string Password { get { return password; }
  97.             set { if (value.Length > 8)
  98.                 {
  99.                     password = value;
  100.                 }
  101.  
  102.                 else
  103.                 {
  104.                     throw new InvalidOperationException("Password harus lebih dari 8 karakter");
  105.                 }
  106.                    
  107.  
  108.                         }
  109.         }
  110.         public int Saldo
  111.         {
  112.             get
  113.             {
  114.                 return _saldo;
  115.             }
  116.             set
  117.             {
  118.                 if (value < 0)
  119.                     throw new InvalidOperationException("Saldo tidak bisa kurang dari 0 rupiah");
  120.                 else if (value > maxSaldo)
  121.                     throw new InvalidOperationException("Saldo tidak boleh melebihi 2000000 rupiah");
  122.                 else
  123.                     _saldo = value;
  124.             }
  125.         }
  126.  
  127.         public Akun(int id,int saldo, string password)
  128.         {
  129.             Id = id;
  130.             _saldo = saldo;
  131.             Password = password;
  132.         }
  133.  
  134.         public virtual void Setor(int jumlah)
  135.         {
  136.             Saldo += jumlah;
  137.         }
  138.  
  139.         public virtual void Tarik(int jumlah)
  140.         {
  141.             Saldo -= jumlah;
  142.         }
  143.  
  144.         public bool PasswordTervalidasi(string password)
  145.         {
  146.             if (this.password == password)
  147.                 return true;
  148.             else
  149.                 return false;
  150.         }
  151.     }
  152. }
  153.  
  154.  
  155.