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;import java.util.Queue; public class UsingStacksSuitorsLab implements Runnable { private static int threadCount

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

}

}

}

}

Introduction to The Royal Suitors In an ancient land, the beautiful princess Eve (or handsome prince Val) had many suitors. Being royalty, it was decided that a special process must be used to determine which suitor would win the hand of the prince/princess. First, all of the suitors would be lined up one after the other and assigned numbers. The first suitor would be number 1, the second number 2, and so on up to the last suitor, number n. Starting at the suitor in the first position, she/he would then count three suitors down the line (because of the three letters in his/her name) and that suitor would be eliminated and removed from the line. The prince/princess would then continue, counting three more suitors, and eliminate every third suitor. When the end of the line is reached, counting would continue from the beginning. For example, if there were 6 suitors, the elimination process would proceed as follows: 123456 12456 1245 initial list of suitors, starting count from 1 suitor 3 eliminated, continue counting from 4 suitor 6 eliminated, continue counting from 1 suitor 4 eliminated, continue counting from 5 suitor 2 eliminated, continue counting from 5 suitor 5 eliminated, 1 is the lucky winner 125 15 Introduction to The Royal Suitors In an ancient land, the beautiful princess Eve (or handsome prince Val) had many suitors. Being royalty, it was decided that a special process must be used to determine which suitor would win the hand of the prince/princess. First, all of the suitors would be lined up one after the other and assigned numbers. The first suitor would be number 1, the second number 2, and so on up to the last suitor, number n. Starting at the suitor in the first position, she/he would then count three suitors down the line (because of the three letters in his/her name) and that suitor would be eliminated and removed from the line. The prince/princess would then continue, counting three more suitors, and eliminate every third suitor. When the end of the line is reached, counting would continue from the beginning. For example, if there were 6 suitors, the elimination process would proceed as follows: 123456 12456 1245 initial list of suitors, starting count from 1 suitor 3 eliminated, continue counting from 4 suitor 6 eliminated, continue counting from 1 suitor 4 eliminated, continue counting from 5 suitor 2 eliminated, continue counting from 5 suitor 5 eliminated, 1 is the lucky winner 125 15

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!