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

Can someone help with this JAVA program??? The tribonacci sequence is a generali

ID: 3689307 • Letter: C

Question

Can someone help with this JAVA program???

The tribonacci sequence is a generalization of the fibonacci sequence, where the n h term in the sequence is given by the following recurrence relation T(n) = T(n - 1) + T(n - 2) + T(n - 3) Create a class GeneralTribonacci. At a minimum, your class should have the following methods: genTrib that takes four numbers: the first three numbers in the sequence, as well as an index n. This should return the n h term in the given sequence. If the first three numbers are given in non-ascending order, or if the index given is less than 0, this should throw a (runtime) SequenceStartException A main method, that asks the user to input the beginning of the tribonacci sequence as well as an index n, then prints the n h term in the sequence. Enter the first three terms to start: 0 1 1 Enter the index of the term to finds 5 Term 5 of the sequence 0, 1, 1,... is 7 You should experiment with the running time of your algorithm, in terms of the index. E.g. how fast can it find the 10 h term? How about the 40 h? Experiment further to see if you can find a faster algorithm with the same result.

Explanation / Answer

/**
* Java program called Tribonacci to display the index of Tribonacci numbers
* F(n), where F(n) = F(n–1) + F(n–2) + F(n–3)
*/

import java.util.*;

public class Tribonacci {
  
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the first three terms to start: ");
int f1 = sc.nextInt();
int f2 = sc.nextInt();
int f3 = sc.nextInt();
System.out.print("Enter the index of the termto find: ");
int fn = sc.nextInt();


Tribonacci aTribonacci = new Tribonacci();
int fn_value = aTribonacci.gentrip(fn,f1,f2,f3);
System.out.println("Term " + fn + " of the sequence " + f1 + ", " + f2 + ", " + f3 + ",... is " + fn_value );
}
  
public int gentrip(int fbn, int fb1, int fb2, int fb3 )
{
int result = 0;
int i = 0;
if (fbn < 0 || fb1 < 0 || fb2 < 0 || fb3 < 0) {
throw new RuntimeException("Not Valid");
}

else if(fb1 > fb2 || fb2 > fb3 || fb1 > fb3){
throw new RuntimeException("Not Valid");
}
  

while(result < fbn) {
result = fb1 + fb2 + fb3;
fb1 = fb2;
fb2 = fb3;
fb3 = result;

}
  
return result;
}
  
}