Kalkulator dan Currency Converter (Tugas 3)

 Langkah - langkah

  1. Kalkulator
  • Create Project dan memilih jenis windows form application dan akan keluar workspace seperti ini


  • terdapat toolbox dan properties yang bisa membantu design kalkulator yang nanti dibuat



  • toolbox berfungsi sebagai elemen atau shape-shape yang bisa dimasuki dalam form
  • dan properties berfungsi untuk mengubah nama, dll dari elemen yang dimasuki dalam form 
  • buat form seperti ini

  • input 1,2, hasil merupakan sebuah label
  • untuk input angka merupakan sebuah textbox
  • dan untuk tombol operator menggunakan button
  • kodingannya :
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 kalkulator
                        {
                              public partial class Form1 : Form
                                {
                                      public Form1()
                                        {
                                              InitializeComponent();
                                            }

                                                private void label1_Click(object sender, EventArgs e)
                                                  {

                                                      }
                                                        //PLUS
                                                          private void button1_Click(object sender, EventArgs e)
                                                            {
                                                                  if (string.IsNullOrEmpty(textBox1.Text) || string.IsNullOrEmpty(textBox2.Text))
                                                                    {
                                                                          MessageBox.Show("Input 1 or 2 harus diisi");
                                                                        }
                                                                          else
                                                                            {
                                                                                  int a, b, c;
                                                                                    a = int.Parse(this.textBox1.Text);
                                                                                      b = int.Parse(this.textBox2.Text);
                                                                                        c = a + b;
                                                                                          this.lblhasil.Text = c.ToString();
                                                                                        }
                                                                                      }
                                                                                        //MINUS
                                                                                          private void button3_Click(object sender, EventArgs e)
                                                                                            {
                                                                                                  if (string.IsNullOrEmpty(textBox1.Text) || string.IsNullOrEmpty(textBox2.Text))
                                                                                                    {
                                                                                                          MessageBox.Show("Input 1 or 2 harus diisi");
                                                                                                        }
                                                                                                          else
                                                                                                            {
                                                                                                                  int a, b, c;
                                                                                                                    a = int.Parse(this.textBox1.Text);
                                                                                                                      b = int.Parse(this.textBox2.Text);
                                                                                                                        c = a - b;
                                                                                                                          this.lblhasil.Text = c.ToString();
                                                                                                                        }
                                                                                                                      }
                                                                                                                        //DIVIDE
                                                                                                                          private void button4_Click(object sender, EventArgs e)
                                                                                                                            {
                                                                                                                                  if (string.IsNullOrEmpty(textBox1.Text) || string.IsNullOrEmpty(textBox2.Text))
                                                                                                                                    {
                                                                                                                                          MessageBox.Show("Input 1 or 2 harus diisi");
                                                                                                                                        }
                                                                                                                                          else
                                                                                                                                            {
                                                                                                                                                  int a, b, c;
                                                                                                                                                    a = int.Parse(this.textBox1.Text);
                                                                                                                                                      b = int.Parse(this.textBox2.Text);
                                                                                                                                                        c = a / b;
                                                                                                                                                          this.lblhasil.Text = c.ToString();
                                                                                                                                                        }
                                                                                                                                                      }

                                                                                                                                                          private void textBox2_TextChanged(object sender, EventArgs e)
                                                                                                                                                            {

                                                                                                                                                                }

                                                                                                                                                                    private void label5_Click(object sender, EventArgs e)
                                                                                                                                                                      {

                                                                                                                                                                          }

                                                                                                                                                                              private void Form1_Load(object sender, EventArgs e)
                                                                                                                                                                                {
                                                                                                                                                                                      textBox1.Clear();
                                                                                                                                                                                        textBox2.Clear();
                                                                                                                                                                                          lblhasil.Text = "";
                                                                                                                                                                                        }
                                                                                                                                                                                          //MULTIPLY
                                                                                                                                                                                            private void button2_Click(object sender, EventArgs e)
                                                                                                                                                                                              {
                                                                                                                                                                                                    if (string.IsNullOrEmpty(textBox1.Text) || string.IsNullOrEmpty(textBox2.Text))
                                                                                                                                                                                                      {
                                                                                                                                                                                                            MessageBox.Show("Input 1 or 2 harus diisi");
                                                                                                                                                                                                          }
                                                                                                                                                                                                            else
                                                                                                                                                                                                              {
                                                                                                                                                                                                                    int a, b, c;
                                                                                                                                                                                                                      a = int.Parse(this.textBox1.Text);
                                                                                                                                                                                                                        b = int.Parse(this.textBox2.Text);
                                                                                                                                                                                                                          c = a * b;
                                                                                                                                                                                                                            this.lblhasil.Text = c.ToString();
                                                                                                                                                                                                                          }
                                                                                                                                                                                                                            
                                                                                                                                                                                                                          }

                                                                                                                                                                                                                              private void button5_Click(object sender, EventArgs e)
                                                                                                                                                                                                                                {
                                                                                                                                                                                                                                      textBox1.Clear();
                                                                                                                                                                                                                                        textBox2.Clear();
                                                                                                                                                                                                                                          lblhasil.Text = "";
                                                                                                                                                                                                                                        }
                                                                                                                                                                                                                                      }
                                                                                                                                                                                                                                    }
                                                                                                                                                                                                                                    • contoh dijalankan
                                                                                                                                                                                                                                    2. Currency Converter

                                                                                                                                                                                                                                    langkah yang dilakukan kurang lebih sama seperti kalkulator yang membedakan dalam kodingannya

                                                                                                                                                                                                                                    codingan : 

                                                                                                                                                                                                                                    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 currency_converter
                                                                                                                                                                                                                                    {
                                                                                                                                                                                                                                        public partial class Form1 : Form
                                                                                                                                                                                                                                        {
                                                                                                                                                                                                                                            public Form1()
                                                                                                                                                                                                                                            {
                                                                                                                                                                                                                                                InitializeComponent();
                                                                                                                                                                                                                                            }

                                                                                                                                                                                                                                            private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
                                                                                                                                                                                                                                            {

                                                                                                                                                                                                                                            }

                                                                                                                                                                                                                                            private void textBox1_TextChanged(object sender, EventArgs e)
                                                                                                                                                                                                                                            {

                                                                                                                                                                                                                                            }

                                                                                                                                                                                                                                            private void label3_Click(object sender, EventArgs e)
                                                                                                                                                                                                                                            {

                                                                                                                                                                                                                                            }

                                                                                                                                                                                                                                            private void label4_Click(object sender, EventArgs e)
                                                                                                                                                                                                                                            {

                                                                                                                                                                                                                                            }

                                                                                                                                                                                                                                            private void label2_Click(object sender, EventArgs e)
                                                                                                                                                                                                                                            {

                                                                                                                                                                                                                                            }

                                                                                                                                                                                                                                            private void conv_btn_Click(object sender, EventArgs e)
                                                                                                                                                                                                                                            {
                                                                                                                                                                                                                                                double i = double.Parse(amount_txt.Text);
                                                                                                                                                                                                                                                if(from.SelectedItem=="USDollar" && to.SelectedItem == "Rupiah")
                                                                                                                                                                                                                                                {
                                                                                                                                                                                                                                                    double conver = i * 14000;
                                                                                                                                                                                                                                                    disp_txt.Text = "Converted Amount : " + conver;
                                                                                                                                                                                                                                                }
                                                                                                                                                                                                                                                if (from.SelectedItem == "Rupiah" && to.SelectedItem == "Euro")
                                                                                                                                                                                                                                                {
                                                                                                                                                                                                                                                    double conver = i / 17000;
                                                                                                                                                                                                                                                    disp_txt.Text = "Converted Amount : " + conver;
                                                                                                                                                                                                                                                }
                                                                                                                                                                                                                                                if (from.SelectedItem == "USDollar" && to.SelectedItem == "Euro")
                                                                                                                                                                                                                                                {
                                                                                                                                                                                                                                                    double conver = i * 0.71;
                                                                                                                                                                                                                                                    disp_txt.Text = "Converted Amount : " + conver;
                                                                                                                                                                                                                                                }
                                                                                                                                                                                                                                                if (from.SelectedItem == "Euro" && to.SelectedItem == "Rupiah")
                                                                                                                                                                                                                                                {
                                                                                                                                                                                                                                                    double conver = i * 17000;
                                                                                                                                                                                                                                                    disp_txt.Text = "Converted Amount : " + conver;
                                                                                                                                                                                                                                                }
                                                                                                                                                                                                                                                if (from.SelectedItem == "Euro" && to.SelectedItem == "USDollar")
                                                                                                                                                                                                                                                {
                                                                                                                                                                                                                                                    double conver = i / 0.71;
                                                                                                                                                                                                                                                    disp_txt.Text = "Converted Amount : " + conver;
                                                                                                                                                                                                                                                }
                                                                                                                                                                                                                                                if (from.SelectedItem == "Rupiah" && to.SelectedItem == "USDollar")
                                                                                                                                                                                                                                                {
                                                                                                                                                                                                                                                    double conver = i / 14000;
                                                                                                                                                                                                                                                    disp_txt.Text = "Converted Amount : " + conver;
                                                                                                                                                                                                                                                }
                                                                                                                                                                                                                                            }
                                                                                                                                                                                                                                        }
                                                                                                                                                                                                                                    }

                                                                                                                                                                                                                                    tampilan :



                                                                                                                                                                                                                                    terdapat dropdown menu untuk memilih currency


                                                                                                                                                                                                                                    jika tombol convert diklik maka dalam baris "converted Amount" akan terlihat isi yang sudah di convert


                                                                                                                                                                                                                                    Comments

                                                                                                                                                                                                                                    Popular posts from this blog

                                                                                                                                                                                                                                    CRUD (Code Igniter) - Tugas 7

                                                                                                                                                                                                                                    Web Jual Toko Ikan - Tugas Kelompok