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!
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
//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
}
}
}
}
Warming Up With Reversing Strings Palindromes are interesting strings in that they are the same when displayed both left-to-right and right to-left. For example, "Do geese see God" or "A man a plan a canal: panama!" are both palindromes, not considering punctuation or case sensitivity. We'll write multiple methods to determine whether a string is a palindrome, and we can make use of Stacks to accomplish this. To get started, download the driver code and first practicing printing a String in reverse using a Stack: Download the driver file UsingStacksSuitorsLab.java and read it Find the main method and comment out everything below the printReversel) function calls in main Find the printReverse() method and declare a Stack inside of it . Use your Stack from the previous labs (the Linked Stack is preferable here) "If your Stack is broken, you can consider using Java's Stack Stack
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started