Question: import java.util.LinkedList; import java.util.Queue; public class Lab_Assignment { public static void main(String[] args) { // TODO Auto-generated method stub String[] words = { Cat, Dog,

import java.util.LinkedList; import java.util.Queue;

public class Lab_Assignment {

public static void main(String[] args) { // TODO Auto-generated method stub

String[] words = { "Cat", "Dog", "Antelope", "Walrus", "Cat", "Ant", "Carrot", "Mouse", "Rat", "Tiger", "Dog", "Horse", "Worm", "Frog", "Elephant", "Goat", "Mule", "Cat", "Reindeer", "Whale", "Baboon", "Inchworm", "Dog", "Starfish" };

Queue q = QueueFromArray(words);

Queue newQueue = replace(q, 4, "Tiger"); System.out.println("Queue with replaced value: " + newQueue);

String findString = "Cat"; int nextPosition = findNext(q, findString, 1);

if (nextPosition == -1) { System.out.println("The string is not found!"); } else System.out.println("The position of " + findString + " is: " + nextPosition);

System.out.println("Showing the queue as a string: "+toString(q));

String findOccurance = "Dog"; int occur_times = countOccurrences(q, findOccurance); System.out.println("'" + findOccurance + "'" + " is present " + occur_times + " times in the list."); Queue reversedQueue = revereseQueue(q); System.out.println("Showing the queue in reserse: "+reversedQueue); } private static Queue QueueFromArray(String[] words) { Queue q = new LinkedList<>(); // write your code here return q; }

private static Queue revereseQueue(Queue q) { Queue reverse = new LinkedList<>(); // write your code here return reverse; }

private static int countOccurrences(Queue q, String findOccurance) { int occur = 0; // write your code here return occur; }

private static Queue replace(Queue q, int i, String string) { Queue newQueue = new LinkedList<>(); // write your code here return newQueue; }

private static String toString(Queue q) { String str = ""; // write your code here return str; }

private static int findNext(Queue q, String findString, int i) { // write your code here return -1; }

}

You are given a Java file, which you would need to complete by implementing the methods mentioned there.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!