Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Exercise 6 - 1 Enhance the Future Value application In this exercise, you'll enhance the Future Value application that you created in chapter 5 so
Exercise Enhance the Future Value application
In this exercise, you'll enhance the Future Value application that you created in chapter so it works like the one in figure
Use refactoring to create the CalculateFutureValue method
Open the application that's in the :#FutureValue directory.
Use refactoring as shown in figure to refactor the calculation in the event handler and create a new method named CalculateFutureValue
Test the application to make sure the new method works correctly.
Add the CalculateFutureValue method without using refactoring
Press twice to return the code to the way it was before you refactored it
Add a method named CalculateFutureValue that works like the one in figure To do that, type the start of the new method including its opening brace, and its closing brace will be added automatically. Then, move the related code from the btnCalculateClick method to the block within the new method and modify it where necessary.
Modify the code in the btnCalculateClick method so it calls the CalculateFutureValue method. As you enter the call to the method, note how the IntelliSense feature helps you enter the arguments.
Test the application to make sure this new method works correctly.
Add an event handler for the TextChanged events
In the Form Designer, select the first text box. Then, click the Events button in the Properties window to display the Events list for that text box. Review the events that are available.
Enter "ClearFutureValue" to the right of the TextChanged event and press Enter. When you do the Code Editor will open and an event handler named ClearFutureValue will be created. Enter a statement that clears the Future Value text box as shown in figure
Open the frmFutureValue.Designer.cs file for the form, expand the Windows Form Designer generated code region if necessary, and locate the statements that set the properties of the Monthly Investment text box. At the end of those statements, you'll find a statement that wires the TextChanged event of this control to the ClearFutureValue event handler.
Return to the Form Designer and select the Yearly Interest Rate text box. Drop down the list for the TextChanged event of this control, and notice that the ClearFutureValue event handler is included in this list. Select this event handl to wire the event to it Repeat this process for the Number of Years text box.
Run the application and perform a calculation. Then, change the value that's displayed in one of the text boxes. When you do that, the value that's display for the Future Value text box should be cleared.
When you're sure the enhancements are working correctly, close the application.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started