Please answer this using Java OVERVIEW We now discuss the features of class StringBuilder for creating and
Fantastic news! We've Found the answer you've been seeking!
Question:
Please answer this using Java
Transcribed Image Text:
OVERVIEW We now discuss the features of class StringBuilder for creating and manipulating dynamic string information that is, modifiable strings. Every StringBuilder is capable of storing a number of characters specified by its capacity. If a StringBuilder's capacity is exceeded, the capacity expands to accommodate the additional characters. In programs that frequently perform string concatenation, or other string modifications, it's often more efficient to implement the modifications with class StringBuilder rather than String. INSTRUCTIONS Write an application that uses random-number generation to create sentences. Create four String arrays called article, noun, verb, and preposition containing the following words: The article array must contain the articles "the," "a," "one," "some," and "any." The noun array must contain the nouns "boy," "girl," "dog," "town," and "car." The verb array must contain the verbs "drove," "jumped," "ran," "walked," and "skipped." The preposition array must contain the prepositions "to," "from," "over," "under" and "on." Create a sentence (using the StringBuilder type) by selecting a word at random from each array in the following order: 1. Article, 2. noun, 3. verb, 4. preposition, 5. article, and 6. noun. As each word is picked, concatenate it to the previous words in the sentence using the StringBuilder append() method. The words must be separated by spaces. When each sentence is output, the first letter of the first word should start with a capital letter and the sentence should end with a period (see sample output below). The application must generate and display 20 sentences. OVERVIEW We now discuss the features of class StringBuilder for creating and manipulating dynamic string information that is, modifiable strings. Every StringBuilder is capable of storing a number of characters specified by its capacity. If a StringBuilder's capacity is exceeded, the capacity expands to accommodate the additional characters. In programs that frequently perform string concatenation, or other string modifications, it's often more efficient to implement the modifications with class StringBuilder rather than String. INSTRUCTIONS Write an application that uses random-number generation to create sentences. Create four String arrays called article, noun, verb, and preposition containing the following words: The article array must contain the articles "the," "a," "one," "some," and "any." The noun array must contain the nouns "boy," "girl," "dog," "town," and "car." The verb array must contain the verbs "drove," "jumped," "ran," "walked," and "skipped." The preposition array must contain the prepositions "to," "from," "over," "under" and "on." Create a sentence (using the StringBuilder type) by selecting a word at random from each array in the following order: 1. Article, 2. noun, 3. verb, 4. preposition, 5. article, and 6. noun. As each word is picked, concatenate it to the previous words in the sentence using the StringBuilder append() method. The words must be separated by spaces. When each sentence is output, the first letter of the first word should start with a capital letter and the sentence should end with a period (see sample output below). The application must generate and display 20 sentences.
Expert Answer:
Answer rating: 100% (QA)
Here is a Java application that utilizes random number generation to create sentences based on the g... View the full answer
Related Book For
Cost Accounting A Managerial Emphasis
ISBN: 978-0133138443
7th Canadian Edition
Authors: Srikant M. Datar, Madhav V. Rajan, Charles T. Horngren, Louis Beaubien, Chris Graham
Posted Date:
Students also viewed these programming questions
-
Design a Java class that represents a cache with a fixed size. It should support operations like add, retrieve, and remove, and it should evict the least recently used item when it reaches capacity.
-
can someone solve this Modern workstations typically have memory systems that incorporate two or three levels of caching. Explain why they are designed like this. [4 marks] In order to investigate...
-
Glencoe First National Bank operated for years under the assumption that profitability can be increased by increasing dollar volumes. Historically, First Nationals efforts were directed toward...
-
In 2015, an industrial plant owned by Company C, a calendar year taxpayer, was destroyed in a flood. C's adjusted basis in the plant was $1.65 million, and the company received a $2 million insurance...
-
Echeverria S.A. is an Argentinian manufacturing company whose total factory overhead costs fluctuate somewhat from year to year, according to the number of machine-hours worked in its production...
-
An engineer performed an experiment to determine the effect of $\mathrm{CO}_{2}$ pressure, $\mathrm{CO}_{2}$ temperature, peanut moisture, $\mathrm{CO}_{2}$ flow rate, and peanut particle size on the...
-
Many companies post their financial statements and auditors report on their home pages, generally under a heading labeled investor relations. Use one of the Internet search engines to do the...
-
1 . What is the starting point in doing a projected discounted cash flows analysis?A . Start with the projected increase in assets.B . Start with the required interest rate.C . Start with the sale...
-
(c) Prove that in two dimensions the free electron density of levels g(8) is a constant indepen- dent of 8 for & > 0, and 0 for & < 0. What is the constant?
-
What is understood by the applicantorganization ft approach to the selection interview?
-
How is the price of petroleum determined and why is it so volatile?
-
York Engineering Ltd. forecasts sales of 1,250,000 for 2022. Assume that the firm has fixed costs of 320,000 and variable costs amount to 30% of sales. Operating expenses are estimated to include...
-
Explain what is meant by team appraisal.
-
Identify the modes of communication within organizations.
-
A 2-wire d.c. distributor A B is fed at both ends at the same voltage of 230 V. The length of the distributor is 500 metres and the loads are tapped off from the end A as shown below : Load : 100 A...
-
What are multinational corporations (MNCs) and what economic roles do they play?
-
Give three definitions of investment used in practice when computing ROI.
-
Explain the incentive problems that can arise when employees must perform multiple tasks as part of their jobs?
-
BigScreen Corporation manufactures and sells 50-inch television sets and uses standard costing. Actual data relating to January, February, and March of 2015 are: Required 1. Present statements of...
-
A flow of nitrogen is discharged from a duct with \(M_{2}=0.85, T_{2}=500^{\circ} \mathrm{R}\), and \(p_{2}=28\) psia. The temperature at the inlet is \(560^{\circ} \mathrm{R}\). Compute the pressure...
-
Consider the flow of a perfect gas along a Fanno line. Show that the pressure at the * reference state is given by the relation 1/2 m 2RT, P Ayge(y+1)
-
Air enters a duct with a mass flow rate of \(35 \mathrm{lbm} / \mathrm{sec}\) at \(T_{1}=520^{\circ} \mathrm{R}\) and \(p_{1}=20 \mathrm{psia}\). The duct is square and has an area of \(0.64...
Study smarter with the SolutionInn App