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

in java by eclipse IDE pls answer and screenshot results then upload all files i

ID: 3751886 • Letter: I

Question

in java by eclipse IDE pls answer and screenshot results then upload all files in Google drive and sent me link
----------------------------

2 is 1 CSC 212 Programming Assignment # 0 Warm Up Due date: 24/09/2018 This is an individual assignment. This assignment is optional. The assignment must be submitted to Web-CAT Guidelines This assignment consists of two independent parts 1. Write a method that counts the number of Fibonacci numbers that are less or equal a given number . Your method ust work even for very large values of n The Fibonacci sequence is defined as: Method signature: public static int nbFibLeqlong n) Example 1. nbFibLeg(1) should return 2, nbFibLeg(10) should return 6 2. We want to implement a generic array class having the following interface public interface MyArray

Explanation / Answer

import java.util.Scanner;

// Class Fibonacci definition

public class Fibonacci

{

// Static method to return number of fibonacci number less than or equals to n

public static int nbFibLeq(long n)

{

// Initializes the variables

int first = 1, second = 0, third = 0;

// Sets the counter to -1

int counter = -1;

// Loops till n

while(third <= n)

{

// Increase the loop counter by one

counter++;

// Adds the first and second and stores it in third

third = first + second;

// Assigns second value to first

first = second;

// Assigns third value to second

second = third;

}// End of while loop

// Returns the counter

return counter;

}// End of method

// main method definition

public static void main(String[] args)

{

// To store number

int no;

// Scanner class object created

Scanner sc = new Scanner(System.in);

// Accepts a number

System.out.print(" Enter a number to count number of fibonacci numbers: ");

no = sc.nextInt();

// Call the method and displays the count

System.out.println(" Number of fibonacci numbers less than or equals to "

+ no + " is: " +nbFibLeq(no));

}// End of main method

}// End of class

Sample output 1:


Enter a number to count number of fibonacci numbers: 1

Number of fibonacci numbers less than or equals to 1 is: 2

Sample output 2:

Enter a number to count number of fibonacci numbers: 10

Number of fibonacci numbers less than or equals to 10 is: 6

------------------------------------------------------------------------------------------------------------

package ClassProg;

// Defines an interface MyArray of type template

public interface MyArray <T extends Comparable<T>>

{

// Return the element at position i

T get(int i);

// Set the element at position i

void set(int i, T e);

// Return the index of smallest element in the array (index of first occurrence returned)

int min();

// Return the index of largest element in the array (index of first occurrence returned)

int max();

// Return the number of elements largest or equal e1 and smallest or equal e2

int nbBetween(T e1, T e2);

}// End of interface

------------------------------------------------------------------------------------------------------------------------------------------

package ClassProg;

// Defines a class MyArrayFactory

public class MyArrayFactory

{

// Creates and return an array of size n

public static <T extends Comparable<T>> MyArray<T> getMyArray(final int n)throws Exception

{

// Creates an anonymous class and overrides the interface methods

MyArray <T>obj = new MyArray<T>()

{

// Creates an template array of size n

T array[] = (T[]) new Integer[n];

// Return the element at position i

public T get(int i)

{

return array[i];

}// End of method

// Set the element at position i

public void set(int i, T e)

{

array[i] = e;

}// End of method

// Return the index of smallest element in the array (index of first occurrence returned)

public int min()

{

// Stores the zero index position value as minimum value

T min = array[0];

// Stores the zero index position as minimum index position

int index = 0;

// Loops till length of the array

for(int x = 1; x < array.length; x++)

{

// Checks if the current index position value is less than the earlier minimum

if(array[x].compareTo(min) < 0)

{

// Update the minimum to current index position value

min = array[x];

// Sets the current loop value as minimum index position

index = x;

}// End of if condition

}// End of for loop

// Returns the index

return index;

}// End of method

// Return the index of largest element in the array (index of first occurrence returned)

public int max()

{

// Stores the zero index position value as maximum value

T max = array[0];

// Stores the zero index position as maximum index position

int index = 0;

// Loops till length of the array

for(int x = 1; x < array.length; x++)

{

// Checks if the current index position value is greater than the earlier minimum

if(array[x].compareTo(max) > 0)

{

// Update the maximum to current index position value

max = array[x];

// Sets the current loop value as maximum index position

index = x;

}// End of if condition

}// End of for loop

// Returns the index

return index;

}// End of method

// Return the number of elements largest or equal e1 and smallest or equal e2

public int nbBetween(T e1, T e2)

{

// Initializes the counter to 0

int counter = 0;

// Loops till length of the array

for(int x = 0; x < array.length; x++)

// Checks the current index position of the array value with the range

if(array[x].compareTo(e1)>= 0 && array[x].compareTo(e2)<= 0)

// Increase the counter by one

counter++;

// Returns the counter

return counter;

}// End of method

};// End of anonymous class

// Returns the object

return obj;

}// End of method

// main method definition

public static void main(String[] args) throws Exception

{

// Creates an integer array

int arr[] = {12, 6, 88, 7, 1, 23, 54, 99};

// Calls the method to return MyArray object

MyArray m = getMyArray(arr.length);

// Loops till length of the array

for(int x = 0; x < arr.length; x++)

// Calls the method to assign data

m.set(x, arr[x]);

System.out.println("My array contains: ");

// Loops till length of the array

for(int x = 0; x < arr.length; x++)

// Calls the method to retrieve the data

System.out.print(m.get(x) + ", ");

// Calls the method to display minimum

System.out.println(" My array minimum value index positon: " + m.min());

// Calls the method to display maximum

System.out.println(" My array maximum value index positon: " + m.max());

// Calls the method to display count of numbers between range

System.out.println(" My array number of elements between 1 - 10: " + m.nbBetween(1, 10));

}// End of main method

}// End of class

Sample Output:

My array contains:
12, 6, 88, 7, 1, 23, 54, 99,
My array minimum value index positon: 4

My array maximum value index positon: 7

My array number of elements between 1 - 10: 3