Learning debugging is important if you like to be a programmer. To verify a program is...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Learning debugging is important if you like to be a programmer. To verify a program is doing what it should, a programmer should know the expected (correct) values of certain variables at specific places of the program. Therefore make sure you know how to perform the instructions by hand to obtain these values. Remember, you should master the technique(s) of debugging. Create a new project Assignment02 in NetBeans and copy the following program into a new Java class. The author of the program intends to find the sum of the numbers 4, 7 and 10. public class Assignment02Q1a { public static void main(String[] args) { int from = 4; } int to = 10; int sum= 0; for (int i-from; i<to; i++) { sum += i; } System.out.println("The sum is "+sum); (i) Run the program. What is the output? (ii) What is the expected value of sum just before the for loop is executed? // (1) // (2) (iii) Write down the three expected intermediate sums after the integers 4, 7 and 10 are added one by one (in the given order) to an initial value of zero. (iv) Since we have only a few executable statements here, the debugging is not difficult. Insert a System.out.println() statement just after the statement indicated by the comment "// (2)" to print out sum. What are the values of sum printed (press Ctrl-C to stop the program if necessary)? (v) What modification(s) is/are needed to make the program correct? NetBeans allows you to view values of variables at specific points (called break points). This saves you the efforts of inserting/removing println() statements. Again, you must know the expected (correct) values of those variables at the break points. If you like, you can try to explore the use break points yourself. Learning debugging is important if you like to be a programmer. To verify a program is doing what it should, a programmer should know the expected (correct) values of certain variables at specific places of the program. Therefore make sure you know how to perform the instructions by hand to obtain these values. Remember, you should master the technique(s) of debugging. Create a new project Assignment02 in NetBeans and copy the following program into a new Java class. The author of the program intends to find the sum of the numbers 4, 7 and 10. public class Assignment02Q1a { public static void main(String[] args) { int from = 4; } int to = 10; int sum= 0; for (int i-from; i<to; i++) { sum += i; } System.out.println("The sum is "+sum); (i) Run the program. What is the output? (ii) What is the expected value of sum just before the for loop is executed? // (1) // (2) (iii) Write down the three expected intermediate sums after the integers 4, 7 and 10 are added one by one (in the given order) to an initial value of zero. (iv) Since we have only a few executable statements here, the debugging is not difficult. Insert a System.out.println() statement just after the statement indicated by the comment "// (2)" to print out sum. What are the values of sum printed (press Ctrl-C to stop the program if necessary)? (v) What modification(s) is/are needed to make the program correct? NetBeans allows you to view values of variables at specific points (called break points). This saves you the efforts of inserting/removing println() statements. Again, you must know the expected (correct) values of those variables at the break points. If you like, you can try to explore the use break points yourself.
Expert Answer:
Answer rating: 100% (QA)
Certainly I can help you with this debugging exercise Lets go through the questions one by one i Run ... View the full answer
Related Book For
Systems Analysis and Design
ISBN: 978-1305494602
11th Edition
Authors: Scott Tilley, Harry J. Rosenblatt
Posted Date:
Students also viewed these programming questions
-
What role do authentic leaders play in cultivating trust, transparency, and ethical integrity, fostering enduring relationships and sustainable organizational cultures based on authenticity and...
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
The Crazy Eddie fraud may appear smaller and gentler than the massive billion-dollar frauds exposed in recent times, such as Bernie Madoffs Ponzi scheme, frauds in the subprime mortgage market, the...
-
Based on your reading of the rules of Professional Code of Conduct as given by AICPA, which part of the code did the accountants of Enron, Waste Management or Wells Fargo have violated and how about...
-
The profit P (in hundreds of dollars) that a company makes depends on the amount x (in hundreds of dollars) the company spends on advertising according to the model P = 230 + 20x 0.5x2. What...
-
Visit the Web site of Canon (usa.canon.com). How does Canon segment its markets, such as geographic, product related, demographic, or brand loyalty? Does the firm use more than one method of product...
-
Which continents are most at risk from lack of food security?
-
On January 1, 2013, Heckert Company purchases a controlling interest in Aker Company. The following information is available: a. Heckert Company purchases 1,600 shares of Aker Company outstanding...
-
Hypothetically, let's say the New York Jets believe that the injury to Aaron Rodgers constituted a career ending injury pursuant to an exit clause in the contract and Aaron Rodgers argued that his...
-
Explain which transportation mode would probably be most suitable for shipping the following goods to a large Los Angeles department store: a. 300 pounds of Maine lobster. b. 15 pounds of...
-
Decontaminate the messages that follow the Guidelines by rewriting them in a way that makes them whole (separate out each type of relevant expression). You can fill in details, if needed, to make...
-
Explain how digital platforms can be used to increase market penetration in existing markets and develop new markets.
-
Perform a demand analysis for e-commerce services for a product sector and geographical market of your choice.
-
Distinguish between social media marketing, inbound and content marketing.
-
Why is it important to understand conversion marketing models?
-
How can the Internet be used to support the different stages of the buying process?
-
17. Four circles of radius r1 are inscribed inside a square of side 4r1 as shown in the diagram below. (a) What is the radius r2 of the largest circle that can fit in the space at the centre of the...
-
Use the graphs of f and g to graph h(x) = (f + g) (x). To print an enlarged copy of the graph, go to MathGraphs.com. 1. 2. y 24 8. 2. -2 -2 4 6
-
Is this the best time to schedule a post-implementation evaluation? Why or why not? Are there other options? What are they? Victorian Creations specializes in the reproduction of furniture from the...
-
Draw a context diagram and a diagram 0 DFD that represents the information system at a typical library.
-
1. Review the organization chart you prepared in Chapter 1 and determine who should be on the JAD team, and why. Also, how will you create a sense of team ownership from the start? 2. You may be...
-
What is meant by a cap and floor?
-
What is the impact on interest rate risk of including a cap and/or floor in the coupon structure?
-
The pricing expression for a risky floater can be thought of as possessing two components. Explain.
Study smarter with the SolutionInn App