The importance of using braces with nested if statements. Analyze and trace the following code. (Do...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
The importance of using braces with nested if statements. Analyze and trace the following code. (Do not code it yet): import java.util.Scanner; public class IfBrackets ( public static void main(String[] args) ( // TODO Auto-generated method stub now!"); double fuelgauge = 0; now!"); System.out.println("enter the fuel gauge reading"); Scanner input= new Scanner (System.in); fuelgauge input.nextDouble(); System.out.println ("first with braces"); if (fuelgauge < 0.75) { } else { រ caution!"); if (fuelgauge < 0.25) System.out.println("fuel is very low caution!"); System.out.println("fuel over 3/4. Don't stop System.out.println("now without braces"); if (fuelgauge < 0.75) else if (fuelgauge < 0.25) System.out.println("fuel is very low System.out.println("fuel over 3/4. Don't stop Part A. Trace through the following code by hand and record your results in a trace table. Variable Value Screen Output First with Braces fuelgauge-0.1 fuelgauge-0.5 fuelgauge -0.8 part B: Now write the code in your IDE, debug, and execute. Include a snapshot of the code and execution here. part C: Compare your results in part A to the results in part B. Even if they differ, please do not change them. You will still get full credit for this task. Explain the importance of the braces and how their absence affected the results in the second part of the program. The importance of using braces with nested if statements. Analyze and trace the following code. (Do not code it yet): import java.util.Scanner; public class IfBrackets ( public static void main(String[] args) ( // TODO Auto-generated method stub now!"); double fuelgauge = 0; now!"); System.out.println("enter the fuel gauge reading"); Scanner input= new Scanner (System.in); fuelgauge input.nextDouble(); System.out.println ("first with braces"); if (fuelgauge < 0.75) { } else { រ caution!"); if (fuelgauge < 0.25) System.out.println("fuel is very low caution!"); System.out.println("fuel over 3/4. Don't stop System.out.println("now without braces"); if (fuelgauge < 0.75) else if (fuelgauge < 0.25) System.out.println("fuel is very low System.out.println("fuel over 3/4. Don't stop Part A. Trace through the following code by hand and record your results in a trace table. Variable Value Screen Output First with Braces fuelgauge-0.1 fuelgauge-0.5 fuelgauge -0.8 part B: Now write the code in your IDE, debug, and execute. Include a snapshot of the code and execution here. part C: Compare your results in part A to the results in part B. Even if they differ, please do not change them. You will still get full credit for this task. Explain the importance of the braces and how their absence affected the results in the second part of the program.
Expert Answer:
Answer rating: 100% (QA)
Step 1 Part A Variable Value fuelgauge 01 fuelgauge 05 fuelgauge 08 ExplanationPlease refer to solution in this step Step 2 123456 Part B The Java pro... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
A parent in a high tax brackets wants to gift income producing property (such as stocks and bonds) to their child, who is in a low tax bracket, in order to shift income and collectively save the...
-
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...
-
Analytics mindset Final Project 4 Gamification Part 1: Background You are the chief technology officer (CTO) of an international bank. A key component of your job is to manage risk within the bank...
-
What are conjugate faults, and what stress information do they give?
-
Use loop equations to find Vo(t),t>0 in the network shown in fig.
-
Transactions from Gravenhurst Inc.'s current year follow. Gravenhurst follows IFRS. 1. Gravenhurst Inc. thinks it should dispose of its excess land. While the carrying value is $50,000, current...
-
A nozzle for a supersonic wind tunnel is designed to achieve a Mach number of 3.0, with a velocity of \(2000 \mathrm{~m} / \mathrm{s}\), and a density of \(1.0 \mathrm{~kg} / \mathrm{m}^{3}\) in the...
-
1. What categories of costs would you expect to see in a list of MooBella start-up costs? 2. What was the mix of fundsby percentageused by MooBella to get started? 3. What are the start-up costs that...
-
Let sequence (an) be -8, -3, 2, 7, ... (a = -8) a. Find recursive formula for an. b. Find explicit (iterative) formula for an
-
1. If Bozena participates and the 401(k) earns 10 percent annually, how much will she have accumulated in 45 years (to age 67) even if her salary does not change? 2. If she does not participate and...
-
c. A nutritionist argues that the mean Diastolic pressure of vegetarian people is lower than non-vegetarians and that they should be looked at separately for better health control. Another person...
-
3. A spacecraft is observed at two moments separated 76.0 minutes. The first position vector is = 15945.34 km the second observation has a position vector: =12214.83899 + 10249.46731 km. Determine:...
-
Based on below information please answer the following questions? What is the overall relationship between the two variables in each tab? Is there a positive or negative relationship? Based on the R...
-
A proton is initially at rest. After some time, a uniform electric field is turned on and the proton accelerates. The magnitude of the electric field is 1 . 5 6 1 0 5 N / C . ( a ) What is the speed...
-
1.Find the total monthlypayment, including taxes and insurance. Mortgage : 89,400 Interest Rate : 3.5 % Term of Loan : 15 years Annual Taxes : 906 Annual Insurance : 333 The total monthly payment is?...
-
Five years ago, Weisu bought an 8-year, 7% semi-annual coupon bond. Face Value= 1000. If the yield to maturity (compounded semi-annually) is 5.5%, what is the bonds duration today? What does this...
-
Currently your own and farm 950 acres of wheat. Your neighbor Frank has offered you the opportunity to rent 300 acres of his farm for $55 per acre. You expect Frank's operating costs to be 10% higher...
-
The rate at which the temperature of an object changes is proportional to the difference between its own temperature and the temperature of the surrounding medium. Express this rate as a function of...
-
If you are familiar with structured exception handling, as provided in Ada, C++, Java, C#,ML, Python, or Ruby, consider how this mechanismrelates to the issue of scoping. Conventionally, a raise or...
-
Write an attribute grammar, based on the following context-free grammar, that accumulates jump code for Boolean expressions (with short-circuiting) into a synthesized attribute code of condition, and...
-
As noted in Figure 6.1, Fortran and Pascal give unary and binary minus the same level of precedence. Is this likely to lead to nonintuitive evaluations of certain expressions? Why or why not? Figure...
-
Is leadership synonymous with management, or is leading just one of the many things that a manager does? In what ways are they the same or different?
-
Explain Blake and Moutons Leadership Grid in relationship to previous leadership research.
-
Write a description of an effective manager. Write words that you would use to describe an effective leader. When you review your list, consider the differences and similarities in your adjectives....
Study smarter with the SolutionInn App