Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Variable paychecksQueue is a Queue of type Integer. Integers are read from input and are added to paychecksQueue until - 9 9 is read. While
Variable paychecksQueue is a Queue of type Integer. Integers are read from input and are added to paychecksQueue until is read. While paychecksQueue is not empty, repeat the following:
Remove the element at the head of paychecksQueue.
If the element's value is greater than or equal to then output "Paycheck delivered. Unpaid hours returned to queue: followed by the element minus and insert the remainder to the tail of paychecksQueue.
Otherwise, output the element followed by hours: paycheck not delivered yet".
End each output with a newline.
Ex: If the input is then the output is:
Paycheck delivered. Unpaid hours returned to queue:
hours: paycheck not delivered yet
hours: paycheck not delivered yet
Queue is empty
import java.util.Queue;
import java.util.Scanner;
import java.util.LinkedList;
public class NumberOfPaychecksQueue
public static void mainString args
Scanner scnr new ScannerSystemin;
Queue paychecksQueue new LinkedList;
int paycheckValue;
paycheckValue scnrnextInt;
while paycheckValue
paychecksQueue.addpaycheckValue;
paycheckValue scnrnextInt;
while paychecksQueuepeek null
Your code goes here
int currentPaycheck paychecksQueue.poll;
if currentPaycheck && currentPaycheck
System.out.printlnQueue is empty";
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started