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...
-
Define a geometric series, state when it converges, and give the formula for the sum of a convergent geometric series.
-
Brian Hughes and Wendy Perez formed a partnership five years ago. The partnership has been very successful and is growing rapidly. The partners are evaluating future actions for the next five years....
-
Vanna Co. produces and sells two products, T and O. It manufactures these products in separate factories and markets them through different channels. They have no shared costs. This year, the company...
-
Required Rates of Return Suppose that the risk - free rate is 3 % and that the market risk premium is 5 % . Round your answers to one decimal place. What is the required return on the market? % What...
-
1. Considering Yips globalisation framework (Figure 9.2), what drivers of internationalisation do you think were most important when Wanda entered the US market through its AMC and Legendary...
-
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...
-
How do we discover business activities?
-
Hazelnut Corporation manufactures lawn ornaments. It currently has two product lines, the basic and the luxury. Hazelnut has a total of $143,484 in overhead. The company has identified the following...
-
Discuss the interplay between literature and technology in the digital age. How are new forms of storytelling, such as interactive fiction and digital poetry, transforming the literary landscape ?
-
In what ways does postmodernist literature challenge traditional narrative structures, and what implications does this have for readers' understanding of truth and reality ?
-
Both Plato and Aristotle believed that there is a world of true knowledge, the ultimate reality of the world that has been created perfectly by God (or the equivalent concept of God). What did each...
-
The E-field produced by a single point charge Q is characterized by all of the following except it always points radially from (or to) Q. it increases in magnitude as Q increases. it is modified by...
-
Arnie and Angela are married and file a joint return in 2016. Arnie is a partner in a public accounting firm. His share of the partnerships income in the current year is $40,000, and he receives...
-
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.
-
Assume that a lender offers a 30-year, $158,000 adjustable rate mortgage (ARM) with the following terms: Initial interest rate = 7.5 percent Index = one-year Treasuries Payments reset each year...
-
Suppose that a trader writes three naked put option contracts, with each contract being on 100 shares of underlying stock. The option price is $3 on each share, the time to maturity is six months,...
-
Richardson Ski Racing (RSR) sells equipment needed for downhill ski racing. One of RSR's products is fencing used on downhill courses. The fence product comes in 150- foot rolls and sells for $215...
Study smarter with the SolutionInn App