PBKK A : Latihan 1 Membuat Aplikasi Desktop Sederhana

Nama    : Hanafi Satriyo Utomo Setiawan
NRP      : 5025211195
Kelas     : PBKK A

Berikut merupakan salah satu tugas dari mata kuliah PBKK yang saya kerjakan. Tugas tersebut berupa membuat project windows application menggunakan .NET FRAMEWORK. Pada kesempatan kali ini saya membuat sebuah kalkulator sederhana yang memiliki fungsi untuk menambah, mengurang, mengali, serta membagi dua bilangan. Berikut merupakan tampilannya



Source code:

namespace CalculatorApp

{

    public partial class Form1 : Form

    {

        Double resultValue = 0;

        String Action = "";

        bool isAction = false;


        public Form1()

        {

            InitializeComponent();

        }


        private void Form1_Load(object sender, EventArgs e)

        {


        }


        private void n_click(object sender, EventArgs e)

        {

            if ((textBox.Text == "0") || (isAction) ) 

                textBox.Clear();

            isAction = false;

            Button n = (Button)sender;

            if(n.Text == ".")

            {

                if(!textBox.Text.Contains("."))

                    textBox.Text = textBox.Text + n.Text;

            }else

            textBox.Text = textBox.Text + n.Text;


        }


        private void n_operation(object sender, EventArgs e)

        {

            Button n = (Button)sender;

            Action = n.Text;

            resultValue = Double.Parse(textBox.Text);

            isCurrentOp.Text = resultValue + " " + Action;

            isAction = true;

            

        }


        private void n_result(object sender, EventArgs e)

        {

            switch (Action)

            {

                case "+":

                    textBox.Text = (resultValue + Double.Parse(textBox.Text)).ToString();

                    break;

                case "-":

                    textBox.Text = (resultValue - Double.Parse(textBox.Text)).ToString();

                    break;

                case "x":

                    textBox.Text = (resultValue * Double.Parse(textBox.Text)).ToString();

                    break;

                case "/":

                    textBox.Text = (resultValue / Double.Parse(textBox.Text)).ToString();

                    break;

                default:

                    break;



            }

        }


        private void n_delete(object ender, EventArgs e)

        {

            textBox.Text = "0";

            resultValue = 0;

        }


        private void n_reset(object sender, EventArgs e)

        {

            textBox.Text = "0";

        }


        private void label1_Click(object sender, EventArgs e)

        {


        }

    }

}


https://github.com/tiostwn/PBKK-Calculator

Comments

Popular posts from this blog

PPL : Pertemuan 2

PPL : Pertemuan 7

Final Project : Pemrograman Berbasis Kerangka Kerja A