Halo teman-teman perkenalkan nama saya Gabriel Solomon Sitanggang dengan NRP 5025201165. Pada pertemuan kedua, kami ditugaskan untuk membuat aplikasi desktop sederhana. Saya akan membuat sebuah kalkulator BMI yang mengukur apakah seseorang itu kekurangan berat badan, normal, kelebihan berat badan, atau obesitas. Untuk tampilannya seperti dibawah ini :
Pada kalkulator BMI di atas, pengguna diminta untuk menginput beberapa data seperti berat badan, tinggi badan, dan satuan berat. Hasil perhitungan kalkulator BMI ini akan ditampilkan di kotak yang sudah tersedia. Dibawah kotak hasil terdapat tombol calculate yang berfungsi untuk menjalankan perhitungan yang ada pada program. Dibawah tombol reset yang berfungsi untuk membersihkan input pengguna dan terdapat tombol exit yang berfungsi untuk keluar dari program.
Untuk kodingan kalkulator BMI dapat dilihat dibawah ini :
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
namespace BMI | |
{ | |
public partial class Form1 : Form | |
{ | |
public Form1() | |
{ | |
InitializeComponent(); | |
} | |
private void btnExit_Click(object sender, EventArgs e) | |
{ | |
this.Close(); | |
} | |
private void btnReset_Click(object sender, EventArgs e) | |
{ | |
txtHeight.Text = ""; | |
txtWeight.Text = ""; | |
txtResult.Text = ""; | |
radKg.Checked = false; | |
radLb.Checked = false; | |
} | |
private void btnCalculate_Click(object sender, EventArgs e) | |
{ | |
double weight = Convert.ToDouble(txtWeight.Text); | |
double height = Convert.ToDouble(txtHeight.Text); | |
double result = 0.0; | |
string result2 = ""; | |
if (radKg.Checked) | |
{ | |
result = weight / (height * height); | |
} | |
else | |
if (radLb.Checked) | |
{ | |
weight = weight / 2.205; | |
result = weight / (height * height); | |
} | |
if(result < 18.5) | |
{ | |
result2 = "You are underweight"; | |
} | |
else | |
if(result < 25) | |
{ | |
result2 = "You have normal weight"; | |
} | |
else | |
if(result < 30) | |
{ | |
result2 = "You are overweight"; | |
} | |
else | |
if(result >= 30) | |
{ | |
result2 = "You are obese"; | |
} | |
txtResult.Text = "Your BMI is: " + result.ToString("#.#") + "\r\n" + result2; | |
} | |
} | |
} |
Untuk source code dari kalkulator program di atas dapat dilihat di link berikut link
Untuk hasil programnya bisa dilihat di video berikut
Tidak ada komentar:
Posting Komentar