We have the following code: Make an edit to this code. What variable can we globalize to
Question:
We have the following code:
Make an edit to this code. What variable can we globalize to simplify the methods? You can also change the method definitions.
Note you don’t need to worry about how we came up with the roundUp() and roundDown() method definitions. Just know that they do the following:
● roundUp() : rounds up if decimal point is 5 or greater. For example, 10.5 will round to 11.
● roundDown() : rounds down regardless of the number. For example, 10.5 will round to 10.
Transcribed Image Text:
public class Rounding Calculator { } public static void main(String[] args) { double sum = add (10.5d, 9.0d, true); System.out.println("sum: " + sum); double subtraction = subtract (10.5d, 9.0d, true); System.out.println("subtraction: " + subtraction); double product = multiply(10.5d, 9.0d, true); System.out.println("product: + product); double division = divide (10.5, 9.0d, true); System.out.println("division: " + division); } public static double add(double x, double y, boolean roundup) { double sum = x + y; if (roundUp == true) { return roundUp(sum); } return roundDown (sum); } public static double subtract(double x, double y, boolean roundUp) { double subtraction = x - y; if (roundUp == true) { return roundUp(subtraction); } return roundDown (subtraction); } public static double multiply(double x, double y, boolean roundup) { double product = x = y; if (roundUp == true) { return roundUp(product); } public static double divide (double x, double y, boolean roundup) { double divide x / y; if (roundUp == true) { return roundup (divide); } return roundDown (divide); } public static double roundup (double number) { return Math.round(number); } public static double roundDown(double number) { return Math.floor(number);
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 100% (1 review)
The code youve presented includes several methods in a RoundingCalculator class that perform arithmetic operations with an additional parameter to dec...View the full answer
Answered By
Keziah Thiga
I am a self motivated financial professional knowledgeable in; preparation of financial reports, reconciling and managing accounts, maintaining cash flows, budgets, among other financial reports. I possess strong analytical skills with high attention to detail and accuracy. I am able to act quickly and effectively when dealing with challenging situations. I have the ability to form positive relationships with colleagues and I believe that team work is great key to performance. I always deliver quality, detailed, original (0% plagirism), well-researched and critically analyzed papers.
4.90+
1504+ Reviews
2898+ Question Solved
Related Book For
Question Posted:
Students also viewed these Computer science questions
-
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...
-
Dyson: Solving Customer Problems in Ways They Never Imagined From a head-on perspective, it has a sleek, stunning stainless steel design. With wings that extend downward at a 15-degree angle from its...
-
Investigate the challenges and solutions associated with managing I/O devices in a multitasking operating system, including topics such as device drivers, interrupt handling, DMA (Direct Memory...
-
A taxpayer has qualified business income of $50,000 from partnership A and a qualified business loss of $30,000 from partnership B. Wages allocable to the taxpayers interest in partnership A were...
-
Express each force in Cartesian vector form. Given: F1 = 400 lb F2 = 600 lb θ1 = 45 deg θ2 = 60 deg θ3 = 60 deg θ4 = 45 deg θ5 = 30 deg F2
-
Again, consider the change series of the US monthly unemployment duration from February 1948 to August 2017. Fit a time-varying coefficient AR model to the data. Perform model checking and write down...
-
(NPV and IRR) You are considering a project whose cash flows are given below: a. Calculate the present value of the future cash flows of the project. b. Calculate the projects net present value. c....
-
On August 1, 2018, Brooke Kline established Western Realty. Brooke completed the following $39,750 transactions during the month of August: A. Opened a business bank account with a deposit of $35,000...
-
Jim Company bought a machine for $ 2 4 , 2 4 0 with an estimated life of 5 years. The residual value of the machine is $ 5 , 2 0 0 . This machine is expected to produce 1 1 2 , 0 0 0 units. In year 1...
-
Lets take a look at the CleanCalculator code with the global variable name . Make this variable private and create a public method that gives access to the value of name. Change CleanCalculatorImpls...
-
Is your company able to engage in outsourcing? If so, what do you see as the pros and cons of outsourcing?
-
What is the goal of line balancing? What happens if a line is unbalanced?
-
Identify the sentence below in which the subject and verb agree. Selected answer will be automatically saved. For keyboard navigation, press up/down arrow keys to select an answer. a Neither Gina nor...
-
04 Network efficiency Yellow Balloon and Toys LLC (YBT) is a toy manufacturing company. They are providing toy to more than 100 different Toy retail stores in the region. The company has 700...
-
The following information is from Ellerby Company's comparative balance sheets. At December 31 Furniture Accumulated depreciation-Furniture Current Year $ 154,500 (96,200) Prior Year $ 214,500...
-
Clarington issued 15 year bonds in the amount of $500 000. Interest on the bonds is 2.2% payable annually. What is the promised payment at the end of each year?
-
Write program in C++ to print a welcome text in a separate line. 2. Write program in C++ to print the sum of two numbers 3. Write program in C++ to find Size of fundamental data types. Consider the...
-
Discuss how the baseline accounting system model corresponds to the value chain shown inFigure. Make Sell Support Customers ChainVendors Purchase Accounting System Purchasing Payroll Cycle Sales...
-
The trade-off theory relies on the threat of financial distress. But why should a public corporation ever have to land in financial distress? According to the theory, the firm should operate at the...
-
Use a friend function to overload the multiplication operator for the Stonewt class; have the operator multiply the double value by the Stone value.
-
Does a nonmember function have to be a friend to access a classs members?
-
What are the differences between a friend function and a member function?
-
Punyain Company acquired Sallsap Corporation on January 1 , 2 0 X 1 , through an exchange of common shares. All of Sallsap's assets and llabilities were immediately transferred to Punyain, which...
-
( a ) Prepare the adjusting entries for items i to v above ( b ) Prepare the statement of profit or loss for the year ended 3 1 Dec 2 0 x 0 and the appropriation of profit for the partnership....
-
Goed Building Company located in Cincinnati Ohio borrowed $ 3 5 0 , 0 0 0 cash from USBank. The terms of the note were: 1 0 - year, 8 . 5 % installment note requiring equal payments each June 3 0 of...
Study smarter with the SolutionInn App