Visual Basic 2015 Reloaded Diane Zak Tools in the interface: Principle: with Tex
ID: 3602419 • Letter: V
Question
Visual Basic 2015 Reloaded Diane Zak
Tools in the interface:
Principle: with TextBox
Annual interest rate (%): with ComboBox
Term (years): with ComboBox
Monthly payment: with Label
Principle and interest: with ListBox
Display = Button
Exit = Button
(PLEASE WRITE CODE FOR INTERFACE IN PICTURE, AS INSTRUCTED BY PROFESSOR)
Case Projects Case Projects Loan Calculator Create an application that displays a monthly payment on a loan. also display the amount applied to the loan's principal each month and represents interest. Use the following names for the solution and project, respectively Solution and Loan Project. Save the soluti the form fil 2% through 10% The application should the amount that : Loan on in the VbReloaded2015Chap07 folder. Change le's name to Main Form.vb. The application should use annual interest rates from in increments of 1%, and use terms from 1 through 30 years. You can use Financial.PPmt method to calculate the portion of the payment applied to the principal each month. The method's syntax is Financial.PPmt (Rate, Per, NPer, PV). In the syntax, Rate is the interest rate, NPer is the number of payment periods, and PV is the present value of the loan. The Per argument is the payment period for which you want to calculate the portion applied to the principal. The Per argument must be a number from 1 through NPer. The method returns the calculated value as a Double number. You can either create your own interface or create the one shown in Figure 7-44; the figure shows a sample run of the application. The combo box that gets the interest rate is the DropDown style. The combo box that gets the term is the DropDownList style. The text box that displays the output has its Multiline and ReadOnly properties set to True and its ScrollBars property set to Vertical. Loan Calculator Annual interest rate (%): Term (years) Principal 120000 4 30 Monthly payment 5572.80 Bselby Principal and interest: Display Exit Principal Interest 172.90 173.47 174.05 174.63 175.22 175.80 176.39 176.97 400.00 399.42 398.85 398.27 397. 68 397.10 396.51 395.93 v Figure 7-44 Sample run of the Loan Calculator applicationExplanation / Answer
using System;
using System.Drawing;
using System.Windows.Forms;
namespace PMTApp
{
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.TextBox textBox4;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.StatusBar statusBar1;
private System.Windows.Forms.Timer timer1;
private System.Windows.Forms.ToolTip toolTip1;
private System.ComponentModel.IContainer components;
public Form1()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.textBox4 = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.textBox2 = new System.Windows.Forms.TextBox();
this.textBox3 = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.statusBar1 = new System.Windows.Forms.StatusBar();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
this.SuspendLayout();
//
// textBox4
//
this.textBox4.BackColor = System.Drawing.Color.Gainsboro;
this.textBox4.Location = new System.Drawing.Point(136, 144);
this.textBox4.Name = "textBox4";
this.textBox4.ReadOnly = true;
this.textBox4.Size = new System.Drawing.Size(80, 20);
this.textBox4.TabIndex = 4;
this.textBox4.TabStop = false;
this.textBox4.Text = "";
this.toolTip1.SetToolTip(this.textBox4, "Monthly payment");
//
// label1
//
this.label1.Location = new System.Drawing.Point(32, 24);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(96, 24);
this.label1.TabIndex = 0;
this.label1.Text = "Present value-$";
//
// label2
//
this.label2.Location = new System.Drawing.Point(40, 64);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(96, 24);
this.label2.TabIndex = 0;
this.label2.Text = "Interest rate-%";
//
// label3
//
this.label3.Location = new System.Drawing.Point(40, 112);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(96, 24);
this.label3.TabIndex = 0;
this.label3.Text = "Period";
//
// button1
//
this.button1.BackColor = Color.FromArgb(((System.Byte)(0)),
((System.Byte)(192)), ((System.Byte)(192)));
this.button1.Location = new System.Drawing.Point(72, 216);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(72, 24);
this.button1.TabIndex = 5;
this.button1.Text = "Calculate";
this.toolTip1.SetToolTip(this.button1, "Calculate the monthly payment");
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.BackColor = Color.FromArgb(((System.Byte)(0)), ((System.Byte)(192)), ((System.Byte)(192)));
this.button2.Location = new System.Drawing.Point(168, 216);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(72, 24);
this.button2.TabIndex = 6;
this.button2.Text = "E&xit";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// textBox2
//
this.textBox2.BackColor = System.Drawing.Color.White;
this.textBox2.Location = new System.Drawing.Point(136, 64);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(80, 20);
this.textBox2.TabIndex = 2;
this.textBox2.Text = "10.00";
this.toolTip1.SetToolTip(this.textBox2, "Interest rate per year");
this.textBox2.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txt_KeyPress);
this.textBox2.TextChanged += new System.EventHandler(this.txt_TextChanged);
//
// textBox3
//
this.textBox3.BackColor = System.Drawing.Color.White;
this.textBox3.Location = new System.Drawing.Point(136, 104);
this.textBox3.Name = "textBox3";
this.textBox3.Size = new System.Drawing.Size(80, 20);
this.textBox3.TabIndex = 3;
this.textBox3.Text = "60";
this.toolTip1.SetToolTip(this.textBox3, "Period in months");
this.textBox3.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txt_KeyPress);
this.textBox3.TextChanged += new System.EventHandler(this.txt_TextChanged);
//
// label4
//
this.label4.Location = new System.Drawing.Point(40, 152);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(96, 24);
this.label4.TabIndex = 0;
this.label4.Text = "Payment PMT - $";
//
// textBox1
//
this.textBox1.BackColor = System.Drawing.Color.White;
this.textBox1.Location = new System.Drawing.Point(136, 24);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(80, 20);
this.textBox1.TabIndex = 1;
this.textBox1.Text = "25000";
this.toolTip1.SetToolTip(this.textBox1, "Loan amount");
this.textBox1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txt_KeyPress);
this.textBox1.TextChanged += new System.EventHandler(this.txt_TextChanged);
//
// statusBar1
//
this.statusBar1.Location = new System.Drawing.Point(0, 253);
this.statusBar1.Name = "statusBar1";
this.statusBar1.Size = new System.Drawing.Size(292, 20);
this.statusBar1.TabIndex = 8;
this.statusBar1.Text = "Ready";
//
// timer1
//
this.timer1.Enabled = true;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(176)), ((System.Byte)(231)), ((System.Byte)(216)));
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(textBox1);
this.Controls.Add(textBox2);
this.Controls.Add(textBox3);
this.Controls.Add(textBox4);
this.Controls.Add(label1 );
this.Controls.Add(label2);
this.Controls.Add(label3);
this.Controls.Add(label4);
this.Controls.Add(button1);
this.Controls.Add(button2);
this.Controls.Add(statusBar1);
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "PMT Calculator";
this.ResumeLayout(false);
}
// The main entry point for the application.
static void Main()
{
Application.Run(new Form1());
}
private void button2_Click(object sender, System.EventArgs e)
{
Application.Exit();
}
static bool CheckForNumeric(char ch)
{
//allow only numbers and a decimal point and backspace key
int keyInt = (int)ch ;
if (( keyInt < 48 || keyInt > 57) && keyInt != 46 && keyInt != 8)
return false;
else
return true ;
}
private void txt_TextChanged(object sender, EventArgs e)
{
textBox4.Text ="" ;
}
private void txt_KeyPress(object sender, KeyPressEventArgs e)
{
//allow only numbers and a decimal point and backspace key
if (CheckForNumeric(e.KeyChar) == false)
e.Handled = true ;
}
private void button1_Click(object sender, System.EventArgs e)
{
double pv = Convert.ToDouble(textBox1.Text);
double intrate = Convert.ToDouble(textBox2.Text) ;
double period = Convert.ToDouble(textBox3.Text) ;
double pmt = calcPayment( pv,period, intrate) ;
string str = pmt.ToString( "f2" );
textBox4.Text = str ;
}
public static double calcPayment(double presentValue, double financingPeriod,doubleinterestRatePerYear)
{
double a, b, x;
double monthlyPayment;
a = (1 + interestRatePerYear / 1200);
b = financingPeriod;
x = Math.Pow(a, b);
x = 1 / x;
x = 1 - x;
monthlyPayment = (presentValue ) * (interestRatePerYear / 1200) / x;
return(monthlyPayment);
}
private void timer1_Tick(object sender, System.EventArgs e)
{
if(textBox1.Focused == true)
{
statusBar1.Text =" Enter the annual interest rate - %" ;
else if(textBox3.Focused == true)
statusBar1.Text =" Enter the number of months financed" ;
else if(textBox4.Focused == true)
statusBar1.Text =" Calculated Monthly Loan Payment -$" ;
else
statusBar1.Text =" " ;
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.