Question: JAVA Declare new class SuperFibs Super Fibonacci numbers are defined as follows: the first 3 numbers are: 1st is 0, 2nd is 1, 3rd

JAVA Declare new class SuperFibs JAVA Declare new class SuperFibs "Super Fibonacci" numbers are defined as follows:

"Super Fibonacci" numbers are defined as follows: the first 3 numbers are: 1st is 0, 2nd is 1, 3rd is 1. Every next number is the sum of *three* of the previous numbers, so the 4th number is 0+1+1=2, for example. You must NEVER recompute a "Super Fibonacci" number that you've already computed. Also add a property int stepsCount. It will start at 1 when the object is instantiated and then be incremented by 1 every time your program has to make a set of 3 recursive calls to compute a "Super Fibonacci" number as opposed to obtaining it from cache (Map). If a number is obtained from the cache stepsCount is not incremented. For example, after the following code is executed StepsCount should be at the first 3 numbers are: 1st is 0, 2nd is 1, 3rd

class SuperFibs{ private Map cache = new HashMap(); public static int stepsCount = 1; | public long getNthFib(int n) { //if n throw IndexOutOfBoundsException public static void main(String[] args) { SuperFibs f = new SuperFibs(); System.out.printf("1 : %d, steps %d", f.getNthFib( n: 0), SuperFibs.stepsCount); System.out.println(); System.out.printf("2 : %d, steps %d", f.getNthFib( n: 1), SuperFibs.stepsCount); System.out.println(); System.out.printf("3: %d, steps %d", f.getNthFib( n: 2), SuperFibs.stepsCount); System.out.println(); System.out.printf("4 : %d, steps %d", f.getNthFib( n: 3), SuperFibs.stepsCount); System.out.println(); System.out.printf("5 : %d, steps %d", f.getNthFib( n: 4), SuperFibs.stepsCount); System.out.println(); System.out.printf("6 : %, steps %d", f.getNthFib( n: 5), SuperFibs.stepsCount); System.out.println(); System.out.printf("7 : %d, steps %d", f.getNthFib( n: 6), SuperFibs.stepsCount); System.out.println(); System.out.printf("8 : %d, steps %d", f.getNthFib( n: 200), SuperFibs.stepsCount); } 1:0, steps 1 2 : 1, steps 1 3:1, steps 1 4: 2, steps 2 5 : 4, steps 3 6: 7, steps 4 7:13, steps 5 8: 8475542707715235980, steps 199

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!