We're making a queue that simulates a line at the DMV and aftersomeone goes through the line, or queue, we cant to take that persons name and add it to a new queue to display in the final stats of how many people have gone through and the total amount of time spent at the DMV, here is the code, help would be greatly appreciated.\

import java.util.Scanner;

public class Test
{
    public static void main(String[] args)
    {
        //initialization of variables and scanner
        String tempVar = "N";
        Scanner in = new Scanner(System.in);
        MVDList list = new MVDList();
        MVDList listTwo = new MVDList();
        while(tempVar.equals("N"))
        {
        System.out.println("Hit N to enter a new name, or q to quit.");
        tempVar = in.nextLine();
        if(tempVar.equals("q"))
        {
            break;
        }
        // print statements for the user
        System.out.println("Please enter your full name.");
        String custName = in.nextLine();
        System.out.println("Enter your transaction type: L for license renewal or R for registration renewal.");
        String transaction = in.nextLine();
        System.out.println("Enter payment type: $ for cash or C for check. (Checks take approval time).");
        String payment = in.nextLine();
        System.out.println("The time is 2:00pm");
        int arrivalTime = 1400;

        list.processInput(transaction,payment,arrivalTime,custName);
        list.computeTime();
        list.formatOutput();
        list.addPerson(custName);


        }
    }
}

I've initialized listTwo to put the dequeued names onto, i need to know how to set up the removePerson method to get the name.  here is MDV list code

public class MVDList extends Queue
{
    private int arrivalTime;
    private int signIn = 10;
    private int renewLicense = 90;
    private int regAuto = 60;
    private int payCashier = 30;
    private int cashCheck = 10;
    private int timeSpent;
    private int counter;
    private String custName;
    private String transactionCode;
    private String paymentType;

    Queue aQueue = new Queue();

    public MVDList()
    {
    }

    public void processInput(String trans, String payment, int time, String name)
    {
        transactionCode = trans;
        paymentType = payment;
        custName = name;
        arrivalTime = time;
    }

    public void formatOutput()
    {
        int average = timeSpent / counter;

        System.out.println("You have spent " + timeSpent + " seconds in the great, happy, and most of all, aesthetically pleasing MVD");
        System.out.println("Average time was " + average + " seconds.");
    }

    public Queue addPerson(String custName)
    {
        aQueue.enqueue(custName);
        System.out.println(aQueue.peek());
        return aQueue;
    }
    public Queue removePerson(String custName)
    {
        aQueue.dequeue();


    }
    public int computeTime()
    {
        timeSpent += 10;
        if(transactionCode.equals("L"))
        {
            timeSpent += 90;
        }
        else if (transactionCode.equals("R"))
        {
            timeSpent += 60;
        }
        else {}
        if(paymentType.equals("$"))
        {
            timeSpent += 30;
        }
        else if(paymentType.equals("C"))
        {
            timeSpent += 30;

        }
        else {}
        System.out.println(timeSpent);
        counter++;
        return timeSpent;
    }
}

Edited 3 Years Ago by Reverend Jim: Fixed formatting

Then the class does not need to extend Queue.

The remove person method will not need to take a custName parameter because dequeue() should remove the next item from the queue and return the name of that person. I'm not sure why you are returning the Queue from addPerson() and removePerson().

This article has been dead for over six months. Start a new discussion instead.