In: Computer Science
(50 pts) Enhance the Future Goal Problem. a. Use lists to track and store the inputs and outputs for each Future Value investment the user calculates. b. Modify the existing code so that it correctly calculates the numbers months/years it takes to achieve a monetary goal. c. Write code that properly stores each input/output value in its corresponding list. d. Comment on the provided code for the History button. You do NOT need to modify the included code! It will work correctly if the rest of your program is properly coded. e. Validation is not necessary for this problem. When you are finished: zip the original folder (ISTM250Exam2) and name the zipfile based upon your name (e.g. BooneTedExam2).
Short Summary:
**************Please upvote the answer and appreciate our time.************
Source Code:
FRMFutureGoal.cs File:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace FutureValue
{
public partial class FRMFutureGoal : Form
{
// Use lists to store input/output values
List<decimal> historyInvestments = new List<decimal>();
List<decimal> historyInterestRates = new List<decimal>();
List<decimal> historyGoals = new List<decimal>();
List<int> historyMonths = new List<int>();
List<decimal> historyYears = new List<decimal>();
public FRMFutureGoal()
{
InitializeComponent();
}
private void btnCalculate_Click(object sender, EventArgs e)
{
// Read the values from text boxes
decimal monthlyInvestment = Convert.ToDecimal(txtMonthlyInvestment.Text);
decimal yearlyInterestRate = Convert.ToDecimal(txtInterestRate.Text);
decimal futureGoalValue = Convert.ToDecimal(txtFutureValue.Text);
decimal monthlyInterestRate = yearlyInterestRate / 12 / 100;
// Assume current future value is ZERO
decimal futureValue = 0m;
int months = 0;
// Add the monthly investment to the current future value, until it equals or exceeds Goal Value
while(futureValue < futureGoalValue)
{
futureValue = (futureValue + monthlyInvestment)
* (1 + monthlyInterestRate);
// Increment month for every iteration
months++;
}
txtMonths.Text = months.ToString();
// Convert months into year
decimal years = (decimal)months / (decimal)12;
txtYears.Text = years.ToString("0.00");
txtMonthlyInvestment.Focus();
// Add the input/output values to corresponding lists
historyInvestments.Add(monthlyInvestment);
historyInterestRates.Add(yearlyInterestRate);
historyGoals.Add(futureGoalValue);
historyMonths.Add(months);
historyYears.Add(years);
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnHistory_Click(object sender, EventArgs e)
{
// heading
string history = string.Format("{0,-15}{1, -15}{2, -20}{3, -15}{4, -15}\n", "inv", "IR", "Goal", "mths", "yrs");
// Loop through the lists and add rows
for(int index = 0; index < historyInvestments.Count; index++)
{
history += string.Format("{0,-10}{1, -10}{2, -20}{3, -10}{4, -10}\n", historyInvestments[index].ToString("c"),
(historyInterestRates[index].ToString("0.00") + "%"), historyGoals[index].ToString("c"), historyMonths[index], historyYears[index].ToString("0.00"));
}
// Display in a meesagebox
MessageBox.Show(history);
}
}
}
**************************************************************************************
FRMFutureGoal.designer.cs File
namespace FutureValue
{
partial class FRMFutureGoal
{
/// <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);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.txtMonthlyInvestment = new System.Windows.Forms.TextBox();
this.txtInterestRate = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.txtFutureValue = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.txtMonths = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label();
this.txtYears = new System.Windows.Forms.TextBox();
this.label5 = new System.Windows.Forms.Label();
this.btnCalculate = new System.Windows.Forms.Button();
this.btnExit = new System.Windows.Forms.Button();
this.btnHistory = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(84, 57);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(146, 20);
this.label1.TabIndex = 0;
this.label1.Text = "Monthly Invesment:";
//
// txtMonthlyInvestment
//
this.txtMonthlyInvestment.Location = new System.Drawing.Point(256, 54);
this.txtMonthlyInvestment.Name = "txtMonthlyInvestment";
this.txtMonthlyInvestment.Size = new System.Drawing.Size(185, 26);
this.txtMonthlyInvestment.TabIndex = 1;
//
// txtInterestRate
//
this.txtInterestRate.Location = new System.Drawing.Point(256, 118);
this.txtInterestRate.Name = "txtInterestRate";
this.txtInterestRate.Size = new System.Drawing.Size(185, 26);
this.txtInterestRate.TabIndex = 3;
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(84, 121);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(155, 20);
this.label2.TabIndex = 2;
this.label2.Text = "Yearly Interest Rate:";
//
// txtFutureValue
//
this.txtFutureValue.Location = new System.Drawing.Point(256, 181);
this.txtFutureValue.Name = "txtFutureValue";
this.txtFutureValue.Size = new System.Drawing.Size(185, 26);
this.txtFutureValue.TabIndex = 5;
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(84, 184);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(158, 20);
this.label3.TabIndex = 4;
this.label3.Text = "Future Goal Amount:";
//
// txtMonths
//
this.txtMonths.Location = new System.Drawing.Point(256, 251);
this.txtMonths.Name = "txtMonths";
this.txtMonths.ReadOnly = true;
this.txtMonths.Size = new System.Drawing.Size(185, 26);
this.txtMonths.TabIndex = 7;
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(84, 254);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(144, 20);
this.label4.TabIndex = 6;
this.label4.Text = "Number of Months:";
//
// txtYears
//
this.txtYears.Location = new System.Drawing.Point(256, 320);
this.txtYears.Name = "txtYears";
this.txtYears.ReadOnly = true;
this.txtYears.Size = new System.Drawing.Size(185, 26);
this.txtYears.TabIndex = 9;
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(84, 323);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(133, 20);
this.label5.TabIndex = 8;
this.label5.Text = "Number of Years:";
//
// btnCalculate
//
this.btnCalculate.Location = new System.Drawing.Point(137, 373);
this.btnCalculate.Name = "btnCalculate";
this.btnCalculate.Size = new System.Drawing.Size(122, 44);
this.btnCalculate.TabIndex = 10;
this.btnCalculate.Text = "Calculate";
this.btnCalculate.UseVisualStyleBackColor = true;
this.btnCalculate.Click += new System.EventHandler(this.btnCalculate_Click);
//
// btnExit
//
this.btnExit.Location = new System.Drawing.Point(295, 373);
this.btnExit.Name = "btnExit";
this.btnExit.Size = new System.Drawing.Size(122, 44);
this.btnExit.TabIndex = 11;
this.btnExit.Text = "Exit";
this.btnExit.UseVisualStyleBackColor = true;
this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
//
// btnHistory
//
this.btnHistory.Location = new System.Drawing.Point(201, 451);
this.btnHistory.Name = "btnHistory";
this.btnHistory.Size = new System.Drawing.Size(109, 39);
this.btnHistory.TabIndex = 12;
this.btnHistory.Text = "History";
this.btnHistory.UseVisualStyleBackColor = true;
this.btnHistory.Click += new System.EventHandler(this.btnHistory_Click);
//
// FRMFutureGoal
//
this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(502, 539);
this.Controls.Add(this.btnHistory);
this.Controls.Add(this.btnExit);
this.Controls.Add(this.btnCalculate);
this.Controls.Add(this.txtYears);
this.Controls.Add(this.label5);
this.Controls.Add(this.txtMonths);
this.Controls.Add(this.label4);
this.Controls.Add(this.txtFutureValue);
this.Controls.Add(this.label3);
this.Controls.Add(this.txtInterestRate);
this.Controls.Add(this.label2);
this.Controls.Add(this.txtMonthlyInvestment);
this.Controls.Add(this.label1);
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "FRMFutureGoal";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Future Value Goal";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox txtMonthlyInvestment;
private System.Windows.Forms.TextBox txtInterestRate;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox txtFutureValue;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox txtMonths;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.TextBox txtYears;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Button btnCalculate;
private System.Windows.Forms.Button btnExit;
private System.Windows.Forms.Button btnHistory;
}
}
**************************************************************************************
Sample Run:
**************************************************************************************
Feel free to rate the answer and comment your questions, if you have any.
Please upvote the answer and appreciate our time.
Happy Studying!!!
**************************************************************************************