Suppose myRoster is an instance of the iterable class Roster. Then we can use enhanced for loop as follows. Fill in the

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

Suppose myRoster is an instance of the iterable class Roster. Then we can use enhanced for loop as follows. Fill in the

Post by answerhappygod »

Suppose myRoster is an instance of the iterable class Roster.
Then we can use enhanced for loop as follows. Fill in the blanks
(SECOND SCREENSHOT).
Suppose Myroster Is An Instance Of The Iterable Class Roster Then We Can Use Enhanced For Loop As Follows Fill In The 1
Suppose Myroster Is An Instance Of The Iterable Class Roster Then We Can Use Enhanced For Loop As Follows Fill In The 1 (151.67 KiB) Viewed 58 times
Suppose Myroster Is An Instance Of The Iterable Class Roster Then We Can Use Enhanced For Loop As Follows Fill In The 2
Suppose Myroster Is An Instance Of The Iterable Class Roster Then We Can Use Enhanced For Loop As Follows Fill In The 2 (75.76 KiB) Viewed 58 times
Enhanced for loop requires some effort. We have to do some work (making class iterable) before you can use it. Suppose we have the following collection class Roster that contains members of class Student. public class Roster { private int maxEnrolled; private int maxWaitlist; private int totalwithhope; private TreeSet<Student> enrolled; private ArrayList<Student> waitList; private HashSet<Student> hoping; } To make class Roster to be iterable, we can add an inner class Rosterlterator that implements Iterator <Student>. Give the names of the two methods that we have to have to implement interface Iterator <Student> as shown in RED below. B public class Roster implements Iterable<Student> { public Iterator<Student> iterator() { return new RosterIterator; } private class RosterIterator implements Iterator<Student> { public boolean A___O { }; public Student _B___O {...}; } }

(Cont.) Suppose myRoster is an instance of the iterable class Roster. Then we can use enhanced for loop as follows. for (Student s: myRoster) { System.out.println(s); } The reason why the enhanced for-loop works is that Java compiler will (internally) translate the loop as follows. Fill in the blanks. . B = . = Iterator<Student> it = myRoster.-__A___(); while (it. __B___() { Student s = it. _C___O; System.out.println(s); }
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply