Some of the outcome is correct but before it finished it show me error in need help with that.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

import components.naturalnumber.NaturalNumber;
import components.naturalnumber.NaturalNumber2;
import components.simplewriter.SimpleWriter;
import components.simplewriter.SimpleWriter1L;

/**
* Program with implementation of {@code NaturalNumber} secondary operation
* {@code root} implemented as static method.
*
* @author Mati Desissa
*
*/
public final class NaturalNumberRoot {

/**
* Private constructor so this utility class cannot be instantiated.
*/
private NaturalNumberRoot() {
}

/**
* Updates {@code n} to the {@code r}-th root of its incoming value.
*
* @param n
* the number whose root to compute
* @param r
* root
* @updates n
* @requires r >= 2
* @ensures n ^ (r) <= #n < (n + 1) ^ (r)
*/
public static void root(NaturalNumber n, int r) {
assert n != null : "Violation of: n is not null";
assert r >= 2 : "Violation of: r >= 2";

double lowEnough = 0;
double tooHigh = n.toInt();
double power = 1.0 / r;
double value = Math.pow(tooHigh, power);
double guess = (1.0) * tooHigh / 2;

while ((int) guess != (int) value) {
if (guess > value) {
tooHigh = guess;
} else {
lowEnough = guess;
}
guess = (1.0) * (lowEnough + tooHigh) / 2;
}
NaturalNumber k = new NaturalNumber2((int) guess);
n.copyFrom(k);

}

/**
* Main method.
*
* @param args
* the command line arguments
*/
public static void main(String[] args) {
SimpleWriter out = new SimpleWriter1L();

final String[] numbers = { "0", "1", "13", "1024", "189943527", "0",
"1", "13", "4096", "189943527", "0", "1", "13", "1024",
"189943527", "82", "82", "82", "82", "82", "9", "27", "81",
"243", "143489073", "2147483647", "2147483648",
"9223372036854775807", "9223372036854775808",
"618970019642690137449562111",
"162259276829213363391578010288127",
"170141183460469231731687303715884105727" };
final int[] roots = { 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 15, 15, 15, 15, 15,
2, 3, 4, 5, 15, 2, 3, 4, 5, 15, 2, 2, 3, 3, 4, 5, 6 };
final String[] results = { "0", "1", "3", "32", "13782", "0", "1", "2",
"16", "574", "0", "1", "1", "1", "3", "9", "4", "3", "2", "1",
"3", "3", "3", "3", "3", "46340", "46340", "2097151", "2097152",
"4987896", "2767208", "2353973" };

for (int i = 0; i < numbers.length; i++) {
NaturalNumber n = new NaturalNumber2(numbers[i]);
NaturalNumber r = new NaturalNumber2(results[i]);
root(n, roots[i]);
if (n.equals(r)) {
out.println("Test " + (i + 1) + " passed: root(" + numbers[i]
+ ", " + roots[i] + ") = " + results[i]);
} else {
out.println("*** Test " + (i + 1) + " failed: root("
+ numbers[i] + ", " + roots[i] + ") expected <"
+ results[i] + "> but was <" + n + ">");
}
}

out.close();
}

}

 

Some of the outcome is correct but before it finished it show me error in need help with that.

The image shows the results of a series of root calculations performed in a Java program. Each line indicates a test, whether it passed or failed, the inputs for the root calculation, and the result.

- Tests 1 to 8 demonstrate successful calculations using the `root` function with varying inputs.
- Test 9 failed because the expected output was 16, but the function returned 15 instead.
- Tests 10 to 26 continued with successful calculations.

The bottom section displays an error message indicating an `AssertionError` due to a violation of `this <= Integer.MAX_VALUE`. The error occurred in the `NaturalNumberRoot` class within the specified lines of code, suggesting an overflow or limit breach in handling integer values within the program.
Transcribed Image Text:The image shows the results of a series of root calculations performed in a Java program. Each line indicates a test, whether it passed or failed, the inputs for the root calculation, and the result. - Tests 1 to 8 demonstrate successful calculations using the `root` function with varying inputs. - Test 9 failed because the expected output was 16, but the function returned 15 instead. - Tests 10 to 26 continued with successful calculations. The bottom section displays an error message indicating an `AssertionError` due to a violation of `this <= Integer.MAX_VALUE`. The error occurred in the `NaturalNumberRoot` class within the specified lines of code, suggesting an overflow or limit breach in handling integer values within the program.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY