Question: Please help me code the following in: JAVA Please use many COMMENTS Full points will be awarded, thanks in advance! UsingStackSuitorsLab class: import java.util.LinkedList; import

Please help me code the following in: JAVA

Please use many COMMENTS

Full points will be awarded, thanks in advance!

Please help me code the following in: JAVA Please use many COMMENTSFull points will be awarded, thanks in advance! UsingStackSuitorsLab class: import java.util.LinkedList;

UsingStackSuitorsLab class:

import java.util.LinkedList;

import java.util.Queue;

public class UsingStacksSuitorsLab implements Runnable {

private static int threadCount = 0;

private String name;

public UsingStacksSuitorsLab() {

name = "#" + threadCount++ + "Thread";

}

public static void main(String[] args) {

String s1 = "food"; /ot a palindrome

String s2 = "racecar"; //a palindrome

System.out.println("String1 is \"" + s1 + "\"");

System.out.println("String2 is \"" + s2 + "\"");

/* System.out.println(s1 + " reversed is: ");

printReverse(s1);

System.out.println(s2 + " reversed is: ");

printReverse(s2);

recPrintReverse(s1);

System.out.println();

recPrintReverse(s2);

System.out.println();

System.out.println(s1 + " is a palindrome: " + isPalindrome(s1));

System.out.println(s2 + " is a palindrome: " + isPalindrome(s2));

System.out.println(s1 + " is a palindrome(recursively): " + isPalindromeRec(s1));

System.out.println(s2 + " is a palindrome(recursively): " + isPalindromeRec(s2));

System.out.println("Did we build a Queue of Threads and start them? " + buildThreadQueue());

int n = 6;

System.out.println("For " + n + " suitors, stand in place:" + findPlaceToStand(n));

n = 10;

System.out.println("For " + n + " suitors, stand in place:" + findPlaceToStand(n));*/

}

public static void printReverse(String target) {

//todo: use a stack

}

public static void recPrintReverse(String target) {

//todo

}

public static boolean isPalindrome(String input) {

//todo: use a stack

}

public static boolean isPalindromeRec(String sentence) {

//todo

}

public static int findPlaceToStand(int numSuitors) {

//todo

return -1;

}

public static boolean buildThreadQueue() { //returns true upon success

Queue q = new LinkedList(); //comment this out and use your own Queue

//when our program starts up, it might create multiple threads to use

//q.enqueue( new Thread(new UsingStacksSuitorsLab()));

System.out.println("Initial Thread order:");

q.toString();

//We need to iterate over our pool of threads and call start() on each one

//Make a loop that dequeues a thread, calls start on it, and enqueues it again

//for(?) {

Thread curreent = q.deque();

current.start();

q.enqueue(current);

/* current = get a thread

current.start();

put the thread back

}*/

System.out.println("Thread order after start()ing:");

q.toString();

return true; //on successful start

}

/*

* No need to edit anything below here,

* unless you'd like to change the

* behaviour of each thread in the thread pool above

*/

@Override

public void run() {

for(int i = 0; i

System.out.println(name + ": " + i + "th iteration");

try {

Thread.sleep(10);

} catch (InterruptedException e) {

//do nothing here

}

}

}

}

Palindromes &Stacks Iteratively In this section, we'll determine that the String "bob" is a palindrome while "food" is not, both iteratively and recursively. Start by uncommenting the lines of code that call isPalindrome) in main, and... In main, uncomment out all calls to isPalindrome) . Find the isPalindrome) function in the driver and look at how it's called from main Inside of isPalindrome, do the following: o Declare a stack to use from the previous labs (the linked Stack is preferable here) If your Stack is broken, you can consider using Java's Stack Stack foo = new Stack(); " . o Write a loop that iterates over the input string In the loop, push each char from the input string on the stack Write a second loop that iterates until the stack is empty *In the loop, pop off a char from the stack and append it to a string. This string is now the reverse of the original input Now that you have two strings (the input and it's reverse), return true if they're equal or false otherwise o Execute the code and observe your output; does it match the sample output below Palindromes& Stacks Recursively In this section, we'll repeat what we did with printReverse) and create a recursive version of the iterative isPalindrome) function we just made. This function should call itself repeatedly to determine

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!