Calculator App dan Currency Converter App
Tugas - 3
Calculator App
Menggunakan .NET, aplikasi ini merupakan salah satu contoh aplikasi kalkulator sederhana, dimana operasi matematika yang tersedia yaitu penjumlahan, pengurangan, perkalian, dan pembagian.
Membuat project dengan windows form C#
Inisisasi Project dengan membuat project baru menggunakan template Windows Forms App
Pembuatan template
Berikut merupakan tampilan aplikasi yang sudah di design dan akan tampil nantinya ketika aplikasi dijalankan.
Pembuatan Kode
Berikut adalah source code dari aplikasi yang dibuat.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 Calculator | |
{ | |
public partial class Form1 : Form | |
{ | |
public Form1() | |
{ | |
InitializeComponent(); | |
} | |
private void Form1_Load(object sender, EventArgs e) | |
{ | |
textBox1.Clear(); | |
textBox2.Clear(); | |
label4.Text = ""; | |
} | |
private void button1_Click(object sender, EventArgs e) | |
{ | |
if (string.IsNullOrEmpty(textBox1.Text) || string.IsNullOrEmpty(textBox2.Text)) | |
{ | |
MessageBox.Show("Angka 1 dan Angka 2 tidak boleh kosong!"); | |
} | |
else | |
{ | |
int a, b, c; | |
a = int.Parse(this.textBox1.Text); | |
b = int.Parse(this.textBox2.Text); | |
c = a + b; | |
this.label4.Text = c.ToString(); | |
} | |
} | |
private void button2_Click(object sender, EventArgs e) | |
{ | |
if (string.IsNullOrEmpty(textBox1.Text) || string.IsNullOrEmpty(textBox2.Text)) | |
{ | |
MessageBox.Show("Angka 1 dan Angka 2 tidak boleh kosong!"); | |
} | |
else | |
{ | |
int a, b, c; | |
a = int.Parse(this.textBox1.Text); | |
b = int.Parse(this.textBox2.Text); | |
c = a - b; | |
this.label4.Text = c.ToString(); | |
} | |
} | |
private void button3_Click(object sender, EventArgs e) | |
{ | |
if (string.IsNullOrEmpty(textBox1.Text) || string.IsNullOrEmpty(textBox2.Text)) | |
{ | |
MessageBox.Show("Angka 1 dan Angka 2 tidak boleh kosong!"); | |
} | |
else | |
{ | |
int a, b, c; | |
a = int.Parse(this.textBox1.Text); | |
b = int.Parse(this.textBox2.Text); | |
c = a * b; | |
this.label4.Text = c.ToString(); | |
} | |
} | |
private void button4_Click(object sender, EventArgs e) | |
{ | |
if (string.IsNullOrEmpty(textBox1.Text) || string.IsNullOrEmpty(textBox2.Text)) | |
{ | |
MessageBox.Show("Angka 1 dan Angka 2 tidak boleh kosong!"); | |
} | |
else if (this.textBox2.Text == "0") | |
{ | |
MessageBox.Show("Undefined"); | |
} | |
else | |
{ | |
int a, b, c; | |
a = int.Parse(this.textBox1.Text); | |
b = int.Parse(this.textBox2.Text); | |
c = a / b; | |
this.label4.Text = c.ToString(); | |
} | |
} | |
private void button5_Click(object sender, EventArgs e) | |
{ | |
textBox1.Clear(); | |
textBox2.Clear(); | |
label4.Text = ""; | |
} | |
} | |
} |
Berikut adalah demo aplikasi setelah selesai dibuat
Currency Converter
Menggunakan .NET, aplikasi ini merupakan salah satu contoh aplikasi currency coverter sederhana, dimana data yang digunakan menggunakan API dari exchangeratesapi.
Membuat project dengan windows form C#
Inisisasi Project dengan membuat project baru menggunakan template Windows Forms App
Pembuatan template
Berikut merupakan tampilan aplikasi yang sudah di design dan akan tampil nantinya ketika aplikasi dijalankan.
Pembuatan Kode
Berikut adalah source code dari aplikasi yang dibuat.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Net; | |
using Newtonsoft.Json.Linq; | |
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 CurrencyConverter | |
{ | |
public partial class Form1 : Form | |
{ | |
public Form1() | |
{ | |
InitializeComponent(); | |
} | |
private string[] getCurrencyTags() | |
{ | |
return new string[] { "EUR", "USD", "JPY", "IDR", "AUD", "CAD", "SGD", "PHP", "MYR", "CNY" }; | |
} | |
private void Form1_Load(object sender, EventArgs e) | |
{ | |
comboBox1.Items.AddRange(getCurrencyTags()); | |
comboBox2.Items.AddRange(getCurrencyTags()); | |
comboBox1.SelectedItem = "EUR"; | |
comboBox2.SelectedItem = "USD"; | |
} | |
private void numericUpDown1_ValueChanged(object sender, EventArgs e) | |
{ | |
} | |
private void textBox1_TextChanged(object sender, EventArgs e) | |
{ | |
} | |
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) | |
{ | |
} | |
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e) | |
{ | |
} | |
private void button1_Click(object sender, EventArgs e) | |
{ | |
string url = string.Format("https://api.exchangeratesapi.io/latest?base={0}&symbols={1}", comboBox1.SelectedItem, comboBox2.SelectedItem); | |
dynamic res = JObject.Parse(new WebClient().DownloadString(url)); | |
float rate = (float)res.rates[comboBox2.SelectedItem]; | |
textBox1.Text = ((float)numericUpDown1.Value * rate).ToString("0.00"); | |
} | |
} | |
} |
Betikut adalah demo aplikasi setelah selesai dibuat
Comments
Post a Comment