Program penghitungan sederhana dengan C#

Bookmark and Share
Berikut tutorial membuat perhitungan sederhana dengan C# oleh teman kita http://octtenz.wordpress.com
Membuat Aplikasi Sederhana dengan C#-1
Kemudian pada bagian MainForm.cs ketikkan kode berikut ( atau copy paste sajalah ;) ):
001/*
002 * Created by SharpDevelop 2.2.1.
003 * User: S.P Widianto
004 * Date: 3/4/2010
005 * Time: 5:56 PM
006 * For : Octtenz.wordpress.com
007 *
008 * To change this template use Tools | Options | Coding | Edit Standard Headers.
009 */
010 
011using System;
012using System.Collections.Generic;
013using System.Drawing;
014using System.Data;
015using System.Windows.Forms;
016 
017namespace saving
018{
019 /// <summary>
020 /// Description of MainForm.
021 /// </summary>
022 public partial class MainForm : Form
023 {
024 // Bunga dapat ditambahkan secara harian atau bulanan
025 enum Compound {
026 Daily,
027 Monthly,
028 Quarterly,
029 SemiAnnually,
030 Annually
031 }
032 
033 public MainForm()
034 {
035 //
036 // The InitializeComponent() call is required for Windows Forms designer support.
037 //
038 InitializeComponent();
039 
040 cmbCompFreq.Items.Add(Compound.Daily);
041 cmbCompFreq.Items.Add(Compound.Monthly);
042 cmbCompFreq.Items.Add(Compound.Quarterly);
043 cmbCompFreq.Items.Add(Compound.SemiAnnually);
044 cmbCompFreq.Items.Add(Compound.Annually);
045 cmbCompFreq.SelectedItem = cmbCompFreq.Items[0];
046 //
047 // TODO: Add constructor code after the InitializeComponent() call.
048 //
049 }
050 
051 private void BtnCalculateClick(object sender, System.EventArgs e)
052 {
053 decLabelMax = 10000000000M;
054 
055 // memasukkan nilai yang diperlukan
056 double jumlahAwal = (double) nupJumlahAwal.Value;
057 double rate = (double) nupInterestRate.Value;
058 int years = (int) nupYears.Value;
059 Compound calcFrequency = (Compound) cmbCompFreq.SelectedItem;
060 
061 // assign total value ke totalValue
062 decimal totalValue = 0;
063 
064 // mengubah suku bunga ke desimal
065 rate = rate / 100;
066 int periods = 0;
067 
068 // Menghitung saving dengan rumus : p=c(1+r/n)^nt
069 switch ( calcFrequency ) {
070 case Compound.Daily:
071 // Bunga harian
072 double dailyRate = rate / 365;
073 // Jumlah hari
074 periods = years * 365;
075 // calculate savings
076 jumlahAwal = jumlahAwal * Math.Pow((1 + dailyRate),(double)periods);
077 break;
078 case Compound.Monthly:
079 // Bunga per bulan
080 double monthlyRate = rate / 12;
081 // Jumlah bulan
082 periods = years * 12;
083 // calculate savings
084 jumlahAwal = jumlahAwal * Math.Pow((1 + monthlyRate),(double)periods);
085 break;
086 case Compound.Quarterly:
087 // Bunga per empat bulan
088 double quarterlyRate = rate / 4;
089 // how many quarters
090 periods = years * 4;
091 // calculate savings
092 jumlahAwal = jumlahAwal * Math.Pow((1 + quarterlyRate),(double)periods);
093 break;
094 case Compound.SemiAnnually:
095 // semi-annual interest
096 double semiAnnualRate = rate / 2;
097 // how many periods
098 periods = years * 2;
099 jumlahAwal = jumlahAwal * Math.Pow((1 + semiAnnualRate),(double)periods);
100 break;
101 case Compound.Annually:
102 // interest per year
103 double annualRate = rate;
104 // how many years
105 periods = years;
106 // calculate savings
107 jumlahAwal = jumlahAwal * Math.Pow((1 + annualRate),(double)periods);
108 break;
109 default:
110 // This code should never execute!
111 MessageBox.Show(this, "Ada Error");
112 break;
113 }
114 totalValue = (decimal) jumlahAwal;
115 
116 // Menampilkan hasil perhitungan
117 if ( totalValue <= decLabelMax ) {
118 //...format the label to display a currency value
119 lblTotalTabungan.Text = String.Format("Rp. {0:###,###.##}", totalValue);
120 
121 }
122 else {
123 MessageBox.Show("Jumlah melebihi nilai maximum");
124 }
125 }
126 }
127}
Apabila tidak ada masalah, maka apabila di run akan muncul tampilan :
Membuat Aplikasi Sederhana dengan C#-3
Semoga bermanfaat…

{ 1 komentar... Views All / Post Comment! }

Unknown mengatakan...

ini sama di visual bassic . net 2012 sama ngga coding nya?

Posting Komentar