form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Chapter3
{
public partial class Form1 : Form
{
Akun akun1 = new Akun(20000, "hiya");
public Form1()
{
InitializeComponent();
lblSaldo.Text = akun1.Saldo.ToString();
}
private void TarikSaldo(int total)
{
akun1.Tarik(total);
lblSaldo.Text = akun1.Saldo.ToString();
}
private void SetorSaldo(int total)
{
akun1.Setor(total);
lblSaldo.Text = akun1.Saldo.ToString();
}
private void btnLanjut_Click(object sender, EventArgs e)
{
if(akun1.PasswordTervalidasi(tbPassword.Text))
{
if (rbSetor.Checked)
SetorSaldo(int.Parse(tbUang.Text));
else if (rbTarik.Checked)
TarikSaldo(int.Parse(tbUang.Text));
}
else
{
MessageBox.Show("Password salah");
}
}
}
}
Akun.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Chapter3
{
public class Akun
{
private const int maxSaldo = 2000000;
private int _saldo;
protected string password;
public int Saldo
{
get
{
return _saldo;
}
set
{
if (value < 0)
throw new InvalidOperationException("Saldo tidak bisa kurang dari 0 rupiah");
else if (value > maxSaldo)
throw new InvalidOperationException("Saldo tidak boleh melebihi 2000000 rupiah");
else
_saldo = value;
}
}
public Akun(int saldo, string password)
{
_saldo = saldo;
this.password = password;
}
public void Setor(int jumlah)
{
Saldo += jumlah;
}
public void Tarik(int jumlah)
{
Saldo -= jumlah;
}
public bool PasswordTervalidasi(string password)
{
if (this.password == password)
return true;
else
return false;
}
}
}
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}