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

We have the following code: 

public class Rounding Calculator { } public static void main(String[] args) {

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.  

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);

Step by Step Solution

3.55 Rating (166 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

The code youve presented includes several methods in a RoundingCalculator class that perform arithmetic operations with an additional parameter to dec... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Introduction Java Program Questions!