In this program you will prompt the user to enter a positive number greater than zero and obtain the cube root of that number using binary search. If the user does not enter a positive number you will prompt him repeatedly to enter a positive number. You will express the cube root of the number correct to 4 places of decimal. You will give the absolute value of the difference between your calculated value and the actual value obtained from Math.pow() correct to 8 places of decimal. You must use System.out.printf() to do your formatting.
Here is a sample scenario for the program:
Enter a positive number: -3 Enter a positive number: -5 Enter a positive number: 6 Cube root of 6: 1.8171 Difference of Calculated Cube Root - Actual Cube Root: 0.00002059
You do not need an array to do this problem. You will have variables to define lo, hi, and mid. There will be two versions of the binary search - one for numbers between 0 and 1 and the other for numbers greater than 1.
The class that you will be writing will be called CubeRoot. You can use methods in your class. We will be looking at good documentation, and adherence to the coding convention mentioned below. Your file CubeRoot.java will have the following header:
/* File: CubeRoot.java Description: Student Name: Student UT EID: Course Name: CS 312 Unique Number: Date Created: Date Last Modified: */
There is a modification that I would like to make to the standard coding conventions. Please align the opening and closing braces vertically so that you can easily make out the blocks of code. For example:
Do this: if ( x > 5 ) { a = b + c; } Not this: if ( x > 5 ) { a = b + c; }
Use the Canvas program to submit your CubeRoot.java file. We should receive your work by 11 PM on Sunday, 12 Jul 2015. There will be substantial penalties if you do not adhere to the guidelines.