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% (13 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...
-
Find v 2 /v 1 in the circuit shown in Fig. 5-16. VI 2 www B A ww 10 15 Fig. 5-16 7 + 12 | 2 R2
-
Plaintiff contracted to install a boiler for defendant. After plaintiff had installed and tested the boiler, but before final payment to plaintiff had been made, defendant took custody of the boiler...
-
Marina Company has a maximum capacity of 200,000 units per year. Variable manufacturing costs are $12 per unit. Fixed overhead is $600,000 per year. Variable selling and administrative costs are $5...
-
Create three new users with names and privileges as described below in Oracle database: Show the code you used to make these users and grant them the correct privileges. Name User1 User2 User3...
-
Adamski Corporation manufactures ballet shoes and is experiencing a period of sustained growth. In an effort to expand its production capacity to meet the increased demand for its product, the...
-
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...
-
Repeat Problem 15.1.5 using the data set in DS 15.1.2 and for the null hypothesis that the median of the distribution is equal to 40 against a two-sided alternative hypothesis. Problem 15.1.5 Suppose...
-
Calculate impairment loss: a piece of equipment has the following balance, what is the amount of impairment loss to be recorded: Purchase Price: $15,000 Accumulated Amortization: $10,000 Recoverable...
-
J Aguila makes scented candles and sells them whole sale by the case. There are 24 candles per case. J Aguila sells a case of candles for Php50 a case. His variable costs are Php30 per case. He has...
-
If Randolph Company has prior year accounts receivables of $792,895, current year accounts receivables of $813,354 and net credit sales of $4,040,002, what is its accounts receivable turnover?
-
The loan is for $20,000, monthly payments are made for 5 years, and the annual interest rate is 1.8%. Requirement What will the monthly payment be?
-
During 2020, Catherine had the following deductions and adjustments to income: Schedule C (Form 1040) expenses of $15,000, standard deduction of $12,400, $8,400 alimony paid, and $3,700 casualty loss...
-
Latoya transferred property to an irrevocable trust in 2002 with a bank trustee. Latoya named Al to receive the trust income annually for life and Pat or Pat's estate to receive the remainder upon...
-
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.
-
How do neoliberal economic policies intersect with globalization, and what impact do they have on global trade dynamics and income inequality?
-
Exercise 1. Packets of socks made by Oliver & Hardy company are sold to consumers for $2.49. Retailers ear 27% on the retail selling price. Wholesalers typically earn 25% mark-up on their cost of...
-
On March 31, 20Y9, the balances of the accounts appearing in the ledger of Royal Furnishings Company, a furniture store, are as follows: Accounts Receivable Accumulated Depreciation-Building...
Study smarter with the SolutionInn App