Mgmt 362a Interest Calculator Application - PowerPoint PPT Presentation

1 / 32
About This Presentation
Title:

Mgmt 362a Interest Calculator Application

Description:

11.1 Test-Driving the Interest Calculator Application ... investing $1,000.00 in a savings account that yields 5% interest, and you ... – PowerPoint PPT presentation

Number of Views:28
Avg rating:3.0/5.0
Slides: 33
Provided by: Pear179
Category:

less

Transcript and Presenter's Notes

Title: Mgmt 362a Interest Calculator Application


1
11
  • Mgmt 362a Interest CalculatorApplication
  • Introducing the For...NextRepetition Statement

2
Objectives
  • In this tutorial you will learn
  • Execute statements repeatedly with the For...Next
    repetition statement.
  • Obtain user input with the NumericUpDown control.
  • Display information, using a multiline TextBox.
  • Use type String.

3
11.1 Test-Driving the Interest Calculator
Application
  • You are considering investing 1,000.00 in a
    savings account that yields 5 interest, and you
    want to forecast how your investment will grow.
    Assuming that you will leave all interest on
    deposit, calculate and print the amount of money
    in the account at the end of each year over a
    period of n years. To compute these amounts, use
    the following formula
  • a p (1 r)n
  • where
  • p is the original amount of money invested
    (the principal) r is the annual interest rate
    (for example, .05 is equivalent to 5) n is the
    number of years a is the amount on deposit at
    the end of the nth year.

4
11.1 Test-Driving the Interest Calculator
Application (Cont.)
  • Figure 11.1 Completed Interest Calculator
    application.
  • Executing the application

5
11.1 Test-Driving the Interest Calculator
Application (Cont.)
  • Enter data into application
  • Principal and interest rate entered
  • Using NumericUpDown control to increase years
  • Program output
  • Output displayed in multiline TextBox
  • Vertical scrollbar enabled

6
11.1 Test-Driving the Interest Calculator
Application (Cont.)
  • Figure 11.2 Output of completed Interest
    Calculator application.

7
11.2 Essentials of Counter-Controlled Repetition
  • Four essential elements of counter-controlled
    repetition
  • The name of a control variable (or loop counter)
    that is used to determine the whether the loop
    continues to iterate
  • The initial value of a control variable
  • The increment (or decrement) by which the control
    variable is modified after each iteration
  • The condition that tests for the final value of
    the control variable

8
Outline
9
11.3 Introducing the For...Next Repetition
Statement
  • Figure 11.4 For...Next header components.

10
Good Programming Practice
  • Place a blank line before and after each control
    statement to make it stand out in the code.

11
Error-Prevention Tip
  • Although the value of the control variable can be
    changed in the body of a For...Next loop,avoid
    doing so, because this practice canlead to
    subtle errors.

12
Good Programming Practice
  • Vertical spacing above and below
    controlstatements, as well as indentation of the
    bodiesof control statements, enhances
    readability.

13
Error-Prevention Tip
  • If you use a For...Next loop for
    counter-controlled repetition, off-by-one errors
    (which occur when a loop is executed for one more
    or one fewer iteration than is necessary) are
    normally avoided, because the terminating value
    is clear.

14
Common Programming Error
  • Counter-controlled loops should not be
    controlledwith floating-point variables. These
    are represented only approximately in the
    computers memory, possibly resulting in
    imprecise counter valuesand inaccurate tests for
    termination that couldlead to logic errors.

15
Outline
16
11.5 Adding and Customizing a NumericUpDown
Control
  • Figure 11.8 Template Interest Calculator
    application Form in design view.
  • Template Form in Design view
  • Adding NumericUpDown control
  • Adding a multiline TextBox

17
11.5 Adding and Customizing a NumericUpDown
Control (Cont.)
  • NumericUpDown control
  • Increment property
  • Increment property default value
  • ReadOnly property
  • Range Limits
  • Maximum property
  • Minimum property

18
GUI Design Tip
  • A NumericUpDown control should follow the same
    GUI Design Guidelines as a TextBox. (See
    Appendix C.)

19
11.5 Adding and Customizing a NumericUpDown
Control (Cont.)
  • Figure 11.9 NumericUpDown control added to
    Interest Calculator application.

20
Good Programming Practice
  • Append the UpDown suffix to NumericUpDowncontrol
    names.

21
GUI Design Tip
  • Use a NumericUpDown control to limitthe range of
    user input.

22
11.5 Adding and Customizing a MultilineTextBox
with a Scrollbar
  • Multiline TextBox
  • Can use scrollbar
  • Enable vertical scrollbar

23
GUI Design Tip
  • If a TextBox will display multiple lines of
    output,set the Multiline property to True and
    left align the output by setting the TextAlign
    property to Left.

24
GUI Design Tip
  • If a multiline TextBox will display many lines
    ofoutput, limit the TextBox height and use a
    vertical scrollbar to allow users to view
    additional linesof output.

25
11.5 Adding and Customizing a MultilineTextBox
with a Scrollbar (Cont.)
  • Figure 11.10 Multiline TextBox with vertical
    scrollbar added to the Form.

26
11.5 Adding a Click Event Handler
  • Declaring variables
  • Declaring a counter variable
  • Retrieving user input
  • Storing user input into variables

27
11.5 Adding a Click Event Handler (Cont.)
  • Figure 11.11 Application code for retrieving
    and storing user input.

28
11.5 Adding a Click Event Handler (Cont.)
  • Figure 11.12 Application code for displaying a
    header in a multiline TextBox.
  • Displaying header text in multiline TextBox
  • Using ControlChars.Tab
  • Using ControlChars.CrLf

29
11.5 Calculating Cumulative Interest with
aFor...Next Statement
  • Figure 11.13 Application code for For...Next
    statement.

30
11.5 Calculating Cumulative Interest with
aFor...Next Statement (Cont.)
  • Figure 11.14 Application code for displaying
    calculation results.
  • Displaying results in a multiline TextBox

31
Outline
(1 of 2 )
Declare a variable of type String
Use the Value property of yearUpdDown
32
Outline
Construct a header for the TextBox as a String
(2 of 2 )
Loop from 1 to year
Append result of calculation to the String named
output
Display results in resultTextBox
Write a Comment
User Comments (0)
About PowerShow.com