Lab 8: Queues
Due Date and Submission Requirements
- Due Date: Thursday, October 24th 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 CarQueue.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 or linked list
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 CarQueue class and fill in the missing methods for the queue data structure.
Since you are writing a queue that represents a Car wash, 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 "Sasha")
- 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 override the toString() method so that it returns information about the customer/car.
Next, you will define the CarQueue class, which will be your queue. You can use either a Linked List or array to represent your queue. The queue has a finite size, and that size is specified as an argument to the CarQueue 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 CarQueue 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 CarQueue class).
Starting Code
Output
When you run your program, your output should look exactly like this screenshot
Restrictions
You CANNOT import java.util.Queue;
Hints
We implemented a queue in class using an Array and by using a linked list. You should be able to use some of the code we wrote for either of 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 CarQueue class is correctly defined and uses a linked list or array