Answered step by step
Verified Expert Solution
Question
1 Approved Answer
For this section, many methods are given. They however contain errors. Some errors are syntax error while others are logical error. The main method contains
For this section, many methods are given. They however contain errors. Some errors are syntax error while others are logical error. The main method contains test that will execute the two other methods and verify if they work properly.
The method isPrime checks if the number received as an argument is a prime number. A prime number is a number bigger then that can only be divided by or itself.
The Fibonacci method takes a number as argument and returns the value at this position in the Fibonacci series. In the Fibonacci series, each number is the sum of the two preceding position in the series. The position has the value and the position has the value This table describes the series:
position
Value
public class Q
public static void mainString args
boolean test new boolean;
test for isPrime
testisPrime false;
testisPrime true;
testisPrime true;
testisPrime false;
testgetFibonacci;
testgetFibonacci;
testgetFibonacci;
testgetFibonacci;
boolean testFlagtrue;
for int i ; i test.length; i
iftesti
System.out.printlntest i passed";
else
System.out.printlntest i failed";
testFlag false;
iftestFlag
System.out.printlnAll tests are successful";
else
System.out.printlnNot all tests are successful";
method that determines if the number x is prime
public static boolean isPrimeint x
boolean prime true;
ifx
prime ;
ifx
prime ;
int i ;
whileprime && x i
ifx i
prime false;
i;
return prime;
returns the fibonacci number at the position in parameter
public static int getFibonacciint position
int num ;
int num;
int fibonacci ;
if position
fibonacci ;
else if position
fibonacci ;
else
for int i ; ;
fibonacci ;
num num;
num fibonacci;
return num;
You need to correct the code above until all tests pass successfully and that you get the following output message:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started