Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

1. You are given the class MyIterable that implements the Iterable interface and a text file input.txt. Read and understand the purpose of the MyIterable

1. You are given the class MyIterable that implements the Iterable interface and a text file \"input.txt\". Read and understand the purpose of the MyIterable class. The Iterable interface has a method to override: Iterator iterator().

2. Write a class MyIterableTester that reads input arrays of any type (Read Step 3, Note for more details) and iterates it in a for-each loop and displays the input in reverse sorted order.

3. MyIterableTester class reads the input data for a text file (input.txt) into appropriate ArrayLists of different types (String, Integer, and Double) and stores them into corresponding arrays. Note: (i) You need to create the input.txt file with the data profile. (ii) Use hasNext(), hasNextInt() and hasNextDouble() to read appropriate data into different ArrayLists using while loops. (iii) convert the ArrayLists into arrays that serve as inputs in MyIterableTester class Mylterable Class: import java.util.List; import java.util.Arrays; import java.util.Iterator; import java.util.Collections; public class MyIterable implements Iterable { private List list; public MyIterable (T [] t) { list = Arrays.asList(t); Collections.sort (list, Collections. reverseOrder()); } @Override public Iterator iterator() { return list.iterator(); } } input.txt Andrew Sasha Mike John Amy Prince Patty 12 2 32 14 5 10 7 6 10.4 30.6 4.95 4.9 6.9 Note: This is just a sample data provided for you to test the program. Your program should work for any data file of varying numbers of data inputs. Sample run: My friends: Sasha Prince Patty Mike John Andrew Amy My numbers: 32 14 12 10 7 6 5 2 My scores: 30.6 10.4 6.9 4.95 4.9

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Design Operation And Evaluation Of Mobile Communications

Authors: Gavriel Salvendy ,June Wei

1st Edition

3030770249, 978-3030770242

More Books

Students explore these related Programming questions