Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

java Program Specifications: you have to submit JollyJumpers.java and TestJollyJ

ID: 3550546 • Letter: J

Question

java Program Specifications:
you have to submit JollyJumpers.java and TestJollyJumpers.java

JOLLY JUMPERS
A sequence of n integers (n > 0) is called a jolly jumper if the absolute values of the differences between successive elements take on all possible values 1 through n - 1. For instance,

1 4 2 3

is a jolly jumper, because the absolute differences are 3, 2, and 1, respectively. Write a program to determine whether each of a number of sequences is a jolly jumper.
Input
Each line of input contains n integers (where n > 1 and n < 500) representing the sequence. Your program should take multiple inputs (i.e., multiple sequences) as input at the same time and calculate the output for all of them.
Output
For each line of input generate a line of output saying

Explanation / Answer

/* OUTPUT
Jolly
Not jolly
Not jolly
Not jolly
Jolly
*/



import java.util.*;

public class JollyJumpers
{
private int[] sequence;
public JollyJumpers(int[] array)
{
sequence = new int[array.length];
for(int i=0; i<array.length; i++)
sequence[i] = array[i];
}
public boolean is_jolly_sequence()
{
int k = Math.abs(sequence[0] - sequence[1]);
for(int i=1; i<sequence.length-1; i++)
{
int next_difference = Math.abs(sequence[i] - sequence[i+1]);
if(Math.abs(next_difference-k)==1)
k = next_difference;
else
return false;
}
return true;
} //end bool method.
}

public class TestJollyJumpers
{
public static void main(String[] args)
{
String[] line_of_numbers = new String[50];
int count = 0;
Scanner in = new Scanner(System.in);
System.out.println("Enter sequence :");
while(in.hasNext())
{
line_of_numbers[count++] = in.nextLine();
}
for(int i=0; i<count; i++)
{
String[] tokens = line_of_numbers[i].split("\s");
int[] int_array = new int[tokens.length];
for(int k=0; k<int_array.length; k++)
int_array[k] = Integer.parseInt(tokens[k]);
JollyJumpers JJ = new JollyJumpers(int_array);
System.out.println((JJ.is_jolly_sequence()?"Jolly":"Not jolly"));
}
}
}