TUGAS 2 - PBKK

 

Kalkulator Sederhana

Nama : Fauzi Rizki Pratama

NRP : 5025211220


Pada pertemuan ini, saya telah mengembangkan sebuah aplikasi operator sederhana dengan menggunakan framework .NET.


Aplikasi ini memiliki beberapa fungsi kalkulator sederhana seperti penambahan, pengurangan, perkalian, dan pembagian. Selain itu, terdapat juga fungsi 'clear' yang memungkinkan pengguna untuk menghapus perhitungan sebelumnya.


Untuk memulai, langkah pertama adalah membuka proyek baru di aplikasi Visual Studio dan memilih 'Windows Forms App (.NET)'. Selanjutnya, Anda dapat mengatur tampilan aplikasi Anda sesuai kebutuhan, seperti menambahkan tombol, kotak teks, mengatur font, penataan, warna, dan lain-lain. Jangan lupa untuk memberi nama ulang tombol dan teks yang telah Anda tambahkan. Berikut adalah tampilannya

DATA HOSTED WITH ♥ BY PASTEBIN.COM - DOWNLOAD RAW - SEE ORIGINAL
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace Calculator
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         Double resultValue = 0;
  16.         String operationPerformed = "";
  17.         bool isOperationPerformed = false;
  18.         public Form1()
  19.         {
  20.             InitializeComponent();
  21.         }
  22.  
  23.         private void button_Click(object sender, EventArgs e)
  24.         {
  25.             if((textBox_Result.Text == "0") || (isOperationPerformed))
  26.                 textBox_Result.Clear();
  27.             isOperationPerformed = false;
  28.             Button button = (Button)sender;
  29.             if(button.Text == ".")
  30.             {
  31.                 if(!textBox_Result.Text.Contains("."))
  32.                     textBox_Result.Text = textBox_Result.Text + button.Text;
  33.             }
  34.             else
  35.             textBox_Result.Text = textBox_Result.Text + button.Text;
  36.         }
  37.  
  38.         private void operator_click(object sender, EventArgs e)
  39.         {
  40.             Button button = (Button)sender;
  41.             if(resultValue!=0)
  42.             {
  43.                 button15.PerformClick();
  44.                 operationPerformed = button.Text;
  45.                 labelCurrentOperation.Text = resultValue + " " + operationPerformed;
  46.                 isOperationPerformed = true;
  47.             }
  48.             else
  49.             {
  50.             operationPerformed = button.Text;
  51.             resultValue = Double.Parse(textBox_Result.Text);
  52.             labelCurrentOperation.Text = resultValue + " " + operationPerformed;
  53.             isOperationPerformed = true;
  54.             }
  55.         }
  56.  
  57.         private void button4_Click(object sender, EventArgs e)
  58.         {
  59.             textBox_Result.Text = "0";
  60.         }
  61.  
  62.         private void button5_Click(object sender, EventArgs e)
  63.         {
  64.             textBox_Result.Text = "0";
  65.             resultValue = 0;
  66.         }
  67.  
  68.         private void button15_Click(object sender, EventArgs e)
  69.         {
  70.             switch(operationPerformed)
  71.             {
  72.                 case "+":
  73.                     textBox_Result.Text = (resultValue +Double.Parse(textBox_Result.Text)).ToString();
  74.                     break;
  75.                 case "-":
  76.                     textBox_Result.Text = (resultValue -Double.Parse(textBox_Result.Text)).ToString();
  77.                     break;
  78.                 case "*":
  79.                     textBox_Result.Text = (resultValue *Double.Parse(textBox_Result.Text)).ToString();
  80.                     break;
  81.                 case "/":
  82.                     textBox_Result.Text = (resultValue /Double.Parse(textBox_Result.Text)).ToString();
  83.                     break;
  84.                 default:
  85.                     break;
  86.  
  87.             }
  88.             resultValue = Double.Parse(textBox_Result.Text);
  89.             labelCurrentOperation.Text = "";
  90.         }
  91.     }
  92. }

Komentar

Postingan populer dari blog ini

ETS PWEB B

Tugas 4: Aplikasi WPF (UI Dashboard)

ETS PBKK A