Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please follow the steps perfectly and i will thumbs up! thank you you will make

ID: 3859414 • Letter: P

Question

Please follow the steps perfectly and i will thumbs up!

thank you

you will make a generic queue class called GenericQueue. A queue is a data structure similar to a stack. However, a stack is last-in-first-out (LIFO) and a queue is first-in-first-out (FIFO). To elaborate, a stack is like a stack of dishes (as mentioned in class) where elements are only added and remove from the same end of the data structure. A queue, on the other hand, is like a lineup at a grocery store. The first person to enter the line is the first one to get served, and consequently is the first one to get removed from the line. So, instead of “push” and “pop” to add and remove elements, a queue has “enqueue” and “dequeue”. The enqueue method adds an element to the end of the queue. The dequeue method returns the first element in the queue and removes it from the queue. Several classes are posted online that must be used with this assignment. The expected output and description of GenericQueue is found below.

Class GenericQueue:

It is generic, therefore it needs a type parameter (let’s call it T). It has an ArrayList instance variable called myQueue. The base type of the ArrayList is T as well. It has a method to check if it is empty, called isEmpty. isEmpty returns true if myQueue is empty, and false otherwise. As described above, GenericQueue has a method called enqueue which accepts a T and adds it to the queue. It also has a method called dequeue which returns a T, the value at index 0 of the queue (if one exists). If no value exists in the queue, return null. The value returned must also be removed from the queue. Lastly, this class has a toString method which first prints “***************************************************” on its own line, followed by “The queue has ” followed by the number of elements, followed by “ elements:” on another line. It then prints the toString of all of the elements in the queue on their own line. Finally, it prints “***************************************************” once more.

Obtain the modified versions of CanadianStudent, Student, CanadianStudentUnder65, and ForeignStudent from the assignment posting, and import these into your project. I have removed the interface implementations from these classes, as we do not need them for this assignment. Import GenericTest as well, which is the tester class for this assignment.

Expected Output:

***************************************************

The queue has 3 elements:

Student #1, Name: Rene is from France, pays fees $4000.0

Student #2, Name: Li is from China, pays fees $3000.0

Student #3, Name: Rakesh is from India, pays fees $2000.0

***************************************************

***************************************************

The queue has 4 elements:

Student #2, Name: Li is from China, pays fees $3000.0

Student #3, Name: Rakesh is from India, pays fees $2000.0

Student #4, Name: Lynne is from Canada, pays fees $800.0

Student #5, Name: Tanya is from Canada, pays fees $800.0

***************************************************

***************************************************

The queue has 5 elements:

Student #3, Name: Rakesh is from India, pays fees $2000.0

Student #4, Name: Lynne is from Canada, pays fees $800.0

Student #5, Name: Tanya is from Canada, pays fees $800.0

Student #6, Name: Chris is from Canada, pays fees $800.0

Student #7, Name: Ryan is from Canada, pays fees $800.0

***************************************************

***************************************************

The queue has 7 elements:

Student #4, Name: Lynne is from Canada, pays fees $800.0

Student #5, Name: Tanya is from Canada, pays fees $800.0

Student #6, Name: Chris is from Canada, pays fees $800.0

Student #7, Name: Ryan is from Canada, pays fees $800.0

Student #8, Name: Bob is from Canada, pays fees $50.0, senior citizen who gets pension $45000.0

Student #9, Name: Tyler is from Canada, pays fees $50.0, senior citizen who gets pension $62000.0

Student #10, Name: Mary is from Canada, pays fees $50.0, senior citizen who gets pension $65000.0

***************************************************

***************************************************

The queue has 4 elements:

Student #7, Name: Ryan is from Canada, pays fees $800.0

Student #8, Name: Bob is from Canada, pays fees $50.0, senior citizen who gets pension $45000.0

Student #9, Name: Tyler is from Canada, pays fees $50.0, senior citizen who gets pension $62000.0

Student #10, Name: Mary is from Canada, pays fees $50.0, senior citizen who gets pension $65000.0

***************************************************

***************************************************

The queue has 0 elements:

***************************************************

Canadian student:

Canadianstudentunder65

ForeignStudent

GenericTester

MyDate

SeniorStudent

Student

Explanation / Answer

Put this file in a GenericQueue.java file alongside with other files in project.

import java.util.*;
import java.io.*;


public class GenericQueue<T>// GenericQueue class
{
ArrayList<T> myQueue = new ArrayList<T>();// list for queue

boolean isEmpty()// check if queue id empty
{
return myQueue.isEmpty();
}

void enqueue(T obj)// enqueue to list
{
myQueue.add(obj);
}

T dequeue()// dequeue from list
{
if (!isEmpty())
return myQueue.remove(0);
return null;
}


public String toString()// return string
{
String out = "*************************************************** ";
out += "The queue has: " + myQueue.size() + " elements ";
for (T obj : myQueue)
{
out += obj.toString() + " ";
}

out += "*************************************************** ";
return out;
}
  
}

Sample output

run:
***************************************************
The queue has: 3 elements
Student #1, Name: Rene is from France, pays fees $4000.0
Student #2, Name: Li is from China, pays fees $3000.0
Student #3, Name: Rakesh is from India, pays fees $2000.0
***************************************************

***************************************************
The queue has: 4 elements
Student #2, Name: Li is from China, pays fees $3000.0
Student #3, Name: Rakesh is from India, pays fees $2000.0
Student #4, Name: Lynne is from Canada, pays fees $800.0
Student #5, Name: Tanya is from Canada, pays fees $800.0
***************************************************

***************************************************
The queue has: 5 elements
Student #3, Name: Rakesh is from India, pays fees $2000.0
Student #4, Name: Lynne is from Canada, pays fees $800.0
Student #5, Name: Tanya is from Canada, pays fees $800.0
Student #6, Name: Chris is from Canada, pays fees $800.0
Student #7, Name: Ryan is from Canada, pays fees $800.0
***************************************************

***************************************************
The queue has: 7 elements
Student #4, Name: Lynne is from Canada, pays fees $800.0
Student #5, Name: Tanya is from Canada, pays fees $800.0
Student #6, Name: Chris is from Canada, pays fees $800.0
Student #7, Name: Ryan is from Canada, pays fees $800.0
Student #8, Name: Bob is from Canada, pays fees $50.0, senior citizen who gets pension $45000.0
Student #9, Name: Tyler is from Canada, pays fees $50.0, senior citizen who gets pension $62000.0
Student #10, Name: Mary is from Canada, pays fees $50.0, senior citizen who gets pension $65000.0
***************************************************

***************************************************
The queue has: 4 elements
Student #7, Name: Ryan is from Canada, pays fees $800.0
Student #8, Name: Bob is from Canada, pays fees $50.0, senior citizen who gets pension $45000.0
Student #9, Name: Tyler is from Canada, pays fees $50.0, senior citizen who gets pension $62000.0
Student #10, Name: Mary is from Canada, pays fees $50.0, senior citizen who gets pension $65000.0
***************************************************

***************************************************
The queue has: 0 elements
***************************************************

BUILD SUCCESSFUL (total time: 0 seconds)