
Code in java please
import java.util.*;
public class QueueLastname //<------ change the name of the class to include your
last name
{
// no code goes here
}
class Queue
{
private ArrayList<String> q;
public Queue( )
{
q = new ArrayList<String>();
}
public void enqueue(String num)
{
q.add(num);
}
public String dequeue()
{
return q.remove(0);
}
/*This method goes through the quque and finds the longest name in the q
The queue must be restored in its original state after finding the longest
name*/
public String getLongestName()
{
Stack s = new Stack();
String longest = q.get(0);
// q.remove(0);
boolean b = false;
while(!b)
{
try
{
String front = q.get(0);//get the first element
q.remove(0);//remove it from the q
s.push(front);// push it to the stack
if (front.length() > longest.length() )
longest = front;
}
catch(Exception e)
{
b = true;
}
}
restore(s); // restoring the queue
return longest;
}
/*
Traverse through the queue and creates a string containing all the names.
must restore the quque to its original state*/
public String toString()
{
Stack c = new Stack();
String s = "";
boolean b = false;
while(!b)
{
try
{
s = s + q.get(0)+ " ";
c.push(q.remove(0));
}
catch(Exception e)
{
b = true;
}
}
restore(c);
return s;
}
/*
This method is called to restore the queue to its original state*/
public void restore(Stack s)
{
boolean b = false;
while(!b)
{
try
{
if (s.isEmpty())
throw new Exception();
String a = (String)s.pop();
q.add(0,a);
}
catch(Exception c)
{
b = true;
}
}
}
/*this method goes through the queue finding the longest name
The queue must be restored to its original state
this method is similar to the longest name*/
public String getShortestName()
{
return "";
}
/*This method reverses the order of the names in the queue */
public void listReversed()
{
}
/*This method finds the verage length of the length of all the names in the q
queue must be restored to its original state*/
public double getAverageLength()
{
return 0;
}
/*
This method returns true if the q is sorted alphabetically
Queue must be restored to its original state
*/
public boolean ordered()
{
return false;
}
/*this method returns true if the queue is palindrom and returns false otherwise
call the method copy in the palindrome method*/
public boolean isPalindrome()
{
return true;
}
public ArrayList<String> copy()
{
return null;
}
public void preserve(Queue q)
{
boolean b = false;
while(!b)
{
try
{
this.enqueue(q.dequeue());
}
catch (Exception e)
{
b = true;
}
}
}
}
class Driver
{
public static void main(String[] args)
{
// String[] names = {"Alexis", "Zoeehra","Maryam","Jose","Bill","Niksan",
"BB"};
String[] names = {"a", "b", "c", "b","a"};
Queue people = new Queue();
//enqueue the queue using the array called names
for(int i = 0; i < names.length; i++)
{
people.enqueue(names[i]);
}
System.out.println("The q of the people at Bestbuy on black Friday : " +
people);
people.listReversed();
System.out.println("The q of the people in the reverse order is: "+
people );
people.listReversed();
System.out.println("List is back to its original state: "+ people);
System.out.printf("Average length of all the Strings in the q is = %.2f\n",
people.getAverageLength());
System.out.println("The longest name in the q is = " +
people.getLongestName());
System.out.println(people+"******************");
System.out.println("The shortest name in the q is = " +
people.getShortestName());
System.out.print("is of the list of the people is sorted? " );
if(people.ordered())
System.out.print("Yes");
else
System.out.print("No");
if(people.isPalindrome())
System.out.println("The list is palindrome");
else
System.out.println("The list is not palindrome");
System.out.println(people.isPalindrome());
}
}
/* create your own driver(15 points)
In this driver must use an array q otherwise you will not get any points*/
class YourDriver
{
public static void main (String[] args)
{
//1. declare an arrayq to store some names of your choice
//2. declare a Queue and instantiate it
//3. copy the names from the arrayq to the queue that you declared(for loop
is needed
//4. call all the methods similar to the given driver.
}
}

Trending nowThis is a popular solution!
Step by stepSolved in 3 steps

- package edu.umsl.iterator;import java.util.ArrayList;import java.util.Arrays;import java.util.Collection;import java.util.Iterator;public class Main {public static void main(String[] args) {String[] cities = {"New York", "Atlanta", "Dallas", "Madison"};Collection<String> stringCollection = new ArrayList<>(Arrays.asList(cities));Iterator<String> iterator = stringCollection.iterator();while (iterator.hasNext()) {System.out.println(/* Fill in here */);}}} Rewrite the while loop to print out the collection using an iterator. Group of answer choices iterator.toString() iterator.getClass(java.lang.String) iterator.remove() iterator.next()arrow_forwardimport java.util.HashSet; import java.util.Set; // Define a class named LinearSearchSet public class LinearSearchSet { // Define a method named linearSearch that takes in a Set and an integer target // as parameters public static boolean linearSearch(Set<Integer> set, int target) { // Iterate over all elements in the Set for () { // Check if the current value is equal to the target if () { // If so, return true } } // If the target was not found, return false } // Define the main method public static void main(String[] args) { // Create a HashSet of integers and populate integer values Set<Integer> numbers = new HashSet<>(); // Define the target to search for numbers.add(3); numbers.add(6); numbers.add(2); numbers.add(9); numbers.add(11); // Call the linearSearch method with the set…arrow_forward/** * This class will use Nodes to form a linked list. It implements the LIFO * (Last In First Out) methodology to reverse the input string. * **/ public class LLStack { private Node head; // Constructor with no parameters for outer class public LLStack( ) { // to do } // This is an inner class specifically utilized for LLStack class, // thus no setter or getters are needed private class Node { private Object data; private Node next; // Constructor with no parameters for inner class public Node(){ // to do // to do } // Parametrized constructor for inner class public Node (Object newData, Node nextLink) { // to do: Data part of Node is an Object // to do: Link to next node is a type Node } } // Adds a node as the first node element at the start of the list with the specified…arrow_forward
- import java.util.*; public class Main{ public static void main(String[] args) { Main m = new Main(); m.go(); } private void go() { List<Stadium> parks = new ArrayList<Stadium>(); parks.add(new Stadium("PNC Park", "Pittsburgh", 38362, true)); parks.add(new Stadium("Dodgers Stadium", "Los Angeles", 56000, true)); parks.add(new Stadium("Citizens Bank Park", "Philadelphia", 43035, false)); parks.add(new Stadium("Coors Field", "Denver", 50398, true)); parks.add(new Stadium("Yankee Stadium", "New York", 54251, false)); parks.add(new Stadium("AT&T Park", "San Francisco", 41915, true)); parks.add(new Stadium("Citi Field", "New York", 41922, false)); parks.add(new Stadium("Angels Stadium", "Los Angeles", 45050, true)); Collections.sort(parks, Stadium.ByKidZoneCityName.getInstance()); for (Stadium s : parks) System.out.println(s); }}…arrow_forwardRedesign LaptopList class from previous project public class LaptopList { private class LaptopNode //inner class { public String brand; public double price; public LaptopNode next; public LaptopNode(String brand, double price) { // add your code } public String toString() { // add your code } } private LaptopNode head; // head of the linked list public LaptopList(String fname) throws IOException { File file = new File(fname); Scanner scan = new Scanner(file); head = null; while(scan.hasNextLine()) { // scan data // create LaptopNode // call addToHead and addToTail alternatively } } private void addToHead(LaptopNode node) { // add your code } private void addToTail(LaptopNode node) { // add your code } private…arrow_forwardChange the __str__ method of the Queue class (provided below) so that it prints each object in the queue along with its order in the queue (see sample output below). class Queue(): def __init__(self): self.queue = [] # implement with Python lists! # start of physical Python list == front of a queue # end of physical Python list == back of a queue def enqueue(self, new_obj): self.queue.append(new_obj); def dequeue(self): return self.queue.pop(0) def peek(self): return self.queue[0] def bad_luck(self): return self.queue[-1] def __str__(self): return str(self.queue) # let's try a more fun waySample output: >>> my_queue = Queue()>>> everyone = ["ESC", "ABC", "YOLO", "HTC"]>>> for initials in everyone:>>> my_queue.enqueue(initials)>>> print(my_queue)Output: 1: ESC2: ABC3: YOLO4: HTCarrow_forward
- comptuer sciecne helparrow_forwardComplete the code. The question is in the picture #include <iostream> using namespace std; class Queue { int size; int* queue; public: Queue() { size = 0; queue = new int[100]; } void add(int data) { queue[size] = data; size++; } void remove() { if (size == 0) { cout << "Queue is empty"<<endl; return; } else { for (int i = 0; i < size - 1; i++) { queue[i] = queue[i + 1]; } size--; } } void print() { if (size == 0) { cout << "Queue is empty"<<endl; return; } for (int i = 0; i < size; i++) { cout<<queue[i]<<" <- "; } cout << endl; } Queue operator+(Queue &obj) { Queue res; for(int i=0;i<this->size;i++) { res.add(this->queue[i]); } for(int i=0;i<obj.size;i++) { res.add(obj.queue[i]); } return res; } }; //your code goes here int main() { Queue q1; q1.add(42); q1.add(2); q1.add(8); q1.add(1); q1.print(); Queue2 q2; q2.add(3);…arrow_forwardcomplete all the implementation of the member functions listed in the class interface for the following header file. #ifndef _LINKEDSTACK#define _LINKEDSTACK #includeusing namespace std;templateclass LinkedStack{private:Node *top; Node *getCurrentTop() { return top; }public: Stack(); bool isEmpty(); bool push(ItemType newItem); bool pop(); ItemType peek(); void clean(); bool display();};#endifarrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





