Rewrite Listing 30.1 to display the output in a text area, as shown in Figure 30.30. Listing
Question:
Rewrite Listing 30.1 to display the output in a text area, as shown in Figure 30.30.
Listing
Transcribed Image Text:
a 1b2b3b 4b 5 b6bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb 7 8bbbbbbbbbbbbbbbbbbbb 9bb10 16 11 12 13 14 15 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99b 100bbbbbbbabaabbabaa baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbb 1 public class TaskThreadDemo { public static void main(String[] args) { // Create tasks Runnable printA = new PrintChar('a', 100); Runnable printB = new PrintChar('b', 100); Runnable print100 - new PrintNum(100); 2 // Create threads Thread threadl = new Thread(printA); Thread thread2 = new Thread(printB); Thread thread3 = new Thread(print100); 10 11 12 // Start threads thread1.start(); thread2.start(); thread3.start(); 13 14 15 16 17 18 } 19 20 // The task for printing a character a specified number of times 21 class PrintChar implements Runnable { 22 23 private char charToPrint; // The character to print private int times; // The number of times to repeat 24 25 26 27 28 29 /** Construct a task with a specified character and number of * times to print the character */ public PrintChar(char c, int t) { charToPrint - c; times - t; 30 31 32 33 34 35 @Override /** Override the run() method to tell the system * what task to perform public void run() { for (int i = 0; i < times; i++) { System.out.print(charToPrint); 36 37 38 39 40 41 } 42 43 // The task class for printing numbers from 1 to n for a given n 44 class PrintNum implements Runnable { 45 46 private int lastNum; 47 /** Construct a task for printing 1, 2, n */ public PrintNum(int n) { lastNum = n; 48 49 50 51 52 53 @Override /** Tell the thread how to run */ public void run() { for (int i = 1; i = lastNum; i++) { System.out.print(" " + i); 54 55 56 57 58 }
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 92% (14 reviews)
Program Plan Create PrintChar class so that prints a specified character a or b 100 times in a te...View the full answer
Answered By
Akshay Agarwal
I am a Post-Graduate with a specialization in Finance. I have been working in the Consulting industry for the past 8 years with a focus on the Corporate and Investment Banking domain. Additionally, I have been involved in supporting student across the globe in their academic assignments and always strive to provide high quality support in a timely manner. My notable achievements in the academic field includes serving more than 10,000 clients across geographies on various courses including Accountancy, Finance, Management among other subjects. I always strive to serve my clients in the best possible way ensuring high quality and well explained solutions, which ensures high grades for the students along-with ensuring complete understanding of the subject matter for them. Further, I also believe in making myself available to the students for any follow-ups and ensures complete support and cooperation throughout the project cycle. My passion in the academic field coupled with my educational qualification and industry experience has proved to be instrumental in my success and has helped me stand out of the rest. Looking forward to have a fruitful experience and a cordial working relationship.
5.00+
179+ Reviews
294+ Question Solved
Related Book For
Introduction to Java Programming, Comprehensive Version
ISBN: 978-0133761313
10th Edition
Authors: Y. Daniel Liang
Question Posted:
Students also viewed these Computer science questions
-
Rewrite Listing 30.6, ThreadCooperation.java, using the object?s wait() and notifyAll() methods. Listing 1 import java.util.concurrent.*; 2 import java.util.concurrent.locks.*; 3 4 public class...
-
Listing 5.15 determines whether a number n is prime by checking whether 2, 3, 4, 5, 6, ..., n/2 is a divisor. If a divisor is found, n is not prime. A more efficient approach is to check whether any...
-
Rewrite Listing 8.2, GradeExam.java, to display the students in increasing order of the number of correct answers. Listing 1 public class GradeExam { 2 /** Main method */ public static void...
-
What is the present value of $9,000 received: a. Twenty eight years from today when the interest rate is 10% per year? b. Fourteen years from today when the interest rate is 10% per year? c. Seven...
-
Gold, which has a density of 19.32 g/cm3, is the most ductile metal and can be pressed into a thin leaf or drawn out into a long fiber. (a) If a sample of gold, with a mass of 27.63 g, is pressed...
-
What promotional benefits does Kevins idea have for the station?
-
What are the relative advantages of: (a) a system of straight salary that is the same each month, and (b) a system of salary with an individual performance-related addition so that the total payment...
-
1. How does Amazon.com illustrate the sources of service sector growth? Comment on information technology, Internet as an enabler, innovation, and changing demographics. 2. What generic approaches(s)...
-
1 Problem 16-55 (Algo) Prepare Flexible Budget (LO 16-2) Odessa, Inc., reports the following information concerning operations for the most recent month: 20 points Actual (based on actual of 585...
-
A computer laboratory in a school has 33 computers. Each of the 33 computers has 90% reliability. Allowing for 10% of the computers to be down, an instructor specifies an enrollment ceiling of 30 for...
-
Since T is implemented using a list in the getMinimumSpanningTree and getShortestPath methods in Listing 29.2 WeightedGraph.java, testing whether a vertex u is in T by invoking T.contains(u) takes...
-
Rewrite Exercise using a thread to control car racing. Compare the program with Exercise by setting the delay time to 10 in both programs. Which one runs the animation faster? Write a program that...
-
be able to evaluate the relevance, value and sufficiency of the literature found?
-
cest Shouldice Hospital in Canada is widely known for one thing-hernia repair! In fact, that is the only operation it performs, and it performs a great many of them. Over the past two decades this...
-
The activation energy for the gas phase decomposition of isobutyl bromide is 211 kJ. (CH3)2CHCH2 Br (CH3)2C=CH2+ HBr The rate constant at 676 K is 5.73 x 10-4 s. The rate constant will be 0.00647 s...
-
Zephyr Minerals completed the following transactions involving machinery. Machine No. 1550 was purchased for cash on April 1, 2020, at an installed cost of $75,000. Its useful life was estimated to...
-
Kelly is a self-employed tax attorney whose practice primarily involves tax planning. During the year, she attended a three-day seminar regarding new changes to the tax law. She incurred the...
-
At a recently concluded Annual General Meeting (AGM) of a company, one of the shareholders remarked; historical financial statements are essential in corporate reporting, particularly for compliance...
-
How much do prices vary for filling a cavity? To find out, an insurance company randomly selects 10 dental practices in California and asks for the cash (non-insurance) price for this procedure at...
-
2. In the circuit given in Figure 2, i,(t) = 5.67cos(5t)A and v (t) = 70.71 cos(5t 60) V a) Find the equivalent load impedance. State whether the load is inductive or capacitive. b) Calculate the...
-
Look over your received e-mails, and examine the header of a message sent from a user with a .edu e-mail address. Is it possible to determine from the header the IP address of the host from which the...
-
In Bit Torrent, suppose Alice provides chunks to Bob throughout a 30-second interval. Will Bob necessarily return the favor and provide chunks to Alice in this same interval? Why or why not?
-
CDNs typically adopt one of two different server placement philosophies. Name and briefly describe them.
-
A farmer is concerned that the price of wheat will drop by the time he is ready to sell his crop. He, therefore, enters into a futures contract on 5,000 bushels of wheat for 250 cents per bushel. The...
-
On December 1, ABC Company received $3,000 cash from a customer for 3 months of business services beginning December 1st. Prepare the journal entry to record the receipt of the 3,000 and the...
-
When Kevin started working 23 years ago, his salary was $59,349. His current salary is $159,408. When Kevin started working, the price level was 134, while the current price level is 157. What was...
Study smarter with the SolutionInn App