Question: Variable codesQueue is a Queue of type Character. Characters are read from input and are added to codesQueue until ' Z ' is read. Complete

Variable codesQueue is a Queue of type Character. Characters are read from input and are added to codesQueue until 'Z' is read. Complete the loop to remove and output the element at the head of codesQueue while both of the following conditions are true:
codesQueue is not empty.
The value at the head of codesQueue is not equal to 'W'.
Ex: If the input is X T V L W Z, then the output is:
Screened code: X
Screened code: T
Screened code: V
Screened code: L
Alert: Code W is now at the front of the queue
import java.util.Queue;
import java.util.Scanner;
import java.util.LinkedList;
public class FirstInCodesQueue {
public static void main(String[] args){
Scanner scnr = new Scanner(System.in);
Queue codesQueue = new LinkedList();
char codeValue;
codeValue = scnr.next().charAt(0);
while (codeValue !='Z'){
codesQueue.add(codeValue);
codeValue = scnr.next().charAt(0);
}
while (
/* Your code goes here */
){
System.out.println("Screened code: "+ codesQueue.poll());
}
if (codesQueue.peek()== null){
System.out.println("All codes screened");
}
else {
System.out.print("Alert: Code "+ codesQueue.peek());
System.out.println(" is now at the front of the queue");
}
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!