Question

Create two thread classes: ThreadWaiterOne and ThreadWaiterTwo. The thread classes must implement Runnable. In the Run...

Create two thread classes: ThreadWaiterOne and ThreadWaiterTwo. The thread classes must implement Runnable. In the Run method for ThreadWaiterOne, delay the code for 20 sec and then output to the console "Thread Waiter One is done." The ThreadWaiterTwo class must wait for 5 sec before outputting the console "Thread Waiter Two is done." Finally create ThreadTester that will run the two classes by having them implement Runnable. The thread classes Create two thread classes, Minute.java and Second.java. The Minute.java class will run in a thread and wake up every 60 sec to count the minutes starting with 1 minute. The Second.java class will wake up every second, counting each second starting with 1. Create a tester class StopWatch.java that starts these two classes.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

program:1

import java.util.*;
class ThreadWaiterOne extends TimerTask {
public void run() {
System.out.println("Thread Waiter One is done.");
}
}
class ThreadWaiterTwo extends TimerTask {
public void run() {
System.out.println("Thread Waiter Two is done.");
}
}

// Main Class
class ThreadTester
{
public static void main(String[] args)
{
Timer timer = new Timer();
//time in milliseconds
timer.schedule(new ThreadWaiterOne(), 0, 20000);
timer.schedule(new ThreadWaiterTwo(), 0, 5000);
}
}

program:2

import java.util.*;
class ThreadWaiterOne extends TimerTask {
public void run() {
System.out.println("Thread Waiter One is done.");
}
}
class ThreadWaiterTwo extends TimerTask {
public void run() {
System.out.println("Thread Waiter Two is done.");
}
}

// Main Class
class ThreadTester
{
public static void main(String[] args)
{
Timer timer = new Timer();
//time in milliseconds
timer.schedule(new ThreadWaiterOne(), 0, 20000);
timer.schedule(new ThreadWaiterTwo(), 0, 5000);
}
}

Hope this helped you! Please comment below still if you have any doubts on this answer.

Add a comment
Know the answer?
Add Answer to:
Create two thread classes: ThreadWaiterOne and ThreadWaiterTwo. The thread classes must implement Runnable. In the Run...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please use java Language Part I Implement a thread by extending the Thread class. Your thread...

    Please use java Language Part I Implement a thread by extending the Thread class. Your thread must do the following: (25 pts.) • Print its name and ID at the start. • Print the numbers from 1 to 100 that can be divided by 5. • Wait 1 second before printing a number. Part II Implement a thread by implementing the Runnable interface. Your thread must do the following: (25 pts.) • Print its name and ID at the start....

  • 1. Analyze the following code: public class Test implements Runnable { public static void main(String[] args) { Thread t = new Thread(this); t.start(); } public void run() { System....

    1. Analyze the following code: public class Test implements Runnable { public static void main(String[] args) { Thread t = new Thread(this); t.start(); } public void run() { System.out.println("test"); } } 1. The code compiles but will not print anything since t does not invoke the run method. 2. The code will not compile since you cannot invoke "this" in a static method. 3. The program compiles, runs, and prints tests on the console. 2. What will the following example...

  • Write a program that will define a runnable frame to have a ball move across the...

    Write a program that will define a runnable frame to have a ball move across the frame left to right. While that is happening, have another frame that will let the user do something like click a button or input into a textfield, but keep the ball moving in the other frame. When the ball reaches the right edge of the frame or when the user takes action - enters in textfield or clicks the button, end the thread. The...

  • In this next example, we'll build two classes that implement the Cloneable Interface. The QuizTracker class...

    In this next example, we'll build two classes that implement the Cloneable Interface. The QuizTracker class contains an ArrayList of QuizScore objects, and it's up to us to build these two classes so that we can make deep copies of QuizTrackers (and share no internal aliases). The key idea here is that to make deep copies of compound objects (or lists of objects), we need to copy (using clone) every object in every list, and even make copies of the...

  • You must write C# classes which are used to manage product review data for Books and...

    You must write C# classes which are used to manage product review data for Books and Cars. You will write an abstract class called Review which abstracts common properties (review rating and comments). You will then create an Interface responsible for the functionality to display the Reviewcontent. Then, you will create 2 concrete classes which inherit from Review and implement the Interface. Finally, you will create console applicationwhich will create 2 CarReview instances and 2 BookReview instances and display them...

  • fill in the blanks with java code The following code implements a Java timer that looks...

    fill in the blanks with java code The following code implements a Java timer that looks like the application below. . Once the application starts it keeps counting seconds until it is terminated. Timer (sec): 20 You are given a partial implementation of the program. Fill out the missing code to complete the program. import java.awt.*; import java.awt.event.; import java.util."; import javax.swing. *; import javax.swing. Timer; * This program shows a timer that is updated once per second. public class...

  • Once your UML diagram is complete implement the class naming the Java file MyInteger.java. Create another...

    Once your UML diagram is complete implement the class naming the Java file MyInteger.java. Create another Java file, a program named MyIntegerTester.java that tests all methods in the class. One technique is to write both classes at the same time. As much as possible you implement and test one method at a time. This minimized the amount of new code you have to look at when debugging a method. Only the Version 4.0 “tester” file will have main() method in...

  • in java : Create Java Application you are to create a project using our designated IDE...

    in java : Create Java Application you are to create a project using our designated IDE (which you must download to your laptop). Create the code to fulfill the requirements below. Demonstrate as stipulated below. Create a Main Application Class called AddressBookApplication (a counsole application / command line application). It should Contain a Class called Menu that contains the following methods which print out to standard output a corresponding prompt asking for related information which will be used to update...

  • Create this c++ program. Create to classes and name their type Account and Money. Follow the...

    Create this c++ program. Create to classes and name their type Account and Money. Follow the instruction listed below. Please read and implement instructions very carefully Money Class Requirements - Negative amounts of Money shall be stored by making both the dollars and cents negative The Money class shall have 4 constructors * A default constructor that initializes your Money object to $0.00 A constructor that takes two integers, the first for the dollars and the second for the cents...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT