Question: Consider the following UML for the Point and Line classes. 1- Write the implementation of compareTo in the Line class where two lines are



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
Step by Step Solution
3.51 Rating (154 Votes )
There are 3 Steps involved in it
1 Implementation of compareTo method in the Line class java import javalangComparable class Line implements Comparable other attributes and methods Ov... View full answer
Get step-by-step solutions from verified subject matter experts
