interestRate-max (x (L/512)) MonthlyPayments L * (interestRate a)(1+interestRate /in)^(in) PUT finame + iname PUT Aceto: acctf...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
interestRate-max (x (L/512)) MonthlyPayments L * (interestRate a)(1+interestRate /in)^(in) PUT finame + iname PUT "Aceto: acctf PUT LoanType PUT "Loan Amount You PUT "Time of Loan in years"+i PUT Interest Rate +interestRate PUT "Monthly Payments Monthly Paymeauf L=100 OENO -12 "Enter Customer First Name" Loop finame != "STOP" "Enter Customer Last Name PUT 'No Loan Account not approved for Loan "Enter Loan Type Variable Fixed Interest" GET IqaaType "Enter Loan Amount "Enter Length time of Loan in years" account-random t LoanType="Variable" Enter Customer First Name" PUT "Loan Program Ended End No interestRate Amount 1000.00 MonthlyPayments -L *(interestRate a)(1+interestRate /n)^(in) / PUT finame + name PUT "Aceto: "+ acc PUT LoadType PUT "Loan Amount +15 PUT "Time of Loan in years+f interestRate -.0933 PUT Interest Rate +interestRate PUT "Monthly Payments Monthly Paymeauf 5000.00 No Y interestRate -1045 JoanAmou 10000.00 interestRate -1625 sentinel value input sentinel-controlled loop loop Key 21 22 23 24 Point 25 26 27 } } 5.5 Controlling a Loop with User Confirmation or a Sentinel Value It is a common practice to use a sentinel value to terminate the input. The preceding example executes the loop five times. If you want the user to decide whether to continue, you can offer a user confirmation. The template of the program can be coded as follows: } You can rewrite the program given in Listing 5.4 with user confirmation to let the user decide whether to advance to the next question. char continueLoop = 'Y'; while (continueLoop == 'Y') { // Execute the loop body once Another common technique for controlling a loop is to designate a special value when reading and processing a set of values. This special input value, known as a sentinel value, signifies the end of the input. A loop that uses a sentinel value to control its execution is called a sentinel-controlled loop. 3 4 Listing 5.5 gives a program that reads and calculates the sum of an unspecified number of integers. The input 0 signifies the end of the input. Do you need to declare a new variable for each input value? No. Just use one variable named data (line 12) to store the input value, and use a variable named sum (line 15) to store the total. Whenever a value is read, assign it to data and, if it is not zero, add it to sum (line 17). LISTING 5.5 SentinelValue.java 1 2 5 // Prompt the user for confirmation System.out.print("Enter Y to continue and N to quit: "); continueLoop = input.getLine().charAt(0); 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 import java.util.Scanner; public class SentinelValue { / Main method */ public static void main(String[] args) { // Create a Scanner Scanner input = new Scanner (System.in); // Read an initial data System.out.print( "Enter an integer (the input ends if it is 0): "); int data input.nextInt (); // Keep reading data until the input is 0 int sum= 0; while (data != 0) { sum += data; // Read the next data System.out.print( 5.5 Controlling a Loop with User Confirmation or a Sentinel Value 169 "Enter an integer (the input ends if it is 0): "); data input.nextInt (); } System.out.println("The sum is " + sum); Enter an integer (the input ends if it is 0): 2 Enter Enter an integer (the input ends if it is 0) 3 Enter Enter an integer (the input ends if it is 0): 4 Enter Enter an integer (the input ends if it is 0) 0 The sum is 9 Enter end of loop display result interestRate-max (x (L/512)) MonthlyPayments L * (interestRate a)(1+interestRate /in)^(in) PUT finame + iname PUT "Aceto: acctf PUT LoanType PUT "Loan Amount You PUT "Time of Loan in years"+i PUT Interest Rate +interestRate PUT "Monthly Payments Monthly Paymeauf L=100 OENO -12 "Enter Customer First Name" Loop finame != "STOP" "Enter Customer Last Name PUT 'No Loan Account not approved for Loan "Enter Loan Type Variable Fixed Interest" GET IqaaType "Enter Loan Amount "Enter Length time of Loan in years" account-random t LoanType="Variable" Enter Customer First Name" PUT "Loan Program Ended End No interestRate Amount 1000.00 MonthlyPayments -L *(interestRate a)(1+interestRate /n)^(in) / PUT finame + name PUT "Aceto: "+ acc PUT LoadType PUT "Loan Amount +15 PUT "Time of Loan in years+f interestRate -.0933 PUT Interest Rate +interestRate PUT "Monthly Payments Monthly Paymeauf 5000.00 No Y interestRate -1045 JoanAmou 10000.00 interestRate -1625 sentinel value input sentinel-controlled loop loop Key 21 22 23 24 Point 25 26 27 } } 5.5 Controlling a Loop with User Confirmation or a Sentinel Value It is a common practice to use a sentinel value to terminate the input. The preceding example executes the loop five times. If you want the user to decide whether to continue, you can offer a user confirmation. The template of the program can be coded as follows: } You can rewrite the program given in Listing 5.4 with user confirmation to let the user decide whether to advance to the next question. char continueLoop = 'Y'; while (continueLoop == 'Y') { // Execute the loop body once Another common technique for controlling a loop is to designate a special value when reading and processing a set of values. This special input value, known as a sentinel value, signifies the end of the input. A loop that uses a sentinel value to control its execution is called a sentinel-controlled loop. 3 4 Listing 5.5 gives a program that reads and calculates the sum of an unspecified number of integers. The input 0 signifies the end of the input. Do you need to declare a new variable for each input value? No. Just use one variable named data (line 12) to store the input value, and use a variable named sum (line 15) to store the total. Whenever a value is read, assign it to data and, if it is not zero, add it to sum (line 17). LISTING 5.5 SentinelValue.java 1 2 5 // Prompt the user for confirmation System.out.print("Enter Y to continue and N to quit: "); continueLoop = input.getLine().charAt(0); 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 import java.util.Scanner; public class SentinelValue { / Main method */ public static void main(String[] args) { // Create a Scanner Scanner input = new Scanner (System.in); // Read an initial data System.out.print( "Enter an integer (the input ends if it is 0): "); int data input.nextInt (); // Keep reading data until the input is 0 int sum= 0; while (data != 0) { sum += data; // Read the next data System.out.print( 5.5 Controlling a Loop with User Confirmation or a Sentinel Value 169 "Enter an integer (the input ends if it is 0): "); data input.nextInt (); } System.out.println("The sum is " + sum); Enter an integer (the input ends if it is 0): 2 Enter Enter an integer (the input ends if it is 0) 3 Enter Enter an integer (the input ends if it is 0): 4 Enter Enter an integer (the input ends if it is 0) 0 The sum is 9 Enter end of loop display result
Expert Answer:
Related Book For
Modern Advanced Accounting In Canada
ISBN: 9781259066481
7th Edition
Authors: Hilton Murray, Herauf Darrell
Posted Date:
Students also viewed these programming questions
-
Let A, B be sets. Define: (a) the Cartesian product (A B) (b) the set of relations R between A and B (c) the identity relation A on the set A [3 marks] Suppose S, T are relations between A and B, and...
-
QUIZ... Let D be a poset and let f : D D be a monotone function. (i) Give the definition of the least pre-fixed point, fix (f), of f. Show that fix (f) is a fixed point of f. [5 marks] (ii) Show that...
-
Explain the concept of recursion in programming and provide an example of a recursive function.
-
How might one of the actors in the incident use power and politics to achieve advantage in the situation described?
-
Define the following terms in your own words. a. Active and passive sensing b. Image feature c. Object model d. Rendering model.
-
Follow the steps below to prove the LLN without using CLT. (a) Let \(X\) be a random variable with mean \(\mu\) and variance \(\sigma^{2}\). Then for any real number \(\alpha>0,...
-
Michael Roberts is a cost accountant and business analyst for Darby Design Company (DDC), which manufactures expensive brass doorknobs. DDC uses two direct cost categories: direct materials and...
-
Westeros, Inc. receives scabbards (sheath for a sword) from two different suppliers. 70 percent of its scabbards come from Knights Watch, LLC, while 30 percent come from Crow, Inc. Records indicate...
-
1. determine the taxable income if the taxpayer is a resident citizen 2. Determine the taxable income if the taxpayer is a resident alien. 3. Determine the taxable income if the taxpayer is a...
-
Choose two companies in the same industry whose financial statements are available online. Complete several financial ratios for each company and compare them. What did your analysis tell you about...
-
In the table below are the calculations of the total and average cost of an engineering equipment during eight years of service. Explain by drawing the relationship between the average annual cost...
-
Define the concept of a buffer and elucidate its significance in the preservation of biological macromolecules, particularly enzymes, within a complex biochemical milieu.
-
How have technological innovations aided the wealthy to avoid paying taxes?
-
It has been argued that "regional integration allows countries to overcome costly divisions through integrating goods, services and factors' markets, thus facilitating the flow of trade, capital,...
-
The statement that best describes the end behaviour of the graph of g(x) = x(x-3)(x+2)(x-1) is the graph extends Select one: a. upward into quadrant I and downward into quadrant III O b. downward...
-
Find the output for the following circuit? A W =? HD C D
-
If someone's Z-score for a variable was 0.67. Their score is a significant extreme score. Their score is not significant. O Their score is slightly above average. O Their score is an outlier.
-
P Co. is looking for some additional financing in order to renovate one of the companys manufacturing plants. It is having difficulty getting new debt financing because its debt-to-equity ratio is...
-
For the past 10 years, Prince Company (Prince) has owned 75,000 or 75% of the common shares of Stiff Inc. (Stiff). Elizabeth Winer owns another 20% and the other 5% are widely held. Although Prince...
-
X Company owns 80% of Y Company and uses the equity method to account for its investment. On January 1, Year 2, the investment in Y Company account had a balance of $86,900, and Y Company's common...
-
Which of the following statements are hypotheses? (a) Heavier objects fall to Earth faster than lighter ones. (b) The planet Mars is inhabited by invisible beings that are able to elude any type of...
-
A couple in a sport-utility vehicle (SUV) is traveling at 90 km/h on a straight highway. The driver sees an accident in the distance and slows down to 40 km/h in
-
Give the order of magnitude of these quantities in meters or seconds: (a) length of a football field, \((b)\) height of a mature tree, \((c)\) one week, \((d)\) one year.
Study smarter with the SolutionInn App