The following code is poorly structured: Rewrite it so that it has a better structure and avoids
Question:
The following code is poorly structured:
Rewrite it so that it has a better structure and avoids redundancy. You may wish to introduce a method to help capture redundant code.
Transcribed Image Text:
Scanner console = new Scanner (System.in); System.out.print ("How much will John be spending? "); double amount = console.nextDouble (); System.out.println (); int numBills1 (int) (amount / 20.0); %3D if (numBills1 * 20.0 < amount) { numBills1++; } System.out.print ("How much will Jane be spending? "); amount = console.next Double (); System.out.println (); int numBills2 = (int) (amount / 20.0); if (numBills2 * 20.0 < amount) { numBills2++; System.out.println ("John needs " + numBills1 + bills"); System.out.println ("Jane needs " + numBills2 + " bills");
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 72% (11 reviews)
Refactored code to reduce redundancy Prompts for two peoples m...View the full answer
Answered By
Branice Buyengo Ajevi
I have been teaching for the last 5 years which has strengthened my interaction with students of different level.
4.30+
1+ Reviews
10+ Question Solved
Related Book For
Building Java Programs A Back To Basics Approach
ISBN: 9780135471944
5th Edition
Authors: Stuart Reges, Marty Stepp
Question Posted:
Students also viewed these Computer science questions
-
The following code is not robust against invalid user input. Describe how to change the code so that it will not proceed until the user has entered a valid age and grade point average (GPA). Assume...
-
What is wrong with the following code fragment? Rewrite it so that it produces correct output.
-
Summarize three reasons why a company may wish to introduce e-commerce.
-
Dylan Flaherty, marketing clerk for TipTop Marketing Agency, recorded the following information for last year: He would like to be able to estimate customer service costs using the number of...
-
A Carnot heat engine is operating between a source at TH and a sink at TL. If it is desired to double the thermal efficiency of this engine, what should the new source temperature be? Assume the sink...
-
Write a program that reads and stores a series of integers and then computes the sum of the first N integers. First ask for N, then read the values into a vector, then calculate the sum of the first...
-
A variable mesh screen produces a linear and axisymmetric velocity profile as indicated in Fig. P5.66 in the airflow through a 2 -ft-diameter circular cross-sectional duct. The static pressures...
-
Big City Gymnastics (BCG or the Club) is a not-for-profit organization that operates a gymnastics club. BCG was incorporated in May 1983 and has operated the Club at the same facility since that...
-
Fresh Fruit, Inc. has a $3,000 par value bond that is currently selling for $1,457. It has an annual coupon rate of 14.86 percent, paid semiannually, and has 22-years remaining until maturity. What...
-
On October 12, Belleville Co. borrowed cash from Texas Bank by issuing a 30-day note with a face amount of $70,000. a. Determine the proceeds of the note, assuming the note carries an interest rate...
-
Write a method called average that takes two integers as parameters and returns the average of the two integers.
-
Write the method called printTriangleType referred to in Self-Check Problem 25. This method accepts three integer arguments representing the lengths of the sides of a triangle and prints the type of...
-
If the top of your automobile tire is moving with a speed of v, what is the reading of your speedometer?
-
What is ethnocentrism?
-
This chapter explains one reason you might choose to make a request in person rather than by email: It may be more difficult for your audience to refuse the request. What are other reasons you may...
-
Why should you personalize a thank-you message?
-
Under what circumstances is it a good idea to accommodate (or give in) during a conflict?
-
What design features can you use in a report to enhance its visual appeal?
-
An electron and a proton, starting from rest, are accelerated through an electric potential difference of the same magnitude. In the process, the electron acquires a speed ve, while the proton...
-
On April 29, 2015, Auk Corporation acquires 100% of the outstanding stock of Amazon Corporation (E & P of $750,000) for $1.2 million. Amazon has assets with a fair market value of $1.4 million (basis...
-
Dr. Amongus claims that a (2,4) tree storing a set of entries will always have the same structure, regardless of the order in which the entries are inserted. Show that he is wrong.
-
An alternative way of performing a split at a node w in a (2,4) tree is to partition w into w and w, with w being a 2-node and w a 3-node. Which of the keys k 1 , k 2 , k 3 , or k 4 do we store at ws...
-
The rules for a deletion in an AVL tree specifically require that when the two subtrees of the node denoted as y have equal height, child x should be chosen to be aligned with y (so that x and y are...
-
Give the worst-case Big O running time of this function and explain in detail how you arrived at this answer. public static int f1(int [] a) { int maxSum = 0, this Sum = 0; for(int j = 0; j maxSum )...
-
1. Explain how to set up user and group account in the active directory, in addition, please explain how to have file and folders sharing. Please give examples. 2. List 3 situations that printers in...
-
8=0 for i 1 to n MAT MAP Give an estimate for the number of operations used in this segment of an algorithm. Use your estimate to find the time complexity. 20 City Tec MA for j1 tonti =s+1 if i = j...
Study smarter with the SolutionInn App