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

Which of the following is a proper implementation for a method that displays the

ID: 3895102 • Letter: W

Question

Which of the following is a proper implementation for a method that displays the contents of a List?
(a)

public void Di splayRos t e r ( Li s t<Student> r o s t e r ) {
I t e r a t o r <Student> i t e r = r o s t e r . i t e r a t o r ( ) ;
while ( i t e r . hasNext ( ) )
System . out . p r i n t l n ( i t e r . next ( ) ) ;
}
public void Di splayRos t e r ( Li s t<Student> r o s t e r ) {
I t e r a t o r <Student> i t e r = r o s t e r . i t e r a t o r ( ) ;
while ( i t e r . Next ( ) != nul l )
System . out . p r i n t l n ( i t e r . next ( ) ) ;
}

(b)

public void Di splayRos t e r ( Li s t<Student> r o s t e r ) {
I t e r a t o r <Student> i t e r = r o s t e r . i t e r a t o r ( ) ;
while ( i t e r . hasNext ( ) )
System . out . p r i n t l n ( i t e r . getNext ( ) ) ;
}
public void Di splayRos t e r ( Li s t<Student> r o s t e r ) {
I t e r a t o r <Student> i t e r = r o s t e r . g e t I t e r a t o r ( ) ;
while ( i t e r . hasNext ( ) )
System . out . p r i n t l n ( i t e r . next ( ) ) ;
}

Explanation / Answer

If you have any doubts, please give me comment...

Ans: a)

public void DisplayRoster(List<Student> roster) {

Iterator<Student> iter = roster.iterator();

while (iter.hasNext())

System.out.println(iter.next());

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote