Mgmt 362a Car Payment Calculator Application - PowerPoint PPT Presentation

1 / 31
About This Presentation
Title:

Mgmt 362a Car Payment Calculator Application

Description:

9.1 Test-Driving the Car Payment Calculator Application ... price of a car, the down-payment amount and the annual interest rate of the loan. ... – PowerPoint PPT presentation

Number of Views:43
Avg rating:3.0/5.0
Slides: 32
Provided by: Pear179
Category:

less

Transcript and Presenter's Notes

Title: Mgmt 362a Car Payment Calculator Application


1
9
  • Mgmt 362a Car Payment Calculator Application
  • Introducing the Do While...Loopand Do
    Until...Loop Repetition Statements

2
Objectives
  • In this tutorial you will learn
  • Use the Do While...Loop and Do Until... Loop
    repetition statements to execute statements in an
    application repeatedly.
  • Use counter-controlled repetition.
  • Display information in ListBoxes.
  • Concatenate strings.

3
9.1 Test-Driving the Car Payment Calculator
Application
  • Typically, banks offer car loans for periods
    ranging from two tofive years (24 to 60 months).
    Borrowers repay the loans in monthly
    installments. The amount of each monthly payment
    is based on the length of the loan, the amount
    borrowed and the interest rate. Createan
    application that allows the customer to enter the
    price of a car, the down-payment amount and the
    annual interest rate of the loan. The application
    should display the loans duration in months and
    themonthly payments for two-, three-, four- and
    five-year loans. Thevariety of options allows
    the user to easily compare repayment plans and
    choose the one that is most convenient.

4
9.1 Test-Driving the Car Payment Calculator
Application (Cont.)
  • Figure 9.1 Car Payment Calculator application
    before data has been entered.

5
9.1 Test-Driving the Car Payment Calculator
Application (Cont.)
  • Figure 9.2 Car Payment Calculator application
    after data has been entered.
  • Input data
  • Click Calculate Button

6
9.1 Test-Driving the Car Payment Calculator
Application (Cont.)
  • Figure 9.3 Car Payment Calculator application
    displaying calculation results.

7
9.2 DoWhile Loop Repetition Statement
  • Loop-continuation condition
  • While loop-continuation condition remains true,
    loop statement executes its body repeatedly
  • When loop-continuation condition becomes false,
    loop terminates
  • Code example
  • Dim product As Integer 3Do While product lt
    50 product 3Loop

8
Common Programming Error
  • Provide in the body of every Do While...Loop
    statement an action that eventually causes the
    condition to become false. If you do not,
    therepetition statement never terminates,
    causingan error called an infinite loop. Such an
    errorcauses the application to hang up. When
    aninfinite loop occurs in an application, right
    clickthe application in the task bar and select
    Close.In the dialog box that pops up, click End
    Now.

9
9.3 Do UntilLoop Repetition Statement
  • Loop-continuation condition
  • While loop-continuation condition remains false,
    loop statement executes its body repeatedly
  • When loop-continuation condition becomes true,
    loop terminates
  • Code example
  • Dim product As Integer 3Do Until product gt
    50 product 3Loop

10
Common Programming Error
  • Failure to provide the body of a Do Until...Loop
    statement with an action that eventually causes
    the condition in the Do Until...Loop to
    becometrue creates an infinite loop.

11
9.4 Adding a ListBox to the Car
PaymentCalculator Application (Cont.)
  • Figure 9.8 ListBox added to Car Payment
    Calculator applications Form.
  • ListBox control
  • Change the Name property

12
9.4 Using Code to Change a ListBoxs Contents
  • Adding code to the event handler
  • Clearing the ListBox
  • Call method Clear on property Items
  • Items property returns an object containing items
    in ListBox

13
9.4 Using Code to Change a ListBoxs Contents
(Cont.)
  • Figure 9.9 Clearing the contents of a ListBox.

14
9.4 Using Code to Change a ListBoxs Contents
(Cont.)
  • Adding a header to the ListBox
  • Call method Add
  • String-concatenation operator ()
  • ControlChars.Tab constant

15
GUI Design Tip
  • Use headers in a ListBox when you aredisplaying
    tabular data. Adding headers improves readability
    by indicating the information that will be
    displayed in the ListBox.

16
9.4 Using Code to Change a ListBoxs Contents
(Cont.)
  • Figure 9.10 Adding a header to a ListBox.

17
9.4 Declaring Variables and Receiving User Input
  • Figure 9.11 Variables for the Car Payment
    Calculator application.

Variable declarations
18
9.4 Declaring Variables and Receiving User Input
(Cont.)
  • Figure 9.12 Retrieving input in the Car Payment
    Calculator application.
  • Retrieving input
  • Use Val function
  • Divide interest rate by 100

19
9.4 Declaring Variables and Receiving User Input
(Cont.)
  • Calculating values used in the calculation
  • Subtract down payment from price
  • Monthly interest rate is interest divided by 12

20
9.4 Declaring Variables and Receiving User Input
(Cont.)
  • Figure 9.13 Determining amount borrowed and
    monthly interest rate.

21
9.4 Calculating the Monthly Payment Amounts with
aDo While...Loop Repetition Statement
  • Setting the loop-continuation condition
  • Counter-controlled repetition
  • Uses a counter variable
  • Also called definite repetition

22
Calculating the Monthly Payment Amounts with aDo
While...Loop Repetition Statement (Cont.)
  • Figure 9.14 Loop-continuation condition.

23
Calculating the Monthly Payment Amounts with aDo
While...Loop Repetition Statement (Cont.)
  • Figure 9.15 Converting the loan duration from
    years to months.
  • Add the length of the loan in months

24
Calculating the Monthly Payment Amounts with aDo
While...Loop Repetition Statement (Cont.)
  • Calculate monthly payment amount
  • Use Pmt function
  • Returns a Double value
  • Type Decimal stores monetary values
  • Use the Convert.ToDecimal method

25
Calculating the Monthly Payment Amounts with aDo
While...Loop Repetition Statement (Cont.)
  • Figure 9.16 Pmt function returns monthly
    payment.

26
Calculating the Monthly Payment Amounts with aDo
While...Loop Repetition Statement (Cont.)
  • Displaying the result
  • Use method Add
  • Use method String.Format to display values in
    currency format

27
Calculating the Monthly Payment Amounts with aDo
While...Loop Repetition Statement (Cont.)
  • Figure 9.17 Displaying the number of months and
    the amount of eachmonthly payment.

28
Calculating the Monthly Payment Amounts with aDo
While...Loop Repetition Statement (Cont.)
  • Increment the counter
  • Add one to the counter
  • Will terminate the loop when value becomes 6

29
Calculating the Monthly Payment Amounts with aDo
While...Loop Repetition Statement (Cont.)
  • Figure 9.18 Incrementing the counter.

30
Outline
(1 of 2 )
31
Outline
(2 of 2 )
Write a Comment
User Comments (0)
About PowerShow.com