Queue Exercise
- 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:
- default constructor that does nothing
- constructor to initialize all fields
- toString which makes and returns a nicely formatted String containing the fields
- equals, which compares two Persons to see if they contain the same
values in all fields
- nameStartsWith, which has one parm, a char. The method returns true if the
name starts with the same char, and returns false otherwise.
-
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:
- 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.
- Prompt for and read a character.
- Write another loop to remove each item from the queue and print
the Person if the name starts with the character entered.
- 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.
- Change your program to use a LinkedQueue and run it again with the same
input. Do you get the same results?
- 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