Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Flash XML Applications Use AS2 And AS3 To Create Photo Galleries Menus And Databases

Authors: Joachim Schnier

1st Edition

0240809173, 978-0240809175

More Books

Students also viewed these Databases questions

Question

b. What groups were most represented? Why do you think this is so?

Answered: 1 week ago