Question
Part 1: Fibonacci (70%) 1. (5%) Create a folder named iterators under the Activity2 folder. 2. (5%) Create a class named IterableFibonacci that represents a
Part 1: Fibonacci (70%) 1. (5%) Create a folder named iterators under the Activity2 folder. 2. (5%) Create a class named IterableFibonacci that represents a Fibonacci sequence. 3. (5%) Add a constructor that declares two parameters of type long for the initial two numbers in the Fibonacci sequence. 4. (20%) Add the following methods: a. add() adds the next Fibonacci number to the sequence. b. toString() returns a nicely formatted string of its contents. For example: IterableFibonnaci fib = new IterableFibonnaci(2, 5); fib.add(); fib.add(); System.out.println(fib); // [2, 5, 7, 12] Its recommended to utilize the toString method of a data structure. c. get(int index) returns the Fibonacci number at the index. Using the above example: get(0) returns 2, get(1) returns 5, and so on. d. length() returns the length of the Fibonacci sequence. 5. (10%) Your Fibonacci class must be iterable to work with a for-each loop. a. IterableFibonacci should implement java.util.Iterable
Part 2: File Reader (30%) 1. (5%) Create a class named IterableReader.Your reader should have the capability to read text files similar to the manner in which java.io.BufferedReader does, and should support the for-each loop, allowing it to iterate over each line in the file. 2. (5%) Add a constructor that declares a parameter for a file name. In the event that an IOException occurs, the constructor may throw it again. 3. (10%) The IterableReader class should not only be iterable but also an iterator itself. Additionally, the class should be AutoCloseable in order to work with the try-with-resource feature. To be clear, IterableReader implements the following interfaces: a. Iterable
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