Answer to Question #253211 in Java | JSP | JSF for Tarurendra Kushwah

Question #253211

1. Create a class of SalesPersons as a thread that will display five salespersons names.

2. Create a class as Days as other Thread that has an array of seven days.

3. Call the instance of SalesPersons in Days and start both the

 threads

4. suspend SalesPersons on Sunday and resume on Wednesday

Note: use suspend, resume methods from the thread

1
Expert's answer
2021-10-20T00:06:43-0400
class Days extends Thread {
	private String[] days = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
	public void Display() {
		SalesPersons Sp = new SalesPersons();
		Sp.start();


		for (String D : days) {
			System.out.println(D);
			try {
				sleep(800);
			} catch (InterruptedException m) {
				m.printStackTrace();
			}
			if(D=="Sunday"){
				System.out.println("Suspending");
				Sp.suspend();
				try {
					sleep(1500);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			} 


			if (D=="Wednesday") {
				System.out.println("Resuming");
				Sp.resume();
			}
		}
	}
}
class SalesPersons extends Thread {
	private String[] names = {"Jack", "Ben", "Mary", "Chris", "Ria"};


	public void Display() {		
		for (String N : names) {			
			System.out.println(N);
			try {
				sleep(500);
			} catch (InterruptedException m) {
				m.printStackTrace();
			}
		}
	}
}
public class Main {
	public static void main(String[] args) {				
		Days d = new Days();
		Thread q = new Thread(d);
		q.start();		
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS