Question: Need help filling in the parts in JAVA, ONLY edit between the parts that are bolded. Expected output is highlighted in the comments. /** Illustrates
Need help filling in the parts in JAVA, ONLY edit between the parts that are bolded. Expected output is highlighted in the comments.
/** Illustrates basic operations of an iterator on a set. Notice that the iterator for a set differs from the iterator for a list (i.e., a list iterator), in that the set iterator has no previous method (since the set has no order it does not makes sense to ask to go backwards), and the set iterator has no add method (since the set has no order it makes no sense to try to add an element at a particular position). The part that you write adds 1000 random letters a-z to a set, then puts them in a stack, then pops and prints them. Expected output: A-B-D-F-G zyxwvutsrqponmlkjihgfedcba */ public class SetTester4 { public static void main(String[] args) { //This first part is just an example of set operations. Set set = new TreeSet() ; set.add("A") ; set.add("B") ; set.add("C") ; set.add("D") ; set.add("F") ; set.add("G") ; //The following line shows how to make an iterator for a set. Iterator iterator = set.iterator() ; //The following loop shows how to go through the set with the iterator while (iterator.hasNext()) { String element = iterator.next() ; if (element.equals("C")) iterator.remove() ; else if (iterator.hasNext()) System.out.print(element + "-") ; else System.out.print(element) ; } System.out.println() ; System.out.println("-----------------------------Your work:") ; set = new TreeSet() ; Random random = new Random() ; char ch = 'a' ; for (int i = 0 ; i < 1000 ; i++) { //-----------Start below here. To do: approximate lines of code = 6 // 1. add a randomly selected letter "a" to "z" to set ; }// //2. iterator = ... an iterator on set ; //3. make a stack for strings //4-5. use the iterator to put all of the letters into the stack ; //6. while there are letters on the stack System.out.print(stack.pop()) ;// System.out.println() ;// //-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions. } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
