Queue Exercise


  1. Write a class called Person. This class will have fields for the name, age, and cell number (String) of a person. It will have the following methods:
  2. Write a program that creates a queue of Person objects. Use the ArrayUnboundedQueue class. You can find the queue interfaces and classes in Files on our Canvas page. Your program should do the following:
    1. Write a loop that prompts the user for name, age, and cell number. Use this data to create a Person and add it to the queue. Exit this loop when the user enters "done" for the name.
    2. Prompt for and read a character.
    3. Write another loop to remove each item from the queue and print the Person if the name starts with the character entered.
  3. Run your program with at least five Persons, and make sure that at least three start with the same letter. Enter that letter and notice the order in which the Persons are printed.
  4. Change your program to use a LinkedQueue and run it again with the same input. Do you get the same results?
  5. Change your program to use an ArrayBoundedStack and run it again with the same input. Do you get the same results?


Email Me | Office Hours | My Home Page | Department Home | MCC Home Page

© Copyright Emmi Schatz 2022