1 / 34

340 likes | 457 Vues

Tutorial 9 - Car Payment Calculator Application Introducing the Do While…Loop and Do Until…Loop Repetition Statements. Outline

Télécharger la présentation
## Tutorial 9 - Car Payment Calculator Application Introducing the Do While…Loop and Do Until…Loop Repetition Stateme

**An Image/Link below is provided (as is) to download presentation**
Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.
Content is provided to you AS IS for your information and personal use only.
Download presentation by click this link.
While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.
During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

**Tutorial 9 - CarPaymentCalculator ApplicationIntroducing the**DoWhile…Loop and DoUntil…Loop Repetition Statements Outline 9.1 Test-Driving the Car Payment Calculator Application9.2 Do While…Loop Repetition Statement9.3 Do Until…Loop Repetition Statement9.4 Constructing the Car Payment Calculator Application9.5 Wrap-Up**Objective**• In this tutorial, you will learn to: • Use the Do While…Loop and Do Until…Loop repetition statements to execute statements in a program repeatedly. • Use counter-controlled repetition. • Display information in ListBoxes.**ListBox control**9.1 Test-Driving the Car Payment Calculator Application Figure 9.1Car Payment Calculator application before data has been entered.**9.1 Test-Driving the Car Payment Calculator Application**Figure 9.2Car Payment Calculatorapplication after data has been entered. • Input data • Click CalculateButton**Results displayed in tabular format**9.1 Test-Driving the Car Payment Calculator Application Figure 9.3 Car Payment Calculator application displaying calculation results.**9.2 Do While…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 intProduct As Integer = 3Do While intProduct <= 50 intProduct *= 3Loop**9.2 Do While…Loop Repetition Statement**Figure 9.4 Do While Loop repetition statement UML activity diagram.**9.3 Do Until…Loop 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 intProduct As Integer = 3Do Until intProduct > 50 intProduct *= 3Loop**9.3 Do Until…Loop Repetition Statement**Figure 9.5 Do Until Loop repetition statement UML activity diagram**9.4 Constructing the Car Payment Calculator Application**Figure 9.7Car Payment Calculatorapplication’s Form in design mode.**ListBox’s control name displayed in design view**9.4 Constructing the Car Payment Calculator Application • ListBoxcontrol • Change the Name property Figure 9.8 ListBox added toCar Payment Calculatorapplication’s Form.**9.4 Constructing the Car Payment Calculator Application**• Adding code to the event handler • Clearing the ListBox • Call method Clear on property Items • Items property returns an object containing items in ListBox**9.4 Constructing the Car Payment Calculator Application**Figure 9.9 Clearing the contents of aListBox.**9.4 Constructing the Car Payment Calculator Application**• Adding a header to the ListBox • Call method Add • String-concatenation operator (&) • ControlChars.Tab constant**9.4 Constructing the Car Payment Calculator Application**Figure9.10Adding a header to aListBox.**Variables to store the length of the loan**Variables to store userinput Variables to store calculation results 9.4 Constructing the Car Payment Calculator Application Figure9.11 Variables for theCar Payment Calculatorapplication. • Variable declarations**9.4 Constructing the Car Payment Calculator Application**Figure9.12 Retrieving input in theCarPayment Calculatorapplication. • Retrieving input • Use Valfunction • Divide interest rate by100**9.4 Constructing the Car Payment Calculator Application**• Calculating values used in the calculation • Subtract down payment from price • Monthly interest rate is interest divided by 12**9.4 Constructing the Car Payment Calculator Application**Figure9.13 Determining amount borrowed and monthly interest rate.**9.4 Constructing the Car Payment Calculator Application**• Setting the loop-continuation condition • Counter-controlled repetition • Uses a counter variable • Also called definite repetition**9.4 Constructing the Car Payment Calculator Application**Figure9.14 Loop-continuation condition.**9.4 Constructing the Car Payment Calculator Application**Figure9.15 Converting the loan duration from years to months. • Add the length of the loan in months**9.4 Constructing the Car Payment Calculator Application**• Calculate monthly payment amount • Use Pmt function • Returns a Double value • Type Decimal stores monetary values • Use the Convert.ToDecimal method**9.4 Constructing the Car Payment Calculator Application**Figure9.16 Pmt function returns monthly payment.**9.4 Constructing the Car Payment Calculator Application**• Displaying the result • Use method Add • Use method String.Format to display values in currency format**9.4 Constructing the Car Payment Calculator Application**Figure9.17 Displaying the number of months and the amount of each monthly payment.**9.4 Constructing the Car Payment Calculator Application**• Increment the counter • Add one to the counter • Will terminate the loop when value becomes 6**9.4 Constructing the Car Payment Calculator Application**Figure9.18 Incrementing the counter.

More Related