Java Coding Problem


2. Write a program given a number in any base (base 2 to base 16) and rounds that number to a

specified place. Rounding up occurs when the digit to the right of the rounding place divided by the

number’s base is 0.5 or more. For example, 0.12468 rounded to 3 places is 0.125 because 6 divided by

8 is greater than 0.5; when rounded to 2 places, it’s 0.13 because 4 divided by 8 is 0.5; and it’s 0.1

when rounded to 1 place because 2 divided by 8 is less than 0.5. Input from the keyboard three (3)

values: a number, the base of that number, and the number of places to be rounded. Assume the

numbers entered will have at least one digit to the right of the place to be rounded and at least one digit

to the left of the decimal point. Also, assume the rounding place will never be 0 (round a whole

number). For each input, output to the screen the number rounded to the given number of places. Do

not output any digits beyond the rounded place. Finally, ask the user if he/she wishes to run the

program again (check case). Refer to the sample output below.

Sample Run:

Enter the value: 0.11101

Enter the base of the number: 2

Number of decimal places to round: 4

The resulting value: 0.1111

Run again (Y/N): y

Enter the value: 35.4321

Enter the base of the number: 7

Number of decimal places to round: 3

The resulting value: 35.432

Run again (Y/N): N