Lab 8: Queues
Due Date and Submission Requirements
- Due Date: Thursday, October 26th at 11:59 p.m.
- Partner Information: This is an individual assignment. You are allowed to collaborate with other students, but each student must submit their individual, independent solution.
- Submission Instructions: You will submit your QueueArray.java and Car.Java files to the appropriate D2L dropbox
The goal of this lab is:
- Gain experience using a Queue data structure
- Implement a Queue in Java using an Array
Directions
You will be writing a Java program that simulates cars using a Car Wash station. Using Lab8Demo.java as a starting point, you will define the QueueArray class and fill in the missing methods for the queue data structure.
On Wednesday, October 25th, we will be implementing a Queue with an array with much simpler code than Mondays. It might be helpful to wait to start this lab until after Wednesday's lecture. There is also some hints near in the last several slides of Monday's (10/23) lecture
Since you are writing a queue that represents a Car wash, Your queue will hold Car objects, and must use an array to hold data. Each car object will have:
- The make/model of the car which is a String (for example "Nissan Rogue")
- The owner of the car, which is a String (for example "Scott")
- Whether or not they are a VIP car wash member, which is a boolean (true/false). Car washes only cost $6.00 for VIP members, and $10.00 for non-VIP members
You will need to define the Car class, and add any necessary methods. At the very least, you will need to define a getInfo() method that returns information about the customer/car.
Next, you will define the QueueArray class, which will be your queue data structure that uses an Array. The queue has a finite size, and that size is specified as an argument to the QueueArray constructor. Your queue will need to keep track of the front of the queue, the current size of the queue, and the capacity of the queue.
You will also need to keep track of the number of cars serviced by the car wash, and how much money the car wash has made.
You are NOT allowed to modify the Lab8Demo class. After creating the QueueArray class, you must define the following methods:
- enqueue(Car newCar)- The enqueue method adds a new car to the back of the queue. If the queue is full, an "Error" message should be printed out, and the car should not be added to the queue.
- dequeue()- the dequeue removes and prints out the car at the front of this queue. This method doesn't need to return anything. When a car is dequeued, that means that car has been "serviced". This should increase the number of cars serviced variables by 1, and increase the total earning by $6 (if they are a VIP) or by $10 (if they are not a VIP)
- peek()- the peek() method returns the car that is currently at the front of the queue
- isEmpty()- This method returns true if the queue is empty, false if the queue is not empty
- printQueue()- Prints out all the cars that are currently in the queue. You should print the queue out as a numbered list, where the first thing printed out is the car in the front of the queue, and the last thing printed out is the last thing in the queue (see sample output)
- printStats() - This method prints out how many cars the car wash has serviced, and the total earnings (remember these should be instance fields of the QueueArray class.
Starting Code
Output
When you run your program, your output should look exactly like this screenshot
Restrictions
You MUST use an Array. You cannot use a LinkedList, or an ArrayList
You CANNOT import java.util.Queue;
Hints
We implemented a queue using an Array on the lectures for October 23rd, and October 25th (the more efficient version). You should be able to use some of the code we wrote for those lectures.
Grading (10 points)
- 2 points- enqueue() is correct
- 2 points- dequeue() is correct
- 1 point- peek() is correct
- 1 point- isEmpty() is correct
- 1 point- printQueue() is correct
- 1 point- printStats() is correct
- 1 point- The Car class is correctly defined
- 1 point- The QueueArray class is correctly defined and uses an array
Deductions
- -10 if you do not use an array