Consider the following UML for the Point and Line classes. 1- Write the implementation of compareTo...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Consider the following UML for the Point and Line classes. 1- Write the implementation of compareTo in the Line class where two lines are compared based on their length. 2- Update the given UML class diagram to show that Line implements Comparable interface. 3- Write Java code (in the driver's main method) to instantiate two lines, compare them using compare To, and print on the screen the start and end points of the bigger line. -x: double -y: double +Point() Point +Point(x:double.y.double) +getX():double +getY():double +toString(): String +equals(other:Object):boolean +toString(): String -start:Point -end:Point Line +Line(start:Point,end:Point) +getStart():Point +getEnd():Point +length():double +equals(other:Object):boolean +toString(): String Exercise 2: class LineArrayBag Assume you have the following class LineArrayBag that uses the Line class from Exercise 1. mooooooo LineArrayBag -data:Line[] -manyItems:int +LineArrayBag() +LineArrayBag(capacity:int) +add(element:Line):void +countOccurances(target:Line):int +grab(index:i):Line +remove(target:Line):void +size(): int +max(): int +toString(): String 1- Write the implementation for an iterator class for LineArrayBag. Be sure to include the iterator () method. 2- Write code (in driver's main method) to use your iterator to display all the Lines in a LineArrayBag object. 3- Enable the enhanced for-loop by implementing the Iterable interface for wwwwwwwwwwwwwwwmmm the LineArrayBag class. 4- Write an enhanced for-loop (in driver's main method) to display all the Lines in a LineArrayBag named myLines. Exercise 3: addBefore wccccccccccsssss Implement a method called addBefore in LineArrayBag. This method takes two Line objects, called target and element, as input. The method then inserts element before target in the array. If target is not found in the array, then element is inserted as the last element in the array. You can assume there are no duplicates in the array which means that target may exist at most once in the array. Write code in the driver to test this method. For example, if you have the following elements in data array: 0 1 2 3 4 5 red blue yellow | null null null The call addBefore (green, yellow) will insert green before yellow resulting in the following data array: 0 1 2 3 4 red blue green yellow null 5 null 2 Consider the following UML for the Point and Line classes. 1- Write the implementation of compareTo in the Line class where two lines are compared based on their length. 2- Update the given UML class diagram to show that Line implements Comparable interface. 3- Write Java code (in the driver's main method) to instantiate two lines, compare them using compare To, and print on the screen the start and end points of the bigger line. -x: double -y: double +Point() Point +Point(x:double.y.double) +getX():double +getY():double +toString(): String +equals(other:Object):boolean +toString(): String -start:Point -end:Point Line +Line(start:Point,end:Point) +getStart():Point +getEnd():Point +length():double +equals(other:Object):boolean +toString(): String Exercise 2: class LineArrayBag Assume you have the following class LineArrayBag that uses the Line class from Exercise 1. mooooooo LineArrayBag -data:Line[] -manyItems:int +LineArrayBag() +LineArrayBag(capacity:int) +add(element:Line):void +countOccurances(target:Line):int +grab(index:i):Line +remove(target:Line):void +size(): int +max(): int +toString(): String 1- Write the implementation for an iterator class for LineArrayBag. Be sure to include the iterator () method. 2- Write code (in driver's main method) to use your iterator to display all the Lines in a LineArrayBag object. 3- Enable the enhanced for-loop by implementing the Iterable interface for wwwwwwwwwwwwwwwmmm the LineArrayBag class. 4- Write an enhanced for-loop (in driver's main method) to display all the Lines in a LineArrayBag named myLines. Exercise 3: addBefore wccccccccccsssss Implement a method called addBefore in LineArrayBag. This method takes two Line objects, called target and element, as input. The method then inserts element before target in the array. If target is not found in the array, then element is inserted as the last element in the array. You can assume there are no duplicates in the array which means that target may exist at most once in the array. Write code in the driver to test this method. For example, if you have the following elements in data array: 0 1 2 3 4 5 red blue yellow | null null null The call addBefore (green, yellow) will insert green before yellow resulting in the following data array: 0 1 2 3 4 red blue green yellow null 5 null 2
Expert Answer:
Answer rating: 100% (QA)
1 Implementation of compareTo method in the Line class java import javalangComparable class Line implements Comparable other attributes and methods Ov... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
Write a literature review for your study. See below for an example of a literature review. Your literature review should provide both analysis and synthesis of previous studies as related to the...
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
(a) ABC is a company that manufactures computer desk. The total costs (in RM'000) when x units of computer desk are produced is given by C(x) = 12x 3 - 198x 2 + 1080x Find the level of x that the...
-
At December 31, 2014, Credit Valley Nissan has an Accounts Receivable balance of $101,000. Allowance for Uncollectible Accounts has a credit balance of $2,000 before the year-end adjustment. Service...
-
The quantity demanded for wireless computer mouses is Q d = 500 - 1.75 P , and the quantity supplied is Q s = 450 + 0.25 P . a. Calculate the equilibrium price and quantity. b. Is total surplus...
-
A _______________ interval estimates the mean y-value for all individuals with a given x-value. In Exercises 3 and 4, fill in each blank with the appropriate word or phrase.
-
The following data relate to the operations of Lim Corporation, a wholesale distributor of consumer goods: Current assets as of December 31: Cash . . . . . . . . . . . . . . . . . . . . . . . . . . ....
-
COVID-19 Has had a massive impact on the Service Industry. Please read the article Corona Virus Impact on Service OrganizationsLinks to an external site. After reading the above article, please...
-
Acme Manufacturing makes a variety of household appliances at a single manufacturing facility. The expected demand for one of these appliances during the next four months is shown in the following...
-
Circle T is shown below. M T N P Nina measured the length of line segment MP as 20 centimeters (cm). What is the length of line segment NT?
-
After completing the organizational behavior team projects, what were your three take-aways, and how will you use this information in your personal or professional life? Were you in a high...
-
Lopez Plastics Company (LPC) issued callable bonds on January 1, 2024. LPC's accountant has projected the following amortization schedule from issuance until maturity. Cash interest Effective...
-
What is the expected rate of return on a project that requires an investment of $106 today and generates cash inflows of $7, $17 and $122 in each of the next 3 years?
-
we will explore the similarities and differences between the CAPM and a one factor market model. In class you have learned that the CAPM describes expected returns and you have embraced the equation...
-
Then examine your own workplace or some other organization with which you are familiar and determine how it seeks to increase demand for its product. Navigate to the threaded discussion and post an...
-
Make a prediction. True story: back in 1992, there were only 146 Starbucks locations in the US. How many Starbucks do you think there were in the US in 2015? Make a quick estimate and write it in the...
-
Listed below are common types of current liabilities, contingencies, and commitments: a. Accounts payable b. Bank loans and commercial paper c. Notes payable d. Dividends payable e. Sales and excise...
-
Define the concepts of organization and organizational behavior.
-
A rapidly growing high-tech company has recently experienced resignations by several of its best people. These individuals have left, expressing strong annoyance over the high level of politics...
-
This exercise is designed to help you put into practice some of the skills associated with being a good negotiator. In completing this exercise, follow the steps for negotiating a win-win solution...
-
Optimize the following Boolean functions \(F\) together with the don't-care conditions \(d\) : (a) \(F(A, B, C, D)=\Sigma m(0,1,7,13,15), d(A, B, C, D)=\Sigma m(2,6,8,9,10)\) (b) \(F(W, X, Y,...
-
+Apply the simplified Espresso algorithm to the following function. Show a K-map for each algorithm routine that changes one or more implicants. \[F(A, B, C, D)=\bar{A} \bar{B} \bar{D}+\bar{B}...
-
Illustrate the expansion or reduction performed on each implicant on a Kmap if the operation changes the implicant. (a) Apply the Espresso EXPAND routine to the following function. \[F(A, B, C,...
Study smarter with the SolutionInn App