0% found this document useful (0 votes)
5 views

Lab2.2 DesktopBased_ CalculateSimpleInterest

dotnet labreport

Uploaded by

karantestingdemo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Lab2.2 DesktopBased_ CalculateSimpleInterest

dotnet labreport

Uploaded by

karantestingdemo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Form1.Designer.

Cs
namespace CalculateSimpleInterest
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;

/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise,
false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}

private void InitializeComponent()


{
this.txtPrincipal = new System.Windows.Forms.TextBox();
this.txtRate = new System.Windows.Forms.TextBox();
this.txtTime = new System.Windows.Forms.TextBox();
this.lblPrincipal = new System.Windows.Forms.Label();
this.lblRate = new System.Windows.Forms.Label();
this.lblTime = new System.Windows.Forms.Label();
this.btnCalculate = new System.Windows.Forms.Button();
this.lblResult = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// txtPrincipal
//
this.txtPrincipal.Location = new System.Drawing.Point(124, 15);
this.txtPrincipal.Name = "txtPrincipal";
this.txtPrincipal.Size = new System.Drawing.Size(100, 20);
this.txtPrincipal.TabIndex = 0;
//
// txtRate
//
this.txtRate.Location = new System.Drawing.Point(124, 41);
this.txtRate.Name = "txtRate";
this.txtRate.Size = new System.Drawing.Size(100, 20);
this.txtRate.TabIndex = 1;
//
// txtTime
//
this.txtTime.Location = new System.Drawing.Point(124, 67);
this.txtTime.Name = "txtTime";
this.txtTime.Size = new System.Drawing.Size(100, 20);
this.txtTime.TabIndex = 2;
//
// lblPrincipal
//
this.lblPrincipal.AutoSize = true;
this.lblPrincipal.Location = new System.Drawing.Point(12, 18);
this.lblPrincipal.Name = "lblPrincipal";
this.lblPrincipal.Size = new System.Drawing.Size(106, 13);
this.lblPrincipal.TabIndex = 3;
this.lblPrincipal.Text = "Principal Amount ($):";
//
// lblRate
//
this.lblRate.AutoSize = true;
this.lblRate.Location = new System.Drawing.Point(12, 44);
this.lblRate.Name = "lblRate";
this.lblRate.Size = new System.Drawing.Size(86, 13);
this.lblRate.TabIndex = 4;
this.lblRate.Text = "Interest Rate (%):";
//
// lblTime
//
this.lblTime.AutoSize = true;
this.lblTime.Location = new System.Drawing.Point(12, 70);
this.lblTime.Name = "lblTime";
this.lblTime.Size = new System.Drawing.Size(79, 13);
this.lblTime.TabIndex = 5;
this.lblTime.Text = "Time (in years):";
//
// btnCalculate
//
this.btnCalculate.Location = new System.Drawing.Point(124, 93);
this.btnCalculate.Name = "btnCalculate";
this.btnCalculate.Size = new System.Drawing.Size(100, 23);
this.btnCalculate.TabIndex = 6;
this.btnCalculate.Text = "Calculate";
this.btnCalculate.UseVisualStyleBackColor = true;
this.btnCalculate.Click += new System.EventHandler(this.btnCalculate_Click);
//
// lblResult
//
this.lblResult.AutoSize = true;
this.lblResult.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblResult.Location = new System.Drawing.Point(12, 129);
this.lblResult.Name = "lblResult";
this.lblResult.Size = new System.Drawing.Size(98, 13);
this.lblResult.TabIndex = 7;
this.lblResult.Text = "Simple Interest: ";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(249, 161);
this.Controls.Add(this.lblResult);
this.Controls.Add(this.btnCalculate);
this.Controls.Add(this.lblTime);
this.Controls.Add(this.lblRate);
this.Controls.Add(this.lblPrincipal);
this.Controls.Add(this.txtTime);
this.Controls.Add(this.txtRate);
this.Controls.Add(this.txtPrincipal);
this.Name = "Form1";
this.Text = "Simple Interest Calculator";
this.ResumeLayout(false);
this.PerformLayout();
}

private System.Windows.Forms.TextBox txtPrincipal;


private System.Windows.Forms.TextBox txtRate;
private System.Windows.Forms.TextBox txtTime;
private System.Windows.Forms.Label lblPrincipal;
private System.Windows.Forms.Label lblRate;
private System.Windows.Forms.Label lblTime;
private System.Windows.Forms.Button btnCalculate;
private System.Windows.Forms.Label lblResult;
}
}

Form1.Cs

namespace CalculateSimpleInterest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnCalculate_Click(object sender, EventArgs
e)
{
try
{
double principal =
Convert.ToDouble(txtPrincipal.Text);
double rate = Convert.ToDouble(txtRate.Text);
double time = Convert.ToDouble(txtTime.Text);

double simpleInterest = (principal * rate * time) /


100;

lblResult.Text = $"Simple Interest:


{simpleInterest:C2}";
}
catch (FormatException)
{
MessageBox.Show("Please enter valid numeric
values for all fields.", "Input Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
catch (Exception ex)
{
MessageBox.Show($"An error occurred:
{ex.Message}", "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
}

You might also like